using Furion;
using Furion.DependencyInjection;
using Furion.DistributedIDGenerator;
using Furion.DynamicApiController;
using Furion.Extensions;
using Furion.FriendlyException;
using Furion.JsonSerialization;
using Furion.Localization;
using Furion.Logging.Extensions;
using Furion.RemoteRequest;
using Furion.RemoteRequest.Extensions;
using HtmlAgilityPack;
using Mapster;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.Extensions.Logging;
using Myshipping.Application.EDI;
using Myshipping.Application.Entity;
using Myshipping.Application.Entity.TaskManagePlat;
using Myshipping.Application.Helper;
using Myshipping.Application.Service.BookingOrder;
using Myshipping.Application.Service.BookingSlot.Dto;
using Myshipping.Application.Service.ExpressDelivery.Dto.SF;
using Myshipping.Application.Service.TaskManagePlat.Interface;
using Myshipping.Core;
using Myshipping.Core.Const;
using Myshipping.Core.Entity;
using Myshipping.Core.Helper;
using Myshipping.Core.Service;
using MySqlX.XDevAPI.Common;
using NetTaste;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Npoi.Mapper;
using NPOI.HPSF;
using NPOI.HSSF.UserModel;
using NPOI.OpenXmlFormats;
using NPOI.OpenXmlFormats.Dml.Diagram;
using NPOI.OpenXmlFormats.Wordprocessing;
using NPOI.POIFS.Crypt.Dsig;
using NPOI.SS.Formula.Atp;
using NPOI.SS.Formula.Eval;
using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using NPOI.Util;
using NPOI.XSSF.Model;
using NPOI.XSSF.UserModel;
using Org.BouncyCastle.Asn1.Tsp;
using Org.BouncyCastle.Asn1.X500;
using Org.BouncyCastle.Asn1.X9;
using SixLabors.ImageSharp.Processing.Processors.Transforms;
using SqlSugar;
using StackExchange.Profiling.Internal;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.DirectoryServices.ActiveDirectory;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.InteropServices;
using System.Security.Policy;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using static Aliyun.OSS.Model.CreateSelectObjectMetaInputFormatModel;
using static Aliyun.OSS.Model.ListPartsResult;
namespace Myshipping.Application
{
///
/// 任务管理
///
[ApiDescriptionSettings("Application", Name = "TaskManage", Order = 10)]
public class TaskManageService : ITaskManageService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _taskBaseInfoRepository;
private readonly SqlSugarRepository _taskSISubmittedRepository;
private readonly SqlSugarRepository _taskSISubmittedCtnRepository;
private readonly SqlSugarRepository _taskBillFeeDetailInfoRepository;
private readonly SqlSugarRepository _taskFileInfoRepository;
private readonly SqlSugarRepository _taskEmailInfoRepository;
private readonly SqlSugarRepository _taskVGMInfoRepository;
private readonly SqlSugarRepository _taskVGMCtnInfoRepository;
private readonly SqlSugarRepository _bookingCtnVGMRepository;
private readonly SqlSugarRepository _sysUserRepository;
private readonly SqlSugarRepository _taskStatManageInfoRepository;
private readonly SqlSugarRepository _taskOriginalDownloadHisInfoRepository;
private readonly SqlSugarRepository _taskChargesHisInfoRepository;
private readonly SqlSugarRepository _taskLARAPaperInfoRepository;
private readonly SqlSugarRepository _taskPerBillBaseInfoRepository;
private readonly SqlSugarRepository _taskStoreMsgInfoRepository;
private readonly SqlSugarRepository _taskChangeShipHisInfoRepository;
private readonly SqlSugarRepository _taskBCInfoRepository;
private readonly SqlSugarRepository _taskBCCTNInfoRepository;
private readonly SqlSugarRepository _bookingSlotBaseRepository;
private readonly SqlSugarRepository _bookingOrderRepository;
private readonly SqlSugarRepository _bookingOrderContaRepository;
private readonly SqlSugarRepository _bookingOrderContaCargoRepository;
private readonly SqlSugarRepository _bookingStatusRepository;
private readonly SqlSugarRepository _bookingOrderContactRepository;
private readonly SqlSugarRepository _djyUserMailAccountRepository;
private readonly SqlSugarRepository _taskTruckInfoRepository;
private readonly SqlSugarRepository _taskTruckCtnRepository;
private readonly SqlSugarRepository _taskCutDateChangeInfoRepository;
private readonly SqlSugarRepository _taskCutDateChangeDetailInfoRepository;
private readonly SqlSugarRepository _taskRollingNominationInfoRepository;
private readonly SqlSugarRepository _taskRollingNominationShipInfoRepository;
private readonly SqlSugarRepository _taskRollingNominationDetailInfoRepository;
private readonly SqlSugarRepository _taskDraftInfoRepository;
private readonly SqlSugarRepository _taskPODDischargeGateoutFullInfoRepository;
private readonly SqlSugarRepository _taskPODDischargeGateoutFullDetailInfoRepository;
private readonly SqlSugarRepository _taskCautionNoticeInfoRepository;
private readonly SqlSugarRepository _taskCautionNoticeDetailInfoRepository;
private readonly SqlSugarRepository _taskRouteChangeAdvisoryInfoRepository;
private readonly SqlSugarRepository _taskRouteChangeAdvisoryDetailInfoRepository;
private readonly SqlSugarRepository _taskTransPlanHasChangeInfoRepository;
private readonly SqlSugarRepository _taskTransPlanHasChangeDetailInfoRepository;
private readonly SqlSugarRepository _taskPOLContainerNotPickUpInfoRepository;
private readonly SqlSugarRepository _taskFlowTenant;
private readonly IDjyWebsiteAccountConfigService _webAccountConfig;
private readonly ISysCacheService _cache;
private readonly ILogger _logger;
private readonly ISysDataUserMenu _sysDataUserMenuService;
private readonly INamedServiceProvider _namedBookingOrderServiceProvider;
private readonly INamedServiceProvider _namedRollingNominationServiceProvider;
private readonly INamedServiceProvider _namedTaskManageBCServiceProvider;
private readonly INamedServiceProvider _namedBookingMSKAPIServiceProvider;
private readonly INamedServiceProvider _namedtaskSISubmittedServiceProvider;
private readonly INamedServiceProvider _namedTaskCautionNoticeServiceProvider;
private readonly INamedServiceProvider _namedTaskTransPlanHasChangeServiceProvider;
private readonly INamedServiceProvider _namedTaskPOLContainerNotPickUpServiceProvider;
private readonly INamedServiceProvider _namedTaskManageCutDateChangeServiceProvider;
private readonly INamedServiceProvider _namedRouteChangeAdvisoryServiceServiceProvider;
private readonly INamedServiceProvider _namedBookingLabelServiceServiceProvider;
private readonly INamedServiceProvider _namedPODDischargeGateoutFullProvider;
private readonly INamedServiceProvider _namedVGMServiceProvider;
private readonly IBookingValueAddedService _bookingValueAddedService;
const string CONST_WEB_ACCOUNT_TYPE = "CmaWeb";
const string CONST_BOOK_ORIGINAL_DOWN_URL_CODE = "bookOriginalDownUrl";
const string CONST_WEB_LARA_ACCOUNT_TYPE = "LaraWeb";
const string CONST_LARA_DOWN_URL_CODE = "LaraPaperPostUrl";
const string CONST_MAPPING_MODULE = "YunJia";
//LARA纸计算常量
const int LARA_PARER_DRAFT_VAR = 3;
private readonly BookingOrderAutoService _bookingOrderAuto;
public TaskManageService(SqlSugarRepository taskBaseInfoRepository,
SqlSugarRepository taskSISubmittedRepository,
SqlSugarRepository taskSISubmittedCtnRepository,
SqlSugarRepository taskBillFeeDetailInfoRepository,
SqlSugarRepository taskFileInfoRepository,
SqlSugarRepository taskEmailInfoRepository,
SqlSugarRepository taskVGMInfoRepository,
SqlSugarRepository taskVGMCtnInfoRepository,
SqlSugarRepository sysUserRepository,
SqlSugarRepository taskStatManageInfoRepository,
SqlSugarRepository taskOriginalDownloadHisInfoRepository,
SqlSugarRepository taskChargesHisInfoRepository,
SqlSugarRepository bookingOrderRepository,
SqlSugarRepository taskLARAPaperInfoRepository,
SqlSugarRepository bookingOrderContaRepository,
SqlSugarRepository bookingOrderContaCargoRepository,
SqlSugarRepository bookingStatusRepository,
SqlSugarRepository djyUserMailAccountRepository,
SqlSugarRepository taskPerBillBaseInfoRepository,
SqlSugarRepository taskStoreMsgInfoRepository,
SqlSugarRepository taskChangeShipHisInfoRepository,
SqlSugarRepository bookingOrderContactRepository,
SqlSugarRepository taskTruckInfoRepository,
SqlSugarRepository taskTruckCtnRepository,
SqlSugarRepository taskBCInfoRepository,
SqlSugarRepository taskBCCTNInfoRepository,
SqlSugarRepository taskCutDateChangeInfoRepository,
SqlSugarRepository taskCutDateChangeDetailInfoRepository,
SqlSugarRepository taskRollingNominationInfoRepository,
SqlSugarRepository taskRollingNominationShipInfoRepository,
SqlSugarRepository taskRollingNominationDetailInfoRepository,
SqlSugarRepository bookingCtnVGMRepository,
SqlSugarRepository bookingSlotBaseRepository,
SqlSugarRepository taskDraftInfoRepository,
SqlSugarRepository taskPODDischargeGateoutFullInfoRepository,
SqlSugarRepository taskPODDischargeGateoutFullDetailInfoRepository,
SqlSugarRepository taskCautionNoticeInfoRepository,
SqlSugarRepository taskCautionNoticeDetailInfoRepository,
SqlSugarRepository taskRouteChangeAdvisoryInfoRepository,
SqlSugarRepository taskRouteChangeAdvisoryDetailInfoRepository,
SqlSugarRepository taskTransPlanHasChangeInfoRepository,
SqlSugarRepository taskTransPlanHasChangeDetailInfoRepository,
SqlSugarRepository taskPOLContainerNotPickUpInfoRepository,
INamedServiceProvider namedBookingOrderServiceProvider,
IDjyWebsiteAccountConfigService webAccountConfig,
ISysCacheService cache,
ISysDataUserMenu sysDataUserMenuService,
INamedServiceProvider namedRollingNominationServiceProvider,
INamedServiceProvider namedTaskManageBCServiceProvider,
IBookingValueAddedService bookingValueAddedService,
INamedServiceProvider namedBookingMSKAPIServiceProvider,
INamedServiceProvider namedtaskSISubmittedServiceProvider,
INamedServiceProvider namedTaskCautionNoticeServiceProvider,
INamedServiceProvider namedTaskTransPlanHasChangeServiceProvider,
INamedServiceProvider namedTaskPOLContainerNotPickUpServiceProvider,
INamedServiceProvider namedTaskManageCutDateChangeServiceProvider,
INamedServiceProvider namedRouteChangeAdvisoryServiceServiceProvider,
INamedServiceProvider namedBookingLabelServiceServiceProvider,
INamedServiceProvider namedPODDischargeGateoutFullProvider,
INamedServiceProvider namedVGMServiceProvider,
ILogger logger, BookingOrderAutoService bookingOrderAuto,
SqlSugarRepository taskFlowTenant)
{
_taskBaseInfoRepository = taskBaseInfoRepository;
_taskSISubmittedRepository = taskSISubmittedRepository;
_taskSISubmittedCtnRepository = taskSISubmittedCtnRepository;
_taskBillFeeDetailInfoRepository = taskBillFeeDetailInfoRepository;
_taskFileInfoRepository = taskFileInfoRepository;
_taskEmailInfoRepository = taskEmailInfoRepository;
_taskVGMInfoRepository = taskVGMInfoRepository;
_taskVGMCtnInfoRepository = taskVGMCtnInfoRepository;
_sysUserRepository = sysUserRepository;
_taskStatManageInfoRepository = taskStatManageInfoRepository;
_taskOriginalDownloadHisInfoRepository = taskOriginalDownloadHisInfoRepository;
_taskChargesHisInfoRepository = taskChargesHisInfoRepository;
_bookingOrderRepository = bookingOrderRepository;
_taskLARAPaperInfoRepository = taskLARAPaperInfoRepository;
_bookingOrderContaRepository = bookingOrderContaRepository;
_bookingOrderContaCargoRepository = bookingOrderContaCargoRepository;
_bookingStatusRepository = bookingStatusRepository;
_djyUserMailAccountRepository = djyUserMailAccountRepository;
_taskPerBillBaseInfoRepository = taskPerBillBaseInfoRepository;
_taskStoreMsgInfoRepository = taskStoreMsgInfoRepository;
_taskChangeShipHisInfoRepository = taskChangeShipHisInfoRepository;
_bookingOrderContactRepository = bookingOrderContactRepository;
_taskTruckInfoRepository = taskTruckInfoRepository;
_taskTruckCtnRepository = taskTruckCtnRepository;
_taskBCInfoRepository = taskBCInfoRepository;
_taskBCCTNInfoRepository = taskBCCTNInfoRepository;
_taskCutDateChangeInfoRepository = taskCutDateChangeInfoRepository;
_taskCutDateChangeDetailInfoRepository = taskCutDateChangeDetailInfoRepository;
_taskRollingNominationInfoRepository = taskRollingNominationInfoRepository;
_taskRollingNominationShipInfoRepository = taskRollingNominationShipInfoRepository;
_taskRollingNominationDetailInfoRepository = taskRollingNominationDetailInfoRepository;
_bookingCtnVGMRepository = bookingCtnVGMRepository;
_namedBookingOrderServiceProvider = namedBookingOrderServiceProvider;
_namedRollingNominationServiceProvider = namedRollingNominationServiceProvider;
_bookingValueAddedService = bookingValueAddedService;
_namedTaskManageBCServiceProvider = namedTaskManageBCServiceProvider;
_namedtaskSISubmittedServiceProvider = namedtaskSISubmittedServiceProvider;
_namedTaskCautionNoticeServiceProvider = namedTaskCautionNoticeServiceProvider;
_sysDataUserMenuService = sysDataUserMenuService;
_webAccountConfig = webAccountConfig;
_cache = cache;
_logger = logger;
_bookingSlotBaseRepository = bookingSlotBaseRepository;
_taskDraftInfoRepository = taskDraftInfoRepository;
_taskPODDischargeGateoutFullInfoRepository = taskPODDischargeGateoutFullInfoRepository;
_taskPODDischargeGateoutFullDetailInfoRepository = taskPODDischargeGateoutFullDetailInfoRepository;
_namedBookingMSKAPIServiceProvider = namedBookingMSKAPIServiceProvider;
_taskCautionNoticeInfoRepository = taskCautionNoticeInfoRepository;
_taskCautionNoticeDetailInfoRepository = taskCautionNoticeDetailInfoRepository;
_taskRouteChangeAdvisoryInfoRepository = taskRouteChangeAdvisoryInfoRepository;
_taskRouteChangeAdvisoryDetailInfoRepository = taskRouteChangeAdvisoryDetailInfoRepository;
_taskTransPlanHasChangeInfoRepository = taskTransPlanHasChangeInfoRepository;
_taskTransPlanHasChangeDetailInfoRepository = taskTransPlanHasChangeDetailInfoRepository;
_namedTaskTransPlanHasChangeServiceProvider = namedTaskTransPlanHasChangeServiceProvider;
_taskPOLContainerNotPickUpInfoRepository = taskPOLContainerNotPickUpInfoRepository;
_namedTaskPOLContainerNotPickUpServiceProvider = namedTaskPOLContainerNotPickUpServiceProvider;
_namedTaskManageCutDateChangeServiceProvider = namedTaskManageCutDateChangeServiceProvider;
_namedRouteChangeAdvisoryServiceServiceProvider = namedRouteChangeAdvisoryServiceServiceProvider;
_bookingOrderAuto = bookingOrderAuto;
_taskFlowTenant = taskFlowTenant;
_namedBookingLabelServiceServiceProvider = namedBookingLabelServiceServiceProvider;
_namedPODDischargeGateoutFullProvider = namedPODDischargeGateoutFullProvider;
_namedVGMServiceProvider = namedVGMServiceProvider;
}
#region 创建任务
///
/// 创建任务
///
/// 任务详情
/// 返回回执
[HttpPost("/TaskManage/CreateTaskJob"), AllowAnonymous, ApiUser(ApiCode = "BCTaskManage")]
public async Task CreateTaskJob(TaskManageOrderMessageInfo info)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
_logger.LogInformation("批次={no} 接收到创建任务报文 报文={msg}", batchNo, JSON.Serialize(info));
try
{
result = await InitTaskJob(info, batchNo);
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"请求任务异常,{ex.Message}";
}
return result;
}
#endregion
#region 新增任务
///
/// 新增任务
///
/// 任务详情
/// 批次号
/// 文件
/// 变更文件内容后的文件
/// 返回回执
[SqlSugarUnitOfWork]
private async Task InitTaskJob(TaskManageOrderMessageInfo info,string batchNo, IFormFile file = null, IFormFile modifyFile = null)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
_logger.LogInformation("批次={no} 接收到创建任务报文 开始查询任务 OUT_BUSI_NO={out}", batchNo, $"{info.Head.SenderId}_{info.Head.GID}");
var taskInfo = _taskBaseInfoRepository.AsQueryable().OrderByDescending(a=>a.CreatedTime)
.First(t => t.OUT_BUSI_NO == $"{info.Head.SenderId}_{info.Head.GID}");
_logger.LogInformation("批次={no} 接收到创建任务报文 结束查询任务 {msg}", batchNo, taskInfo == null ? "不存在" : "存在");
/*
只要任务最后一次处理任务的状态是已取消、已完成,就可以重入新的任务
*/
if (taskInfo != null && taskInfo.STATUS != TaskStatusEnum.Cancel.ToString() && taskInfo.STATUS != TaskStatusEnum.Complete.ToString())
{
_logger.LogInformation("批次={no} 状态已存在,不能重复创建任务 status={status}", batchNo, taskInfo.STATUS);
throw Oops.Oh($"状态已存在,不能重复创建任务");
}
//如果文件路径不为空 判断文件是否真实存在
if (!string.IsNullOrWhiteSpace(info.Main.FilePath) && !File.Exists(info.Main.FilePath))
{
throw Oops.Oh(string.Format("{0}文件不存在", info.Main.FilePath));
}
//如果文件路径不为空 判断文件是否真实存在
if (!string.IsNullOrWhiteSpace(info.Main.ModifyFile) && !File.Exists(info.Main.ModifyFile))
{
throw Oops.Oh(string.Format("{0}文件不存在", info.Main.ModifyFile));
}
taskInfo = new TaskBaseInfo
{
PK_ID = IDGen.NextID().ToString(),
STATUS = TaskStatusEnum.Create.ToString(),
IsDeleted = false,
IS_EXCEPT = 0,
IS_COMPLETE = 0,
MBL_NO = info.Main.MBlNo,
TASK_BASE_TYPE = info.Main.TaskType.ToString(),
CARRIER_ID = info.Main.CarrierId?.Trim(),
IS_PUBLIC = string.IsNullOrWhiteSpace(info.Main.TaskUserId) ? 1 : 0,
BOOK_ORDER_NO = info.Main.BookingOrderNo,
OUT_BUSI_NO = $"{info.Head.SenderId}_{info.Head.GID}",
TASK_TITLE = info.Main.TaskTitle,
TASK_DESP = info.Main.TaskDesp,
TASK_SOURCE = info.Main.TaskSource.ToString(),
TASK_TYPE = info.Main.TaskType.ToString(),
VESSEL_VOYNO = info.Main.VesselVoyno?.Trim(),
CONTA_INFO = info.Main.ContaInfo,
TASK_REQ_USERNAME = info.Main.TaskUserName,
YARD_NAME = info.Main.YardName,
ETD = info.Main.ETD,
CUSTOMER_ID = info.Main.CustomerId,
CUSTOMER_NAME = info.Main.CustomerName,
BATCH_STATIC = info.Main.BatchStatic,
DJYUserId = info.Head.DJYUserId,
SYSTEM_CODE = info.Main.SYSTEM_CODE,
SYSTEM_NAME = info.Main.SYSTEM_NAME,
};
long taskReqUserId = 0;
if (!string.IsNullOrWhiteSpace(info.Main.TaskUserId))
{
if (long.TryParse(info.Main.TaskUserId, out taskReqUserId))
{
taskInfo.TASK_REQ_USERID = taskReqUserId;
}
}
UserTendDto userTendInfo = null;
//如果大简云用户ID不为空,接收人为空时,通过大简云用户ID关联订舱人ID
if (UserManager.UserId != null)
{
//这里只有派车不是公共任务,其他基本都是公共任务
if (info.Main.TaskType == TaskBaseTypeEnum.TRUCK_DISPATCH)
{
userTendInfo = GetUserTendInfo(info.Main.RecvUserId);
taskInfo.IS_PUBLIC = 0;
}
else if (info.Main.TaskType == TaskBaseTypeEnum.CAUTION_NOTICE)
{
userTendInfo = GetUserTendInfo(info.Main.TaskUserId);
taskInfo.IS_PUBLIC = 0;
}
else
{
userTendInfo = new UserTendDto
{
userId = UserManager.UserId,
userName = UserManager.Name,
tendId = UserManager.TENANT_ID,
tenantName = UserManager.TENANT_NAME
};
if (info.Main.TaskType != TaskBaseTypeEnum.CAUTION_NOTICE)
{
taskInfo.IS_PUBLIC = 1;
}
}
}
else if (!string.IsNullOrWhiteSpace(info.Main.DJYRecvUserId) && string.IsNullOrWhiteSpace(info.Main.TaskUserId))
{
userTendInfo = GetUserTendInfoByDJYUserId(info.Main.DJYRecvUserId, info.Main.DJYRecvUserEmail);
if (userTendInfo != null)
{
taskInfo.IS_PUBLIC = 0;
}
}
else if (string.IsNullOrWhiteSpace(info.Main.DJYRecvUserId) && string.IsNullOrWhiteSpace(info.Main.TaskUserId) &&
!string.IsNullOrWhiteSpace(info.Main.TaskRecvEmail) && info.Main.TaskTenatId.HasValue && info.Main.TaskTenatId.Value > 0)
{
userTendInfo = GetUserTendInfoByEmail(info.Main.TaskTenatId.Value, info.Main.TaskRecvEmail);
if (userTendInfo != null)
{
taskInfo.IS_PUBLIC = 1;
}
}
else
{
userTendInfo = GetUserTendInfo(info.Main.RecvUserId);
}
taskInfo.CreatedUserId = userTendInfo.userId;
taskInfo.CreatedUserName = userTendInfo.userName;
taskInfo.TenantId = userTendInfo.tendId;
taskInfo.TenantName = userTendInfo.tenantName;
_logger.LogInformation("批次={no} 获取登录人详情 userid={userid} userinfo={userinfo}", batchNo,
info.Main.RecvUserId,
JSON.Serialize(userTendInfo));
taskInfo.CreatedTime = DateTime.Now;
taskInfo.UpdatedTime = taskInfo.CreatedTime;
if (!string.IsNullOrWhiteSpace(taskInfo.CARRIER_ID)
&& taskInfo.CARRIER_ID == "MSC")
{
if (TaskBaseTypeEnum.BC.ToString() == taskInfo.TASK_BASE_TYPE)
taskInfo.TASK_TYPE = TaskBusiTypeEnum.MSC_BC.ToString();
if (taskInfo.IS_EXCEPT == 1)
taskInfo.TASK_TYPE = TaskBusiTypeEnum.MSC_EXCEPT.ToString();
}
if (info.Main != null && info.Main.TruckInfo != null && info.Main.TruckInfo.NeedArriveTime.HasValue)
{
taskInfo.NeedArriveTime = info.Main.TruckInfo.NeedArriveTime;
}
//新增
_taskBaseInfoRepository.Insert(taskInfo);
if (!string.IsNullOrWhiteSpace( info.Main.FilePath))
{
string attachFileType = string.Empty;
string fileCategory = string.Empty;
if (TaskBaseTypeEnum.BC.ToString() == taskInfo.TASK_BASE_TYPE)
{
attachFileType = "bcfiles";
fileCategory = TaskFileCategoryEnum.BC.ToString();
}
else if (TaskBaseTypeEnum.BC_MODIFY.ToString() == taskInfo.TASK_BASE_TYPE)
{
attachFileType = "bcmodifyfiles";
fileCategory = TaskFileCategoryEnum.BC_MODIFY.ToString();
}
else if (TaskBaseTypeEnum.CANCELLATION.ToString() == taskInfo.TASK_BASE_TYPE)
{
attachFileType = "bccancelfiles";
fileCategory = TaskFileCategoryEnum.BC_CANCEL.ToString();
}
else if (TaskBaseTypeEnum.DRAFT.ToString() == taskInfo.TASK_BASE_TYPE)
{
attachFileType = "draftfiles";
fileCategory = TaskFileCategoryEnum.DRAFT.ToString();
}
else if (TaskBaseTypeEnum.SI_FEEDBACK.ToString() == taskInfo.TASK_BASE_TYPE)
{
attachFileType = "sisubmittedfiles";
fileCategory = TaskFileCategoryEnum.SI_SUBMITTED.ToString();
}
else if (TaskBaseTypeEnum.ROUTE_CUT_CHANGE.ToString() == taskInfo.TASK_BASE_TYPE)
{
attachFileType = "advisoryfiles";
fileCategory = TaskFileCategoryEnum.ADVISORY.ToString();
}
if (info.Main.FileList == null)
{
info.Main.FileList = new List();
}
info.Main.FileList.Add(new TaskManageOrderFileInfo
{
PKId = IDGen.NextID().ToString(),
FileName = Path.GetFileName(info.Main.FilePath),
FileType = Path.GetExtension(info.Main.FilePath).ToLower(),
FilePath = info.Main.FilePath,
FileCategory = fileCategory
});
}
else
{
if (file != null)
{
var bytes = file.ToByteArray();
string attachFileType = string.Empty;
string fileCategory = string.Empty;
if (TaskBaseTypeEnum.BC.ToString() == taskInfo.TASK_BASE_TYPE)
{
attachFileType = "bcfiles";
fileCategory = TaskFileCategoryEnum.BC.ToString();
}
else if (TaskBaseTypeEnum.BC_MODIFY.ToString() == taskInfo.TASK_BASE_TYPE)
{
attachFileType = "bcmodifyfiles";
fileCategory = TaskFileCategoryEnum.BC_MODIFY.ToString();
}
else if (TaskBaseTypeEnum.CANCELLATION.ToString() == taskInfo.TASK_BASE_TYPE)
{
attachFileType = "bccancelfiles";
fileCategory = TaskFileCategoryEnum.BC_CANCEL.ToString();
}
else if (TaskBaseTypeEnum.DRAFT.ToString() == taskInfo.TASK_BASE_TYPE)
{
attachFileType = "draftfiles";
fileCategory = TaskFileCategoryEnum.DRAFT.ToString();
}
else if (TaskBaseTypeEnum.SI_FEEDBACK.ToString() == taskInfo.TASK_BASE_TYPE)
{
attachFileType = "sisubmittedfiles";
fileCategory = TaskFileCategoryEnum.SI_SUBMITTED.ToString();
}
else if (TaskBaseTypeEnum.ROUTE_CUT_CHANGE.ToString() == taskInfo.TASK_BASE_TYPE)
{
attachFileType = "advisoryfiles";
fileCategory = TaskFileCategoryEnum.ADVISORY.ToString();
}
var noExtensionFileName = Path.GetFileNameWithoutExtension(file.FileName);
var fileFullName = await FileAttachHelper.SaveFile(taskInfo.PK_ID, bytes, batchNo, noExtensionFileName,
GetFileType(file.FileName), attachFileType);
if (!string.IsNullOrWhiteSpace(fileFullName))
{
if (info.Main.FileList == null)
{
info.Main.FileList = new List();
}
info.Main.FileList.Add(new TaskManageOrderFileInfo
{
PKId = IDGen.NextID().ToString(),
FileName = file.FileName,
FileType = Path.GetExtension(file.FileName).ToLower(),
FilePath = fileFullName,
FileCategory = fileCategory
});
}
}
}
if (!string.IsNullOrWhiteSpace(info.Main.ModifyFile))
{
string fileCategory = string.Empty;
if (TaskBaseTypeEnum.BC.ToString() == taskInfo.TASK_BASE_TYPE)
fileCategory = TaskFileCategoryEnum.BC_NOTICE.ToString();
else if (TaskBaseTypeEnum.BC_MODIFY.ToString() == taskInfo.TASK_BASE_TYPE)
fileCategory = TaskFileCategoryEnum.BC_MODIFY_NOTICE.ToString();
else if (TaskBaseTypeEnum.CANCELLATION.ToString() == taskInfo.TASK_BASE_TYPE)
fileCategory = TaskFileCategoryEnum.BC_CANCEL_NOTICE.ToString();
else if (TaskBaseTypeEnum.DRAFT.ToString() == taskInfo.TASK_BASE_TYPE)
fileCategory = TaskFileCategoryEnum.DRAFT_NOTICE.ToString();
if (info.Main.FileList == null)
info.Main.FileList = new List();
info.Main.FileList.Add(new TaskManageOrderFileInfo
{
PKId = IDGen.NextID().ToString(),
FileName = Path.GetFileName(info.Main.ModifyFile),
FileType = Path.GetExtension(info.Main.ModifyFile).ToLower(),
FilePath = info.Main.FilePath,
FileCategory = fileCategory
});
}
else
{
if (modifyFile != null)
{
var bytes = modifyFile.ToByteArray();
string attachFileType = string.Empty;
string fileCategory = string.Empty;
if (TaskBaseTypeEnum.BC.ToString() == taskInfo.TASK_BASE_TYPE)
{
attachFileType = "bcnoticefiles";
fileCategory = TaskFileCategoryEnum.BC_NOTICE.ToString();
}
else if (TaskBaseTypeEnum.BC_MODIFY.ToString() == taskInfo.TASK_BASE_TYPE)
{
attachFileType = "bcmodifynoticefiles";
fileCategory = TaskFileCategoryEnum.BC_MODIFY_NOTICE.ToString();
}
else if (TaskBaseTypeEnum.CANCELLATION.ToString() == taskInfo.TASK_BASE_TYPE)
{
attachFileType = "bccancelnoticefiles";
fileCategory = TaskFileCategoryEnum.BC_CANCEL_NOTICE.ToString();
}
else if (TaskBaseTypeEnum.DRAFT.ToString() == taskInfo.TASK_BASE_TYPE)
{
attachFileType = "draftnoticefiles";
fileCategory = TaskFileCategoryEnum.DRAFT_NOTICE.ToString();
}
var noExtensionFileName = Path.GetFileNameWithoutExtension(modifyFile.FileName);
var fileFullName = await FileAttachHelper.SaveFile(taskInfo.PK_ID, bytes, batchNo, noExtensionFileName,
GetFileType(modifyFile.FileName), attachFileType);
if (!string.IsNullOrWhiteSpace(fileFullName))
{
if (info.Main.FileList == null)
{
info.Main.FileList = new List();
}
info.Main.FileList.Add(new TaskManageOrderFileInfo
{
PKId = IDGen.NextID().ToString(),
FileName = modifyFile.FileName,
FileType = Path.GetExtension(modifyFile.FileName).ToLower(),
FilePath = fileFullName,
FileCategory = fileCategory
});
}
}
}
#region 附件
//附件
if (info.Main.FileList != null && info.Main.FileList.Count > 0)
{
info.Main.FileList.ForEach(async file =>
{
var fileInfo = new TaskFileInfo();
fileInfo.PK_ID = IDGen.NextID().ToString();
fileInfo.TASK_PKID = taskInfo.PK_ID;
fileInfo.CreatedTime = taskInfo.CreatedTime;
fileInfo.UpdatedTime = taskInfo.CreatedTime;
fileInfo.CreatedUserId = taskInfo.CreatedUserId;
fileInfo.CreatedUserName = taskInfo.CreatedUserName;
fileInfo.TenantId = taskInfo.TenantId;
fileInfo.TenantName = taskInfo.TenantName;
fileInfo.FILE_PATH = file.FilePath;
fileInfo.FILE_NAME = file.FileName;
fileInfo.FILE_TYPE = file.FileType;
if (string.IsNullOrWhiteSpace(file.FileCategory))
{
if (TaskBaseTypeEnum.BC.ToString() == taskInfo.TASK_BASE_TYPE)
{
fileInfo.FILE_CATEGORY = TaskFileCategoryEnum.BC.ToString();
fileInfo.FILE_CATEGORY_NAME = TaskFileCategoryEnum.BC.GetDescription();
}
else if (TaskBaseTypeEnum.BC_MODIFY.ToString() == taskInfo.TASK_BASE_TYPE)
{
fileInfo.FILE_CATEGORY = TaskFileCategoryEnum.BC_MODIFY.ToString();
fileInfo.FILE_CATEGORY_NAME = TaskFileCategoryEnum.BC_MODIFY.GetDescription();
}
}
else
{
TaskFileCategoryEnum fileCategoryEnum = TaskFileCategoryEnum.NONE;
System.Enum.TryParse(file.FileCategory, out fileCategoryEnum);
fileInfo.FILE_CATEGORY = fileCategoryEnum.ToString();
fileInfo.FILE_CATEGORY_NAME = fileCategoryEnum.GetDescription();
}
if (string.IsNullOrWhiteSpace(fileInfo.FILE_NAME))
{
var fileModel = new FileInfo(file.FilePath);
fileInfo.FILE_NAME = fileModel.Name;
fileInfo.FILE_TYPE = fileModel.Extension?.Replace(".", "");
}
await _taskFileInfoRepository.InsertAsync(fileInfo);
});
}
#endregion
#region 邮件
//邮件
if (info.Main.EmailList != null && info.Main.EmailList.Count > 0)
{
info.Main.EmailList.ForEach(async email =>
{
var emailInfo = new TaskEmailInfo();
emailInfo.PK_ID = IDGen.NextID().ToString();
emailInfo.TASK_PKID = taskInfo.PK_ID;
emailInfo.CreatedTime = taskInfo.CreatedTime;
emailInfo.UpdatedTime = taskInfo.CreatedTime;
emailInfo.CreatedUserId = taskInfo.CreatedUserId;
emailInfo.CreatedUserName = taskInfo.CreatedUserName;
emailInfo.TenantId = taskInfo.TenantId;
emailInfo.TenantName = taskInfo.TenantName;
emailInfo.MAIL_PATH = email.MailPath;
await _taskEmailInfoRepository.InsertAsync(emailInfo);
});
}
#endregion
#region SI反馈入库
//SI反馈入库
if (info.Main.TaskType == TaskBaseTypeEnum.SI_FEEDBACK)
{
if (info.Main.SIFeedBack == null)
throw Oops.Oh($"任务类型={info.Main.TaskType.ToString()} SIFeedBack信息必传");
TaskSISubmitted taskSISubmitted = info.Main.SIFeedBack.Adapt();
taskSISubmitted.PK_ID = IDGen.NextID().ToString();
taskSISubmitted.TASK_ID = taskInfo.PK_ID;
taskSISubmitted.CreatedTime = taskInfo.CreatedTime;
taskSISubmitted.UpdatedTime = taskInfo.CreatedTime;
taskSISubmitted.CreatedUserId = taskInfo.CreatedUserId;
taskSISubmitted.CreatedUserName = taskInfo.CreatedUserName;
taskSISubmitted.TenantId = taskInfo.TenantId;
taskSISubmitted.TenantName = taskInfo.TenantName;
_taskSISubmittedRepository.Insert(taskSISubmitted);
//SI反馈箱信息入库
if (info.Main.SIFeedBack.ContaList != null && info.Main.SIFeedBack.ContaList.Count > 0)
{
var ediCtnList = _cache.GetAllCodeCtn().GetAwaiter().GetResult();
info.Main.SIFeedBack.ContaList.ForEach(ctn =>
{
var contaInfo = ctn.Adapt();
contaInfo.PK_ID = IDGen.NextID().ToString();
contaInfo.P_PKID = taskSISubmitted.PK_ID;
contaInfo.CreatedTime = taskInfo.CreatedTime;
contaInfo.UpdatedTime = taskInfo.CreatedTime;
contaInfo.CreatedUserId = taskInfo.CreatedUserId;
contaInfo.CreatedUserName = taskInfo.CreatedUserName;
contaInfo.TenantId = taskInfo.TenantId;
contaInfo.TenantName = taskInfo.TenantName;
if (string.IsNullOrWhiteSpace(contaInfo.CTNCODE) && !string.IsNullOrWhiteSpace(contaInfo.CTNALL))
{
if (ediCtnList != null && ediCtnList.Count > 0)
{
var ctnCodeInfo = ediCtnList.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.Name)
&& x.Name.Equals(contaInfo.CTNALL, StringComparison.OrdinalIgnoreCase));
if (ctnCodeInfo != null)
{
contaInfo.CTNCODE = ctnCodeInfo.Code;
}
}
}
_taskSISubmittedCtnRepository.Insert(contaInfo);
});
}
var siService = _namedtaskSISubmittedServiceProvider
.GetService(nameof(TaskManageSISubmittedService));
await siService.ProcessSISubmitted(taskSISubmitted.TASK_ID);
}
#endregion
#region 费用明细
//费用明细
if (info.Main.TaskType == TaskBaseTypeEnum.INVOICE_BILL_MAIL)
{
if (info.Main.FeeList != null && info.Main.FeeList.Count > 0)
{
info.Main.FeeList.ForEach(async fee =>
{
var feeInfo = fee.Adapt();
feeInfo.PK_ID = IDGen.NextID().ToString();
feeInfo.TASK_PKID = taskInfo.PK_ID;
feeInfo.CreatedTime = taskInfo.CreatedTime;
feeInfo.UpdatedTime = taskInfo.CreatedTime;
feeInfo.CreatedUserId = taskInfo.CreatedUserId;
feeInfo.CreatedUserName = taskInfo.CreatedUserName;
feeInfo.TenantId = taskInfo.TenantId;
feeInfo.TenantName = taskInfo.TenantName;
await _taskBillFeeDetailInfoRepository.InsertAsync(feeInfo);
});
}
}
#endregion
#region 单票账单
if (info.Main.TaskType == TaskBaseTypeEnum.PER_BILL)
{
TaskPerBillBaseInfo taskPerBillBaseInfo = info.Main.PerBillInfo.Adapt();
//写入
await _taskPerBillBaseInfoRepository.InsertAsync(taskPerBillBaseInfo);
if (info.Main.FeeList != null && info.Main.FeeList.Count > 0)
{
info.Main.FeeList.ForEach(async fee =>
{
var feeInfo = fee.Adapt();
feeInfo.PK_ID = IDGen.NextID().ToString();
feeInfo.TASK_PKID = taskInfo.PK_ID;
feeInfo.CreatedTime = taskInfo.CreatedTime;
feeInfo.UpdatedTime = taskInfo.CreatedTime;
feeInfo.CreatedUserId = taskInfo.CreatedUserId;
feeInfo.CreatedUserName = taskInfo.CreatedUserName;
feeInfo.TenantId = taskInfo.TenantId;
feeInfo.TenantName = taskInfo.TenantName;
await _taskBillFeeDetailInfoRepository.InsertAsync(feeInfo);
});
}
}
#endregion
#region 派车任务
if (info.Main.TaskType == TaskBaseTypeEnum.TRUCK_DISPATCH)
{
//派车任务
if (info.Main.TruckInfo == null)
{
throw Oops.Oh($"派车任务主信息不能为空,请查看请求报文");
}
var truckInfo = info.Main.TruckInfo.Adapt();
truckInfo.PK_ID = IDGen.NextID().ToString();
truckInfo.TASK_ID = taskInfo.PK_ID;
truckInfo.BookingTruckId = info.Main.TruckInfo.Id;
truckInfo.CreatedTime = taskInfo.CreatedTime;
truckInfo.UpdatedTime = taskInfo.CreatedTime;
truckInfo.CreatedUserId = taskInfo.CreatedUserId;
truckInfo.CreatedUserName = taskInfo.CreatedUserName;
truckInfo.TenantId = taskInfo.TenantId;
truckInfo.TenantName = taskInfo.TenantName;
truckInfo.Status = BookingTruckStatus.TEMP.ToString();
//异步写入
await _taskTruckInfoRepository.InsertAsync(truckInfo);
if(info.Main.TruckInfo.ContaList != null && info.Main.TruckInfo.ContaList.Count > 0)
{
var contaList = info.Main.TruckInfo.ContaList.Adapt>();
contaList.ForEach(async x =>
{
x.P_ID = truckInfo.PK_ID;
x.PK_ID = IDGen.NextID().ToString();
x.CreatedTime = taskInfo.CreatedTime;
x.UpdatedTime = taskInfo.CreatedTime;
x.CreatedUserId = taskInfo.CreatedUserId;
x.CreatedUserName = taskInfo.CreatedUserName;
x.TenantId = taskInfo.TenantId;
x.TenantName = taskInfo.TenantName;
await _taskTruckCtnRepository.InsertAsync(x);
});
}
}
#endregion
#region BC 任务
if (info.Main.TaskType == TaskBaseTypeEnum.BC || info.Main.TaskType == TaskBaseTypeEnum.BC_MODIFY
|| info.Main.TaskType == TaskBaseTypeEnum.CANCELLATION)
{
//异步写入
var bcInfo = info.Main.BCInfo.Adapt();
bcInfo.PK_ID = IDGen.NextID().ToString();
bcInfo.TASK_ID = taskInfo.PK_ID;
bcInfo.CreatedTime = taskInfo.CreatedTime;
bcInfo.UpdatedTime = taskInfo.CreatedTime;
bcInfo.CreatedUserId = taskInfo.CreatedUserId;
bcInfo.CreatedUserName = taskInfo.CreatedUserName;
bcInfo.TenantId = taskInfo.TenantId;
bcInfo.TenantName = taskInfo.TenantName;
if (info.Main.BCInfo.BookingSlotId.HasValue && info.Main.BCInfo.BookingSlotId.Value > 0)
bcInfo.BOOKING_SLOT_ID = info.Main.BCInfo.BookingSlotId.Value;
await _taskBCInfoRepository.InsertAsync(bcInfo);
//异步写入集装箱
info.Main.BCInfo.CtnList.ForEach(async ctn =>
{
var bcCtnInfo = ctn.Adapt();
bcCtnInfo.PK_ID = IDGen.NextID().ToString();
bcCtnInfo.P_ID = bcInfo.PK_ID;
bcInfo.CreatedTime = taskInfo.CreatedTime;
bcInfo.UpdatedTime = taskInfo.CreatedTime;
bcInfo.CreatedUserId = taskInfo.CreatedUserId;
bcInfo.CreatedUserName = taskInfo.CreatedUserName;
bcInfo.TenantId = taskInfo.TenantId;
bcInfo.TenantName = taskInfo.TenantName;
await _taskBCCTNInfoRepository.InsertAsync(bcCtnInfo);
});
/*
BC_MODIFY
1、检索对应舱位,提取比对差异结果
2、检索舱位对应的订舱信息,如果有则生成用户通知邮件
3、推送钉钉消息@操作人 通知收到变更
CANCELLATION
1、检索舱位对应的订舱信息,如果有则生成用户通知邮件
2、推送钉钉消息@操作人 通知收到变更
*/
if (info.Main.TaskType == TaskBaseTypeEnum.BC)
{
var service = _namedBookingMSKAPIServiceProvider
.GetService(nameof(BookingMSKAPIService));
var synRlt = await service.SyncBCInfo(info.Main.BCInfo.MBLNo, taskInfo.TenantId.Value);
_logger.LogInformation($"入库完BC,自动推送状态到API订舱列表 mblno={info.Main.BCInfo.MBLNo} synRlt={JSON.Serialize(synRlt)}");
}
else if (info.Main.TaskType == TaskBaseTypeEnum.CANCELLATION)
{
var service = _namedBookingMSKAPIServiceProvider
.GetService(nameof(BookingMSKAPIService));
var synRlt = await service.SyncBCInfo(info.Main.BCInfo.MBLNo, taskInfo.TenantId.Value,"Cancellation");
_logger.LogInformation($"入库完BC,自动推送状态到API订舱列表 mblno={info.Main.BCInfo.MBLNo} synRlt={JSON.Serialize(synRlt)}");
}
var name = _namedTaskManageBCServiceProvider
.GetService(nameof(TaskManageBCService));
if (info.Main.TaskType == TaskBaseTypeEnum.BC_MODIFY)
{
await name.SyncBookingSlotChange(bcInfo.TASK_ID, bcInfo.TenantId.Value);
}
await name.SyncDjyVesselInfo(bcInfo.TASK_ID);
#region 自动化处理
//if (taskInfo.CARRIER_ID =="CMA")
//{
// var flow = _taskFlowTenant.AsQueryable().Filter(null, true).Where(t => t.FlowCode == "CMABC" && t.IsMain == true &&t.TenantId== taskInfo.TenantId.Value).First();
// if (flow!=null)
// {
// //方法请求参数
// RecursiveMethodModel mt = new RecursiveMethodModel();
// //TODO待完善请求参数
// mt.parse_attachment = info.Main.parse_attachment;
// RecursiveMethod(flow, 0, mt);
// }
//}
#endregion
}
#endregion
#region 截止时间变更通知
if (info.Main.TaskType == TaskBaseTypeEnum.CUT_MODIFY)
{
var cutInfo = info.Main.CutDateChange.Adapt();
cutInfo.PK_ID = IDGen.NextID().ToString();
cutInfo.TASK_ID = taskInfo.PK_ID;
cutInfo.CreatedTime = taskInfo.CreatedTime;
cutInfo.UpdatedTime = taskInfo.CreatedTime;
cutInfo.CreatedUserId = taskInfo.CreatedUserId;
cutInfo.CreatedUserName = taskInfo.CreatedUserName;
cutInfo.TenantId = taskInfo.TenantId;
cutInfo.TenantName = taskInfo.TenantName;
_taskCutDateChangeInfoRepository.Insert(cutInfo);
if (info.Main.CutDateChange.Details != null && info.Main.CutDateChange.Details.Count > 0)
{
//异步写入明细
info.Main.CutDateChange.Details.ForEach(detail =>
{
var cutDetail = detail.Adapt();
cutDetail.PK_ID = IDGen.NextID().ToString();
cutDetail.P_ID = cutInfo.PK_ID;
cutDetail.CreatedTime = taskInfo.CreatedTime;
cutDetail.UpdatedTime = taskInfo.CreatedTime;
cutDetail.CreatedUserId = taskInfo.CreatedUserId;
cutDetail.CreatedUserName = taskInfo.CreatedUserName;
cutDetail.TenantId = taskInfo.TenantId;
cutDetail.TenantName = taskInfo.TenantName;
_taskCutDateChangeDetailInfoRepository.Insert(cutDetail);
});
}
//触发推送消息
var name = _namedTaskManageCutDateChangeServiceProvider
.GetService(nameof(TaskManageCutDateChangeService));
await name.AutoTransferNotice(taskInfo.PK_ID);
}
#endregion
#region VGM回执或VGM未提交提醒
if (info.Main.TaskType == TaskBaseTypeEnum.VGM_FEEDBACK
|| info.Main.TaskType == TaskBaseTypeEnum.VGM_MISSING)
{
List vgmList = new List();
info.Main.VGMFeedBack.ForEach(p =>
{
//异步写入
var vgmInfo = p.Adapt();
vgmInfo.PK_ID = IDGen.NextID().ToString();
vgmInfo.TASK_ID = taskInfo.PK_ID;
vgmInfo.CreatedTime = taskInfo.CreatedTime;
vgmInfo.UpdatedTime = taskInfo.CreatedTime;
vgmInfo.CreatedUserId = taskInfo.CreatedUserId;
vgmInfo.CreatedUserName = taskInfo.CreatedUserName;
vgmInfo.TenantId = taskInfo.TenantId;
vgmInfo.TenantName = taskInfo.TenantName;
vgmInfo.TASK_TYPE = info.Main.TaskType.ToString();
_taskVGMInfoRepository.InsertAsync(vgmInfo);
vgmList.Add(vgmInfo);
if (p.CtnList != null && p.CtnList.Count > 0)
{
//异步写入集装箱
p.CtnList.ForEach(ctn =>
{
var vgmCtnInfo = ctn.Adapt();
vgmCtnInfo.PK_ID = IDGen.NextID().ToString();
vgmCtnInfo.P_ID = vgmInfo.PK_ID;
vgmCtnInfo.CreatedTime = taskInfo.CreatedTime;
vgmCtnInfo.UpdatedTime = taskInfo.CreatedTime;
vgmCtnInfo.CreatedUserId = taskInfo.CreatedUserId;
vgmCtnInfo.CreatedUserName = taskInfo.CreatedUserName;
vgmCtnInfo.TenantId = taskInfo.TenantId;
vgmCtnInfo.TenantName = taskInfo.TenantName;
_taskVGMCtnInfoRepository.InsertAsync(vgmCtnInfo);
});
}
});
var mblNoList = info.Main.VGMFeedBack.Select(p => p.MBlNo).Distinct().ToList();
/*
1、入库完检索对应的订舱信息。
2、推送订舱相关的状态。
*/
var bookingList = _bookingOrderRepository.AsQueryable().Filter(null, true)
.Where(x => mblNoList.Contains(x.MBLNO) && (x.ParentId == 0 || x.ParentId == null)
&& x.IsDeleted == false && x.TenantId == taskInfo.TenantId).ToList();
if (bookingList.Count > 0)
{
vgmList.ForEach(vgmInfo =>
{
var bookingInfo = bookingList.FirstOrDefault(a =>
a.MBLNO.Equals(vgmInfo.MBL_NO, StringComparison.OrdinalIgnoreCase));
if (bookingInfo != null)
{
var vgmEntity = _taskVGMInfoRepository.AsQueryable().Filter(null, true)
.First(x => x.PK_ID == vgmInfo.PK_ID && x.IsDeleted == false && x.TenantId == taskInfo.TenantId);
vgmEntity.BOOKING_ID = bookingInfo.Id;
_taskVGMInfoRepository.AsUpdateable(vgmEntity).UpdateColumns(x => x.BOOKING_ID).ExecuteCommandAsync();
var ctnVGMList = _bookingCtnVGMRepository.AsQueryable().Filter(null, true)
.Where(x => x.BILLID == bookingInfo.Id && x.IsDeleted == false && x.TenantId == taskInfo.TenantId).ToList();
var bookCtnList = _bookingOrderContaRepository.AsQueryable().Filter(null, true)
.Where(x => x.BILLID == bookingInfo.Id && x.IsDeleted == false && x.TenantId == taskInfo.TenantId).ToList();
var ctnList = info.Main.VGMFeedBack
.FirstOrDefault(x => x.MBlNo.Equals(vgmInfo.MBL_NO, StringComparison.OrdinalIgnoreCase)).CtnList;
if (info.Main.TaskType == TaskBaseTypeEnum.VGM_FEEDBACK)
{
//推送状态
var pushModel = new ModifyServiceProjectStatusDto
{
BookingId = bookingInfo.Id,
SourceType = TrackingSourceTypeEnum.AUTO,
StatusCodes = new List {
new ModifyServiceProjectStatusDetailDto { StatusCode = "VGMCG" } }
};
var saveStatusRlt = _bookingValueAddedService.SaveServiceStatus(pushModel).GetAwaiter().GetResult();
_logger.LogInformation("请求JSON={json} 异步推送服务状态完成,结果={rlt}", JSON.Serialize(pushModel), JSON.Serialize(saveStatusRlt));
foreach (var ctn in ctnList)
{
var bookCtnVGM = ctnVGMList.FirstOrDefault(t => t.CNTRNO.Equals(ctn.CntrNo, StringComparison.OrdinalIgnoreCase));
var bookCtn = bookCtnList.FirstOrDefault(t => t.CNTRNO.Equals(ctn.CntrNo, StringComparison.OrdinalIgnoreCase));
if (bookCtnVGM != null)
{
//更新
bookCtnVGM.UpdatedTime = taskInfo.CreatedTime;
bookCtnVGM.UpdatedUserId = taskInfo.CreatedUserId;
bookCtnVGM.UpdatedUserName = taskInfo.CreatedUserName;
bookCtnVGM.IS_MISSING = false;
bookCtnVGM.SUBMISSION_DEADLINE = null;
_bookingCtnVGMRepository.AsUpdateable(bookCtnVGM).UpdateColumns(x => new
{
x.VGM_WEIGHT,
x.VGM_WEIGHT_UNIT,
x.VGM_METHOD,
x.IS_MATCH,
x.UpdatedTime,
x.UpdatedUserId,
x.UpdatedUserName
}).ExecuteCommand();
}
else
{
//写入
var bookingCtnVGM = new BookingCtnVGM
{
CNTRNO = ctn.CntrNo,
BILLID = bookingInfo.Id,
VGM_WEIGHT = ctn.VGMWeight,
VGM_WEIGHT_UNIT = ctn.VGMWeightUnit,
VGM_METHOD = ctn.VGMWeightMethod,
IS_MATCH = bookCtn != null,
CreatedTime = taskInfo.CreatedTime,
UpdatedTime = taskInfo.CreatedTime,
CreatedUserId = taskInfo.CreatedUserId,
CreatedUserName = taskInfo.CreatedUserName,
TenantId = taskInfo.TenantId,
REC_TIME = vgmInfo.NOTICE_DATE
};
_bookingCtnVGMRepository.Insert(bookingCtnVGM);
}
}
}
else
{
if (ctnList.Count > 0)
{
foreach (var ctn in ctnList)
{
var bookCtnVGM = ctnVGMList.FirstOrDefault(t => t.CNTRNO.Equals(ctn.CntrNo, StringComparison.OrdinalIgnoreCase));
var bookCtn = bookCtnList.FirstOrDefault(t => t.CNTRNO.Equals(ctn.CntrNo, StringComparison.OrdinalIgnoreCase));
if (bookCtnVGM == null)
{
//写入
var bookingCtnVGM = new BookingCtnVGM
{
CNTRNO = ctn.CntrNo,
BILLID = bookingInfo.Id,
VGM_WEIGHT = ctn.VGMWeight,
VGM_WEIGHT_UNIT = ctn.VGMWeightUnit,
VGM_METHOD = ctn.VGMWeightMethod,
IS_MATCH = bookCtn != null,
CreatedTime = taskInfo.CreatedTime,
UpdatedTime = taskInfo.CreatedTime,
CreatedUserId = taskInfo.CreatedUserId,
CreatedUserName = taskInfo.CreatedUserName,
TenantId = taskInfo.TenantId,
REC_TIME = vgmInfo.NOTICE_DATE,
IS_MISSING = true,
SUBMISSION_DEADLINE = vgmInfo.VGM_SUBMISSION_DEADLINE
};
_bookingCtnVGMRepository.Insert(bookingCtnVGM);
}
}
}
}
}
});
}
//触发推送消息
var name = _namedVGMServiceProvider
.GetService(nameof(TaskManageVGMService));
await name.SendVGMMissingNotice(taskInfo.PK_ID);
}
#endregion
#region Rolling Nomination(预甩货通知)
if (info.Main.TaskType == TaskBaseTypeEnum.ROLLING_NOMINATION || info.Main.TaskType == TaskBaseTypeEnum.TRANSFER_NOMINATION)
{
var rollingNomination = info.Main.RollingNomination.Adapt();
rollingNomination.PK_ID = IDGen.NextID().ToString();
rollingNomination.TASK_ID = taskInfo.PK_ID;
rollingNomination.CreatedTime = taskInfo.CreatedTime;
rollingNomination.UpdatedTime = taskInfo.CreatedTime;
rollingNomination.CreatedUserId = taskInfo.CreatedUserId;
rollingNomination.CreatedUserName = taskInfo.CreatedUserName;
rollingNomination.TenantId = taskInfo.TenantId;
rollingNomination.TenantName = taskInfo.TenantName;
//这里把多条的预甩计划列表合并保存,展示时只需要用\n拆分返回给前端
if (info.Main.RollingNomination.RollingPlanList != null && info.Main.RollingNomination.RollingPlanList.Count > 0)
{
rollingNomination.PLAN_TXT = string.Join("\\n", info.Main.RollingNomination.RollingPlanList.ToArray());
}
await _taskRollingNominationInfoRepository.InsertAsync(rollingNomination);
if (info.Main.RollingNomination.From != null && info.Main.RollingNomination.From.Count > 0)
{
info.Main.RollingNomination.From.ForEach(k =>
{
var rollingNominationShip = k.Adapt();
rollingNominationShip.PK_ID = IDGen.NextID().ToString();
rollingNominationShip.TASK_ID = taskInfo.PK_ID;
rollingNominationShip.NOM_ID = rollingNomination.PK_ID;
rollingNominationShip.CreatedTime = taskInfo.CreatedTime;
rollingNominationShip.UpdatedTime = taskInfo.CreatedTime;
rollingNominationShip.CreatedUserId = taskInfo.CreatedUserId;
rollingNominationShip.CreatedUserName = taskInfo.CreatedUserName;
rollingNominationShip.TenantId = taskInfo.TenantId;
rollingNominationShip.TenantName = taskInfo.TenantName;
_taskRollingNominationShipInfoRepository.Insert(rollingNominationShip);
});
}
if (info.Main.RollingNomination.ToDetail != null && info.Main.RollingNomination.ToDetail.Count > 0)
{
var ctnCodeList = _cache.GetAllCodeCtn().GetAwaiter().GetResult().ToList();
info.Main.RollingNomination.ToDetail.ForEach(t =>
{
var rollingNominationShip = t.Adapt();
rollingNominationShip.PK_ID = IDGen.NextID().ToString();
rollingNominationShip.TASK_ID = taskInfo.PK_ID;
rollingNominationShip.NOM_ID = rollingNomination.PK_ID;
rollingNominationShip.CreatedTime = taskInfo.CreatedTime;
rollingNominationShip.UpdatedTime = taskInfo.CreatedTime;
rollingNominationShip.CreatedUserId = taskInfo.CreatedUserId;
rollingNominationShip.CreatedUserName = taskInfo.CreatedUserName;
rollingNominationShip.TenantId = taskInfo.TenantId;
rollingNominationShip.TenantName = taskInfo.TenantName;
_taskRollingNominationShipInfoRepository.Insert(rollingNominationShip);
if (t.NominationList != null && t.NominationList.Count > 0)
{
//这里直接批量检索订舱信息,如果有对应的提单号直接写入订舱主键
var billNoList = t.NominationList.Select(x => x.Shipment.ToUpper())
.Distinct().ToArray();
var bookList = _bookingOrderRepository.AsQueryable().Filter(null, true)
.Where(x => billNoList.Contains(x.MBLNO) && x.IsDeleted == false && x.TenantId == taskInfo.TenantId).ToList();
t.NominationList.ForEach(x =>
{
var rollingNominationDetail = x.Adapt();
if (!string.IsNullOrWhiteSpace(rollingNominationDetail.CTNALL))
{
var ctnCode = ctnCodeList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.Name) &&
a.Name.Equals(rollingNominationDetail.CTNALL, StringComparison.OrdinalIgnoreCase));
rollingNominationDetail.CTNCODE = ctnCode?.Code;
}
rollingNominationDetail.PK_ID = IDGen.NextID().ToString();
rollingNominationDetail.NOM_SHIP_ID = rollingNominationShip.PK_ID;
rollingNominationDetail.NOM_ID = rollingNomination.PK_ID;
rollingNominationDetail.CreatedTime = taskInfo.CreatedTime;
rollingNominationDetail.UpdatedTime = taskInfo.CreatedTime;
rollingNominationDetail.CreatedUserId = taskInfo.CreatedUserId;
rollingNominationDetail.CreatedUserName = taskInfo.CreatedUserName;
rollingNominationDetail.TenantId = taskInfo.TenantId;
rollingNominationDetail.TenantName = taskInfo.TenantName;
var bookingInfo = bookList.FirstOrDefault(x =>
x.MBLNO.Equals(rollingNominationDetail.SHIPMENT, StringComparison.OrdinalIgnoreCase));
if (bookingInfo != null)
{
rollingNominationDetail.BOOKING_ID = bookingInfo.Id;
rollingNominationDetail.CUSTOMERID = bookingInfo.CUSTOMERID;
rollingNominationDetail.CUSTOMERNAME = bookingInfo.CUSTOMERNAME;
}
_taskRollingNominationDetailInfoRepository.Insert(rollingNominationDetail);
});
}
});
}
//异步生成调度
var rollNominationService = _namedRollingNominationServiceProvider
.GetService(nameof(TaskManageRollingNominationService));
var dispatchRlt = await rollNominationService.DispatchRollingNomination(new RollingNominationDispatchRequestDto {
isAdd = true,
nominationId = rollingNomination.PK_ID
});
}
#endregion
#region DRAFT转发客户
if (info.Main.TaskType == TaskBaseTypeEnum.DRAFT)
{
TaskDraftInfo taskDraftInfo = info.Main.DraftInfo.Adapt();
taskDraftInfo.PK_ID = IDGen.NextID().ToString();
taskDraftInfo.TASK_ID = taskInfo.PK_ID;
taskDraftInfo.CreatedTime = taskInfo.CreatedTime;
taskDraftInfo.UpdatedTime = taskInfo.CreatedTime;
taskDraftInfo.CreatedUserId = taskInfo.CreatedUserId;
taskDraftInfo.CreatedUserName = taskInfo.CreatedUserName;
taskDraftInfo.TenantId = taskInfo.TenantId;
taskDraftInfo.TenantName = taskInfo.TenantName;
await _taskDraftInfoRepository.InsertAsync(taskDraftInfo);
}
#endregion
#region 任务目的港未提货/任务目的港提货未返空
if (info.Main.TaskType == TaskBaseTypeEnum.POD_DISCHARGE_FULL || info.Main.TaskType == TaskBaseTypeEnum.POD_GATEOUT_FULL)
{
TaskPODDischargeGateoutFullInfo dischargeGateout = info.Main.PODDischargeGateoutFull.Adapt();
dischargeGateout.PK_ID = IDGen.NextID().ToString();
dischargeGateout.TASK_ID = taskInfo.PK_ID;
dischargeGateout.CreatedTime = taskInfo.CreatedTime;
dischargeGateout.UpdatedTime = taskInfo.CreatedTime;
dischargeGateout.CreatedUserId = taskInfo.CreatedUserId;
dischargeGateout.CreatedUserName = taskInfo.CreatedUserName;
dischargeGateout.TenantId = taskInfo.TenantId;
dischargeGateout.TenantName = taskInfo.TenantName;
await _taskPODDischargeGateoutFullInfoRepository.InsertAsync(dischargeGateout);
//明细入库
if (info.Main.PODDischargeGateoutFull.DetailList != null
&& info.Main.PODDischargeGateoutFull.DetailList.Count > 0)
{
info.Main.PODDischargeGateoutFull.DetailList.ForEach(async ctn =>
{
var detailInfo = ctn.Adapt();
detailInfo.PK_ID = IDGen.NextID().ToString();
detailInfo.P_ID = dischargeGateout.PK_ID;
detailInfo.CreatedTime = taskInfo.CreatedTime;
detailInfo.UpdatedTime = taskInfo.CreatedTime;
detailInfo.CreatedUserId = taskInfo.CreatedUserId;
detailInfo.CreatedUserName = taskInfo.CreatedUserName;
detailInfo.TenantId = taskInfo.TenantId;
detailInfo.TenantName = taskInfo.TenantName;
await _taskPODDischargeGateoutFullDetailInfoRepository.InsertAsync(detailInfo);
});
}
//触发推送消息
var name = _namedPODDischargeGateoutFullProvider
.GetService(nameof(TaskManagePODDischargeGateoutFullService));
await name.AutoTransferNotice(taskInfo.PK_ID);
}
#endregion
#region 重要提醒
if (info.Main.TaskType == TaskBaseTypeEnum.CAUTION_NOTICE)
{
TaskCautionNoticeInfo taskCautionNoticeInfo = info.Main.CautionNoticeInfo.Adapt();
taskCautionNoticeInfo.PK_ID = IDGen.NextID().ToString();
taskCautionNoticeInfo.TASK_ID = taskInfo.PK_ID;
taskCautionNoticeInfo.CreatedTime = taskInfo.CreatedTime;
taskCautionNoticeInfo.UpdatedTime = taskInfo.CreatedTime;
taskCautionNoticeInfo.CreatedUserId = taskInfo.CreatedUserId;
taskCautionNoticeInfo.CreatedUserName = taskInfo.CreatedUserName;
taskCautionNoticeInfo.TenantId = taskInfo.TenantId;
taskCautionNoticeInfo.TenantName = taskInfo.TenantName;
taskCautionNoticeInfo.CAUTION_NOTICE_TYPE = info.Main.CautionNoticeInfo.CautionNoticeType.ToString();
await _taskCautionNoticeInfoRepository.InsertAsync(taskCautionNoticeInfo);
//异步写入集装箱
info.Main.CautionNoticeInfo.NoticeList.ForEach(async notice =>
{
var noticeInfo = notice.Adapt();
noticeInfo.NOTIFY_METHOD = notice.CautionNoticeType.ToString();
noticeInfo.PK_ID = IDGen.NextID().ToString();
noticeInfo.P_ID = taskCautionNoticeInfo.PK_ID;
noticeInfo.CreatedTime = taskInfo.CreatedTime;
noticeInfo.UpdatedTime = taskInfo.CreatedTime;
noticeInfo.CreatedUserId = taskInfo.CreatedUserId;
noticeInfo.CreatedUserName = taskInfo.CreatedUserName;
noticeInfo.TenantId = taskInfo.TenantId;
noticeInfo.TenantName = taskInfo.TenantName;
noticeInfo.STATUS = TaskCautionNoticeStatusEnum.TEMP.ToString();
noticeInfo.STATUS_NAME = TaskCautionNoticeStatusEnum.TEMP.GetDescription();
await _taskCautionNoticeDetailInfoRepository.InsertAsync(noticeInfo);
});
//这里加了个判断如果没有标记自动发送消息就不触发转发功能
if (info.Main.CautionNoticeInfo.IsAutoSendNotice == true)
{
//触发推送消息
var name = _namedTaskCautionNoticeServiceProvider
.GetService(nameof(TaskCautionNoticeService));
await name.TriggerSendNotice(taskInfo.PK_ID, taskInfo.TenantId.Value);
}
}
#endregion
#region 航线船舶截止时间调整的通知
if (info.Main.TaskType == TaskBaseTypeEnum.ROUTE_CUT_CHANGE)
{
TaskRouteChangeAdvisoryInfo taskRouteChangeAdvisoryInfo = info.Main.RouteChangeAdvisoryInfo.Adapt();
taskRouteChangeAdvisoryInfo.PK_ID = IDGen.NextID().ToString();
taskRouteChangeAdvisoryInfo.TASK_ID = taskInfo.PK_ID;
taskRouteChangeAdvisoryInfo.CreatedTime = taskInfo.CreatedTime;
taskRouteChangeAdvisoryInfo.UpdatedTime = taskInfo.CreatedTime;
taskRouteChangeAdvisoryInfo.CreatedUserId = taskInfo.CreatedUserId;
taskRouteChangeAdvisoryInfo.CreatedUserName = taskInfo.CreatedUserName;
taskRouteChangeAdvisoryInfo.TenantId = taskInfo.TenantId;
taskRouteChangeAdvisoryInfo.TenantName = taskInfo.TenantName;
if (!string.IsNullOrWhiteSpace(taskRouteChangeAdvisoryInfo.READ_PORTLOAD))
{
var portList = _cache.GetAllCodePortLoad().GetAwaiter().GetResult();
if (portList != null && portList.Count > 0)
{
var portInfo = portList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.EnName) && a.EnName.Equals(taskRouteChangeAdvisoryInfo.READ_PORTLOAD,StringComparison.OrdinalIgnoreCase));
if (portInfo != null)
{
taskRouteChangeAdvisoryInfo.PORTLOADID = portInfo?.EdiCode;
taskRouteChangeAdvisoryInfo.PORTLOAD = portInfo?.EnName;
}
}
}
await _taskRouteChangeAdvisoryInfoRepository.InsertAsync(taskRouteChangeAdvisoryInfo);
//触发推送消息
var name = _namedRouteChangeAdvisoryServiceServiceProvider
.GetService(nameof(RouteChangeAdvisoryService));
await name.AutoTransferNotice(taskInfo.PK_ID);
}
#endregion
#region 货物运输计划已变更
if (info.Main.TaskType == TaskBaseTypeEnum.TRNAS_PLAN_HAS_CHANGE)
{
TaskTransPlanHasChangeInfo taskTransPlanHasChangeInfo = info.Main.TransportPlanHasChangeInfo.Adapt();
taskTransPlanHasChangeInfo.PK_ID = IDGen.NextID().ToString();
taskTransPlanHasChangeInfo.TASK_ID = taskInfo.PK_ID;
taskTransPlanHasChangeInfo.CreatedTime = taskInfo.CreatedTime;
taskTransPlanHasChangeInfo.UpdatedTime = taskInfo.CreatedTime;
taskTransPlanHasChangeInfo.CreatedUserId = taskInfo.CreatedUserId;
taskTransPlanHasChangeInfo.CreatedUserName = taskInfo.CreatedUserName;
taskTransPlanHasChangeInfo.TenantId = taskInfo.TenantId;
taskTransPlanHasChangeInfo.TenantName = taskInfo.TenantName;
await _taskTransPlanHasChangeInfoRepository.InsertAsync(taskTransPlanHasChangeInfo);
if(info.Main.TransportPlanHasChangeInfo.From != null)
{
if(info.Main.TransportPlanHasChangeInfo.From.portList != null
&& info.Main.TransportPlanHasChangeInfo.From.portList.Count > 0)
{
info.Main.TransportPlanHasChangeInfo.From.portList.ForEach(p => {
TaskTransPlanHasChangeDetailInfo detailInfo = new TaskTransPlanHasChangeDetailInfo {
PORTLOAD = p.PortName,
PORTLOAD_COUNTRY = p.CountryCode,
PORTLOAD_TERMINAL = p.TerminalName,
SORT_NO = p.Indx,
IS_REMOVED = p.IsRemoved
};
detailInfo.PK_ID = IDGen.NextID().ToString();
detailInfo.P_ID = taskTransPlanHasChangeInfo.PK_ID;
detailInfo.PLAN_TYPE = "FROM";
detailInfo.COLUMN_TYPE = "PORT";
detailInfo.CreatedTime = taskInfo.CreatedTime;
detailInfo.UpdatedTime = taskInfo.CreatedTime;
detailInfo.CreatedUserId = taskInfo.CreatedUserId;
detailInfo.CreatedUserName = taskInfo.CreatedUserName;
detailInfo.TenantId = taskInfo.TenantId;
detailInfo.TenantName = taskInfo.TenantName;
_taskTransPlanHasChangeDetailInfoRepository.Insert(detailInfo);
});
}
if (info.Main.TransportPlanHasChangeInfo.From.dateList != null
&& info.Main.TransportPlanHasChangeInfo.From.dateList.Count > 0)
{
info.Main.TransportPlanHasChangeInfo.From.dateList.ForEach(p => {
TaskTransPlanHasChangeDetailInfo detailInfo = new TaskTransPlanHasChangeDetailInfo
{
ETD = p.DateVal,
SORT_NO = p.Indx,
IS_REMOVED = p.IsRemoved
};
detailInfo.PK_ID = IDGen.NextID().ToString();
detailInfo.P_ID = taskTransPlanHasChangeInfo.PK_ID;
detailInfo.PLAN_TYPE = "FROM";
detailInfo.COLUMN_TYPE = "EATD";
detailInfo.CreatedTime = taskInfo.CreatedTime;
detailInfo.UpdatedTime = taskInfo.CreatedTime;
detailInfo.CreatedUserId = taskInfo.CreatedUserId;
detailInfo.CreatedUserName = taskInfo.CreatedUserName;
detailInfo.TenantId = taskInfo.TenantId;
detailInfo.TenantName = taskInfo.TenantName;
_taskTransPlanHasChangeDetailInfoRepository.Insert(detailInfo);
});
}
if (info.Main.TransportPlanHasChangeInfo.From.vesselList != null
&& info.Main.TransportPlanHasChangeInfo.From.vesselList.Count > 0)
{
info.Main.TransportPlanHasChangeInfo.From.vesselList.ForEach(p => {
TaskTransPlanHasChangeDetailInfo detailInfo = new TaskTransPlanHasChangeDetailInfo
{
VESSEL = p.Vessel,
VOYNO = p.Voyno,
SHIP_FLAG = p.Flag,
SORT_NO = p.Indx,
IS_REMOVED = p.IsRemoved
};
detailInfo.PK_ID = IDGen.NextID().ToString();
detailInfo.P_ID = taskTransPlanHasChangeInfo.PK_ID;
detailInfo.PLAN_TYPE = "FROM";
detailInfo.COLUMN_TYPE = "VESSEL";
detailInfo.CreatedTime = taskInfo.CreatedTime;
detailInfo.UpdatedTime = taskInfo.CreatedTime;
detailInfo.CreatedUserId = taskInfo.CreatedUserId;
detailInfo.CreatedUserName = taskInfo.CreatedUserName;
detailInfo.TenantId = taskInfo.TenantId;
detailInfo.TenantName = taskInfo.TenantName;
_taskTransPlanHasChangeDetailInfoRepository.Insert(detailInfo);
});
}
}
if (info.Main.TransportPlanHasChangeInfo.To != null)
{
if (info.Main.TransportPlanHasChangeInfo.To.portList != null
&& info.Main.TransportPlanHasChangeInfo.To.portList.Count > 0)
{
info.Main.TransportPlanHasChangeInfo.To.portList.ForEach(p => {
TaskTransPlanHasChangeDetailInfo detailInfo = new TaskTransPlanHasChangeDetailInfo
{
PORTDISCHARGE = p.PortName,
PORTDISCHARGE_COUNTRY = p.CountryCode,
PORTDISCHARGE_TERMINAL = p.TerminalName,
SORT_NO = p.Indx,
IS_REMOVED = p.IsRemoved
};
detailInfo.PK_ID = IDGen.NextID().ToString();
detailInfo.P_ID = taskTransPlanHasChangeInfo.PK_ID;
detailInfo.PLAN_TYPE = "TO";
detailInfo.COLUMN_TYPE = "PORT";
detailInfo.CreatedTime = taskInfo.CreatedTime;
detailInfo.UpdatedTime = taskInfo.CreatedTime;
detailInfo.CreatedUserId = taskInfo.CreatedUserId;
detailInfo.CreatedUserName = taskInfo.CreatedUserName;
detailInfo.TenantId = taskInfo.TenantId;
detailInfo.TenantName = taskInfo.TenantName;
_taskTransPlanHasChangeDetailInfoRepository.Insert(detailInfo);
});
}
if (info.Main.TransportPlanHasChangeInfo.To.dateList != null
&& info.Main.TransportPlanHasChangeInfo.To.dateList.Count > 0)
{
info.Main.TransportPlanHasChangeInfo.To.dateList.ForEach(p => {
TaskTransPlanHasChangeDetailInfo detailInfo = new TaskTransPlanHasChangeDetailInfo
{
ETA = p.DateVal,
SORT_NO = p.Indx,
IS_REMOVED = p.IsRemoved
};
detailInfo.PK_ID = IDGen.NextID().ToString();
detailInfo.P_ID = taskTransPlanHasChangeInfo.PK_ID;
detailInfo.PLAN_TYPE = "TO";
detailInfo.COLUMN_TYPE = "EATD";
detailInfo.CreatedTime = taskInfo.CreatedTime;
detailInfo.UpdatedTime = taskInfo.CreatedTime;
detailInfo.CreatedUserId = taskInfo.CreatedUserId;
detailInfo.CreatedUserName = taskInfo.CreatedUserName;
detailInfo.TenantId = taskInfo.TenantId;
detailInfo.TenantName = taskInfo.TenantName;
_taskTransPlanHasChangeDetailInfoRepository.Insert(detailInfo);
});
}
if (info.Main.TransportPlanHasChangeInfo.To.vesselList != null
&& info.Main.TransportPlanHasChangeInfo.To.vesselList.Count > 0)
{
info.Main.TransportPlanHasChangeInfo.To.vesselList.ForEach(p => {
TaskTransPlanHasChangeDetailInfo detailInfo = new TaskTransPlanHasChangeDetailInfo
{
VESSEL = p.Vessel,
VOYNO = p.Voyno,
SHIP_FLAG = p.Flag,
SORT_NO = p.Indx,
IS_REMOVED = p.IsRemoved
};
detailInfo.PK_ID = IDGen.NextID().ToString();
detailInfo.P_ID = taskTransPlanHasChangeInfo.PK_ID;
detailInfo.PLAN_TYPE = "TO";
detailInfo.COLUMN_TYPE = "VESSEL";
detailInfo.CreatedTime = taskInfo.CreatedTime;
detailInfo.UpdatedTime = taskInfo.CreatedTime;
detailInfo.CreatedUserId = taskInfo.CreatedUserId;
detailInfo.CreatedUserName = taskInfo.CreatedUserName;
detailInfo.TenantId = taskInfo.TenantId;
detailInfo.TenantName = taskInfo.TenantName;
_taskTransPlanHasChangeDetailInfoRepository.Insert(detailInfo);
});
}
}
if (info.Main.TransportPlanHasChangeInfo.ContaNoList != null && info.Main.TransportPlanHasChangeInfo.ContaNoList.Count > 0)
{
info.Main.TransportPlanHasChangeInfo.ContaNoList.ForEach(p =>
{
TaskTransPlanHasChangeDetailInfo detailInfo = new TaskTransPlanHasChangeDetailInfo
{
CONTA_NO = p,
};
detailInfo.PK_ID = IDGen.NextID().ToString();
detailInfo.P_ID = taskTransPlanHasChangeInfo.PK_ID;
detailInfo.COLUMN_TYPE = "CTN";
detailInfo.CreatedTime = taskInfo.CreatedTime;
detailInfo.UpdatedTime = taskInfo.CreatedTime;
detailInfo.CreatedUserId = taskInfo.CreatedUserId;
detailInfo.CreatedUserName = taskInfo.CreatedUserName;
detailInfo.TenantId = taskInfo.TenantId;
detailInfo.TenantName = taskInfo.TenantName;
_taskTransPlanHasChangeDetailInfoRepository.Insert(detailInfo);
});
}
//触发推送消息
var name = _namedTaskTransPlanHasChangeServiceProvider
.GetService(nameof(TaskTransPlanHasChangeService));
await name.AutoTransferNotice(taskInfo.PK_ID);
}
#endregion
#region 装货港未提箱通知
if (info.Main.TaskType == TaskBaseTypeEnum.POL_CTN_NOT_PICKUP)
{
TaskPOLContainerNotPickUpInfo taskPOLContainerNotPickUpInfo = info.Main.POLContainerNotPickupInfo.Adapt();
taskPOLContainerNotPickUpInfo.PK_ID = IDGen.NextID().ToString();
taskPOLContainerNotPickUpInfo.TASK_ID = taskInfo.PK_ID;
taskPOLContainerNotPickUpInfo.CreatedTime = taskInfo.CreatedTime;
taskPOLContainerNotPickUpInfo.UpdatedTime = taskInfo.CreatedTime;
taskPOLContainerNotPickUpInfo.CreatedUserId = taskInfo.CreatedUserId;
taskPOLContainerNotPickUpInfo.CreatedUserName = taskInfo.CreatedUserName;
taskPOLContainerNotPickUpInfo.TenantId = taskInfo.TenantId;
taskPOLContainerNotPickUpInfo.TenantName = taskInfo.TenantName;
await _taskPOLContainerNotPickUpInfoRepository.InsertAsync(taskPOLContainerNotPickUpInfo);
//触发推送消息
var name = _namedTaskPOLContainerNotPickUpServiceProvider
.GetService(nameof(TaskPOLContainerNotPickUpService));
await name.AutoTransferNotice(taskInfo.PK_ID);
}
#endregion
#region 黑名单
#endregion
#region 截单补料异常提醒
#endregion
#region 启运港箱使费通知
#endregion
if (info.Main.SerialMsgInfo != null)
{
var storeInfo = new TaskStoreMsgInfo
{
PK_ID = IDGen.NextID().ToString(),
TASK_PKID = taskInfo.PK_ID,
MSG_JSON = info.Main.SerialMsgInfo.SerialMsg,
MSG_TYPE = info.Main.SerialMsgInfo.SerialType,
CreatedTime = taskInfo.CreatedTime,
UpdatedTime = taskInfo.CreatedTime,
CreatedUserId = taskInfo.CreatedUserId,
CreatedUserName = taskInfo.CreatedUserName,
TenantId = taskInfo.TenantId,
TenantName = taskInfo.TenantName,
};
await _taskStoreMsgInfoRepository.InsertAsync(storeInfo);
}
result.succ = true;
result.msg = "新增任务成功";
var md = _taskBaseInfoRepository.AsQueryable().First(a => a.PK_ID == taskInfo.PK_ID);
//回写任务号
result.ext = md?.TASK_NO;
}
catch (Exception ex)
{
throw Oops.Oh($"{ex.Message}");
}
return result;
}
#endregion
///
/// 执行方法
///
/// 当前流程配置
/// 循环深度
public void RecursiveMethod(TaskFlowTenant flow,int depth, RecursiveMethodModel model)
{
depth = depth++;
//防止配置错误引发死循环,此处设置最多深度20层
if (depth>=20)
{
return;
}
// 获取方法信息
MethodInfo methodInfo = typeof(BookingOrderAutoService).GetMethod(flow.MethodName);
// 确保方法存在
if (methodInfo != null)
{
// 调用方法
object result = methodInfo.Invoke(_bookingOrderAuto, new object[] { model });
//如果返回类型为bool
if (flow.IsBoolReturn)
{
if ((bool)result)
{
if (string.IsNullOrEmpty( flow.TrueMethod))
{
return;
}
var newflow = _taskFlowTenant.AsQueryable().Filter(null, true).Where(t => t.MethodName == flow.TrueMethod).First();
RecursiveMethod(newflow, depth,model);
}
if (!(bool)result)
{
if (flow.FalseMethod==null)
{
return;
}
var newflow = _taskFlowTenant.AsQueryable().Filter(null, true).Where(t => t.MethodName == flow.FalseMethod).First();
RecursiveMethod(newflow, depth, model);
}
}
else
{
var newflow = _taskFlowTenant.AsQueryable().Filter(null, true).Where(t => t.PId == flow.PK_ID).First();
if (newflow==null)
{
return;
}
RecursiveMethod(newflow, depth,model);
}
}
else
{
($"方法{flow.MethodName}不存在").LogInformation();
return;
}
}
#region 查询订舱表查询用户和租户信息
///
/// 查询订舱表查询用户和租户信息
///
/// 用户ID
/// 返回用户和租户信息
private UserTendDto GetUserTendInfo(string userId)
{
UserTendDto userTendDto = null;
//这里因为接口是不做授权验证的,所以这里直接写的动态sql提取了用户和租户信息
var userTendInfo = _sysUserRepository.EntityContext.Queryable("user").AS("sys_user")
.AddJoinInfo("sys_tenant", "ten", "user.TenantId=ten.Id")
.Where("user.Id=@id", new { id = long.Parse(userId) })
.Select("user.Id as UserId,user.Name as UserName,ten.Id as TendId,ten.Name as TendName").First();
if (userTendInfo == null || userTendInfo.TendId == null)
throw Oops.Oh("当前用户详情获取失败,请确认{0}赋值是否准确", nameof(TaskManageOrderMessageInfo.Main.TaskUserId));
userTendDto = new UserTendDto
{
userId = long.Parse(userTendInfo.UserId.ToString()),
userName = userTendInfo.UserName.ToString(),
tendId = long.Parse(userTendInfo.TendId.ToString()),
tenantName = userTendInfo.TendName.ToString()
};
return userTendDto;
}
#endregion
#region 查询订舱表查询用户和租户信息
///
/// 查询订舱表查询用户和租户信息
///
/// 大简云用户ID
/// 大简云用户邮箱
/// 返回用户和租户信息
private UserTendDto GetUserTendInfoByDJYUserId(string djyUserId,string djyUserEmail)
{
UserTendDto userTendDto = null;
//这里因为接口是不做授权验证的,所以这里直接写的动态sql提取了用户和租户信息
var userTendInfo = _sysUserRepository.EntityContext.Queryable("user").AS("sys_user")
.AddJoinInfo("sys_tenant", "ten", "user.TenantId=ten.Id")
.Where("user.DjyUserId=@id and user.Email like '%"+ djyUserEmail + "%'", new { id = djyUserId})
.Select("user.Id as UserId,user.Name as UserName,ten.Id as TendId,ten.Name as TendName").First();
if (userTendInfo == null || userTendInfo.TendId == null)
throw Oops.Oh("当前用户详情获取失败,请确认{0}赋值是否准确", nameof(TaskManageOrderMessageInfo.Main.TaskUserId));
userTendDto = new UserTendDto
{
userId = long.Parse(userTendInfo.UserId.ToString()),
userName = userTendInfo.UserName.ToString(),
tendId = long.Parse(userTendInfo.TendId.ToString()),
tenantName = userTendInfo.TendName.ToString()
};
return userTendDto;
}
#endregion
#region 通过租户ID和邮箱获取用户信息
///
/// 通过租户ID和邮箱获取用户信息
///
/// 大简云租户ID
/// 大简云用户邮箱
/// 返回用户和租户信息
private UserTendDto GetUserTendInfoByEmail(long tenantId, string emailAccount)
{
UserTendDto userTendDto = null;
//这里因为接口是不做授权验证的,所以这里直接写的动态sql提取了用户和租户信息
var userTendInfo = _sysUserRepository.EntityContext.Queryable("user").AS("sys_user")
.AddJoinInfo("sys_tenant", "ten", "user.TenantId=ten.Id")
.Where("ten.Id=@id and UPPER(user.Email) = '"+ emailAccount.ToUpper()+ "'", new { id = tenantId })
.Select("user.Id as UserId,user.Name as UserName,ten.Id as TendId,ten.Name as TendName").First();
if (userTendInfo == null || userTendInfo.TendId == null)
throw Oops.Oh("当前用户详情获取失败,请确认{0}赋值是否准确", nameof(TaskManageOrderMessageInfo.Main.TaskUserId));
userTendDto = new UserTendDto
{
userId = long.Parse(userTendInfo.UserId.ToString()),
userName = userTendInfo.UserName.ToString(),
tendId = long.Parse(userTendInfo.TendId.ToString()),
tenantName = userTendInfo.TendName.ToString()
};
return userTendDto;
}
#endregion
#region 获取查询参数
///
/// 获取查询参数
///
/// 参数类型 STATUS-任务状态;TASK_TYPE-任务类型;SOURCE-任务来源 CATEGORY-分类
/// 返回回执
/// TASK_TYPE
[HttpGet("/TaskManage/GetParaInfo")]
public async Task GetParaInfo([QueryString] string ParaType)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
Dictionary dict = new Dictionary();
if (ParaType == "STATUS")
{
dict = EnumUtil.GetEnumDictionaryWithKey(typeof(TaskStatusEnum));
}
else if (ParaType == "TASK_TYPE")
{
dict = EnumUtil.GetEnumDictionaryWithKey(typeof(TaskBusiTypeEnum));
}
else if (ParaType == "SOURCE")
{
dict = EnumUtil.GetEnumDictionaryWithKey(typeof(TaskSourceEnum));
}
else if (ParaType == "CATEGORY")
{
dict = EnumUtil.GetEnumDictionaryWithKey(typeof(TaskStatLevelEnum));
}
result.succ = true;
result.rows = dict.Select(t => new { Code = t.Key, Name = t.Value }).ToList();
}
catch (Exception ex)
{
result.succ = false;
result.msg = ex.Message;
}
return result;
}
#endregion
#region 获取登陆人相关的任务统计信息
///
/// 获取登陆人相关的任务统计信息
///
/// 是否强制计算
/// 返回回执
[HttpGet("/TaskManage/GetCurrentTotalStat")]
public async Task GetCurrentTotalStat([FromQuery] bool isReCalc = false)
{
TaskUserStatResultInfo resultInfo = new TaskUserStatResultInfo
{
LevelTop = new List(),
LevelNext = new List(),
LevelTree = new List()
};
/*
1、首先判断当前登陆人是否有统计记录,如果没有触发统计生成统计记录。
2、如果isReCalc=true,表示强制重新统计数据,并重新更新统计数据。
3、按照统计类型(个人/公共)、任务状态、是否异常分组汇总,并写入统计表。
*/
try
{
var userTendInfo = await _sysUserRepository.AsQueryable()
.LeftJoin((usr, ten) => usr.TenantId == ten.Id)
.Where(usr => usr.Id == UserManager.UserId)
.Select((usr, ten) => new { User = usr, Tend = ten }).FirstAsync();
if (userTendInfo == null)
throw Oops.Oh($"当前用户关联租户信息获取失败");
//var statList = _taskStatManageInfoRepository.AsQueryable().Where(t => (t.USER_ID == userTendInfo.User.Id
//&& t.STAT_TYPE == TaskStatLevelEnum.PERSON.ToString()) || (t.COMP_ID == userTendInfo.Tend.Id && t.STAT_TYPE == TaskStatLevelEnum.PUBLIC.ToString())).ToList();
//菜单375504048771141=我的任务台账
List userlist = await _sysDataUserMenuService.GetDataScopeList(MenuConst.MenuTaskManage);
bool isAdmin = userlist == null;
//任务列表分组统计
var groupList = _taskBaseInfoRepository.AsQueryable()
.Where(t => isAdmin
|| (userlist.Contains(t.CreatedUserId) && t.IS_PUBLIC == 0)
|| (t.RealUserId !=null && userlist.Contains(t.RealUserId.Value) && t.IS_PUBLIC == 0)
|| (t.TenantId == userTendInfo.Tend.Id && t.IS_PUBLIC == 1))
.GroupBy(p => new { p.TASK_TYPE, p.STATUS, p.IS_EXCEPT, p.IS_PUBLIC })
.Select(p => new
{
Total = SqlFunc.AggregateCount(p.PK_ID),
TaskType = p.TASK_TYPE,
Status = p.STATUS,
IsExcept = p.IS_EXCEPT,
IsPublic = p.IS_PUBLIC
}).ToList();
var exceptList = groupList
.Where(t => t.IsExcept == 1).ToList();
var personList = groupList
.Where(t => t.IsExcept == 0 && t.IsPublic == 0).ToList();
var publicList = groupList
.Where(t => t.IsExcept == 0 && t.IsPublic == 1).ToList();
#region 异常
if (exceptList.Count > 0)
{
resultInfo.LevelTop.Add(new TaskUserStatItem
{
Key = TaskStatLevelEnum.EXCPTION.ToString(),
Name = TaskStatLevelEnum.EXCPTION.GetDescription(),
Total = exceptList.Sum(t => t.Total),
SortNo = (int)TaskStatLevelEnum.EXCPTION,
ActionKey = TaskStatLevelEnum.EXCPTION.ToString()
});
var nextList = new List();
exceptList.GroupBy(t => t.Status)
.Select(t => new { Key = t.Key, Total = t.ToList().Sum(p => p.Total) })
.ToList().ForEach(t =>
{
TaskStatusEnum currEnum = (TaskStatusEnum)System.Enum.Parse(typeof(TaskStatusEnum), t.Key);
nextList.Add(new TaskUserStatItemNext
{
TopKey = TaskStatLevelEnum.EXCPTION.ToString(),
Key = currEnum.ToString(),
Name = currEnum.GetDescription(),
Total = t.Total,
SortNo = (int)currEnum,
ActionKey = $"{TaskStatLevelEnum.EXCPTION.ToString()}#{currEnum.ToString()}"
});
});
if (nextList.Count > 0)
resultInfo.LevelNext.AddRange(nextList.OrderBy(t => t.SortNo).ToList());
exceptList.GroupBy(t => new { t.Status, t.TaskType })
.Select(t => new { Key = t.Key, Total = t.ToList().Sum(p => p.Total) })
.ToList().ForEach(t =>
{
TaskBusiTypeEnum currEnum = (TaskBusiTypeEnum)System.Enum.Parse(typeof(TaskBusiTypeEnum), t.Key.TaskType);
resultInfo.LevelTree.Add(new TaskUserStatItemTree
{
TopKey = TaskStatLevelEnum.EXCPTION.ToString(),
NextKey = t.Key.Status,
Key = currEnum.ToString(),
Name = currEnum.GetDescription(),
Total = t.Total,
SortNo = (int)currEnum,
ActionKey = $"{TaskStatLevelEnum.EXCPTION.ToString()}#{t.Key.Status}#{currEnum.ToString()}"
});
});
}
#endregion
#region 个人
if (personList.Count > 0)
{
resultInfo.LevelTop.Add(new TaskUserStatItem
{
Key = TaskStatLevelEnum.PERSON.ToString(),
Name = TaskStatLevelEnum.PERSON.GetDescription(),
Total = personList.Sum(t => t.Total),
SortNo = (int)TaskStatLevelEnum.PERSON,
ActionKey = TaskStatLevelEnum.PERSON.ToString()
});
var nextList = new List();
personList.GroupBy(t => t.Status)
.Select(t => new { Key = t.Key, Total = t.ToList().Sum(p => p.Total) })
.ToList().ForEach(t =>
{
TaskStatusEnum currEnum = (TaskStatusEnum)System.Enum.Parse(typeof(TaskStatusEnum), t.Key);
nextList.Add(new TaskUserStatItemNext
{
TopKey = TaskStatLevelEnum.PERSON.ToString(),
Key = currEnum.ToString(),
Name = currEnum.GetDescription(),
Total = t.Total,
SortNo = (int)currEnum,
ActionKey = $"{TaskStatLevelEnum.PERSON.ToString()}#{currEnum.ToString()}"
});
});
if (nextList.Count > 0)
resultInfo.LevelNext.AddRange(nextList.OrderBy(t => t.SortNo).ToList());
personList.GroupBy(t => new { t.Status, t.TaskType })
.Select(t => new { Key = t.Key, Total = t.ToList().Sum(p => p.Total) })
.ToList().ForEach(t =>
{
TaskBusiTypeEnum currEnum = (TaskBusiTypeEnum)System.Enum.Parse(typeof(TaskBusiTypeEnum), t.Key.TaskType);
resultInfo.LevelTree.Add(new TaskUserStatItemTree
{
TopKey = TaskStatLevelEnum.PERSON.ToString(),
NextKey = t.Key.Status,
Key = currEnum.ToString(),
Name = currEnum.GetDescription(),
Total = t.Total,
SortNo = (int)currEnum,
ActionKey = $"{TaskStatLevelEnum.PERSON.ToString()}#{t.Key.Status}#{currEnum.ToString()}"
});
});
}
#endregion
#region 公共
if (publicList.Count > 0)
{
resultInfo.LevelTop.Add(new TaskUserStatItem
{
Key = TaskStatLevelEnum.PUBLIC.ToString(),
Name = TaskStatLevelEnum.PUBLIC.GetDescription(),
Total = publicList.Sum(t => t.Total),
SortNo = (int)TaskStatLevelEnum.PUBLIC,
ActionKey = TaskStatLevelEnum.PUBLIC.ToString()
});
var nextList = new List();
publicList.GroupBy(t => t.Status)
.Select(t => new { Key = t.Key, Total = t.ToList().Sum(p => p.Total) })
.ToList().ForEach(t =>
{
TaskStatusEnum currEnum = (TaskStatusEnum)System.Enum.Parse(typeof(TaskStatusEnum), t.Key);
nextList.Add(new TaskUserStatItemNext
{
TopKey = TaskStatLevelEnum.PUBLIC.ToString(),
Key = currEnum.ToString(),
Name = currEnum.GetDescription(),
Total = t.Total,
SortNo = (int)currEnum,
ActionKey = $"{TaskStatLevelEnum.PUBLIC.ToString()}#{currEnum.ToString()}"
});
});
if (nextList.Count > 0)
resultInfo.LevelNext.AddRange(nextList.OrderBy(t => t.SortNo).ToList());
publicList.GroupBy(t => new { t.Status, t.TaskType })
.Select(t => new { Key = t.Key, Total = t.ToList().Sum(p => p.Total) })
.ToList().ForEach(t =>
{
TaskBusiTypeEnum currEnum = (TaskBusiTypeEnum)System.Enum.Parse(typeof(TaskBusiTypeEnum), t.Key.TaskType);
resultInfo.LevelTree.Add(new TaskUserStatItemTree
{
TopKey = TaskStatLevelEnum.PUBLIC.ToString(),
NextKey = t.Key.Status,
Key = currEnum.ToString(),
Name = currEnum.GetDescription(),
Total = t.Total,
SortNo = (int)currEnum,
ActionKey = $"{TaskStatLevelEnum.PUBLIC.ToString()}#{t.Key.Status}#{currEnum.ToString()}"
});
});
}
#endregion
if(resultInfo.LevelTree != null && resultInfo.LevelTree.Count > 0)
{
resultInfo.LevelTree = resultInfo.LevelTree.OrderBy(x => x.SortNo).ToList();
}
}
catch (Exception ex)
{
throw Oops.Bah("获取登录人相关的任务统计信息异常,{0}", ex.Message);
}
return resultInfo;
}
#endregion
#region 任务台账查询
///
/// 任务台账查询
///
/// 任务台账查询请求
/// 返回结果
[HttpPost("/TaskManage/GetPage")]
public async Task> GetPageAsync(QueryTaskManageDto QuerySearch)
{
List mblList = new List();
if (!string.IsNullOrWhiteSpace(QuerySearch.MBlNo))
{
if (Regex.IsMatch(QuerySearch.MBlNo, "(\\t|\\n\\r|\\n)"))
{
mblList = Regex.Replace(QuerySearch.MBlNo, "(\\t |\\n\\r |\\n)", "#").Split(new char[] { '#' }).Select(t => t?.Trim()).ToList();
}
else
{
mblList.Add(QuerySearch.MBlNo.Trim().ToUpper());
}
}
DateTime etdBegin = DateTime.MinValue;
DateTime etdEnd = DateTime.MinValue;
DateTime taskDateBegin = DateTime.MinValue;
DateTime taskDateEnd = DateTime.MinValue;
if (!string.IsNullOrWhiteSpace(QuerySearch.ETDBegin))
{
if (!DateTime.TryParse(QuerySearch.ETDBegin, out etdBegin))
throw Oops.Oh($"开船起始日期格式错误,{QuerySearch.ETDBegin}");
}
if (!string.IsNullOrWhiteSpace(QuerySearch.ETDEnd))
{
if (!DateTime.TryParse(QuerySearch.ETDEnd, out etdEnd))
throw Oops.Oh($"开船结束日期格式错误,{QuerySearch.ETDEnd}");
etdEnd = etdEnd.AddDays(1);
}
if (!string.IsNullOrWhiteSpace(QuerySearch.TaskDateBegin))
{
if (!DateTime.TryParse(QuerySearch.TaskDateBegin, out taskDateBegin))
throw Oops.Oh($"任务起始日期格式错误,{QuerySearch.TaskDateBegin}");
}
if (!string.IsNullOrWhiteSpace(QuerySearch.TaskDateEnd))
{
if (!DateTime.TryParse(QuerySearch.TaskDateEnd, out taskDateEnd))
throw Oops.Oh($"任务结束日期格式错误,{QuerySearch.TaskDateEnd}");
taskDateEnd = taskDateEnd.AddDays(1);
}
string entityOrderCol = "CreatedTime";
//这里因为返回给前端的台账数据是DTO,所以这里排序时候需要转换成Entity对应的字段
if (!string.IsNullOrWhiteSpace(QuerySearch.SortField))
entityOrderCol = MapsterExtHelper.GetAdaptProperty(QuerySearch.SortField);
//菜单375504048771141=我的任务台账
List userlist = await _sysDataUserMenuService.GetDataScopeList(MenuConst.MenuTaskManage);
if (userlist == null)
userlist = new List { UserManager.UserId };
if (userlist.Count > 0)
userlist = userlist.Distinct().ToList();
_logger.LogInformation("任务台账权限范围 {list}", userlist);
List userIds = new List();
if (!string.IsNullOrWhiteSpace( QuerySearch.DJYUserId))
{
//获取缓存数据
if (!_cache.Exists(QuerySearch.DJYUserId+ "Authorization"))
{
throw Oops.Bah("无效授权");
}
userIds = JsonConvert.DeserializeObject>( _cache.Get(QuerySearch.DJYUserId));
}
switch (QuerySearch.TaskType)
{
case "BC":
var bc = await _taskBaseInfoRepository.AsQueryable().LeftJoin((t, bc) => t.PK_ID==bc.TASK_ID)
.Where((t, bc) => userlist.Contains(t.CreatedUserId) || (t.RealUserId != null && userlist.Contains(t.RealUserId.Value)) || t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.MBlNo), (t, bc) => mblList.Contains(t.MBL_NO))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskRecvName), (t, bc) => t.CreatedUserName.Contains(QuerySearch.TaskRecvName.Trim()))
.WhereIF(etdBegin != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value >= etdBegin)
.WhereIF(etdEnd != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value < etdEnd)
.WhereIF(taskDateBegin != DateTime.MinValue, (t, bc) => t.CreatedTime >= taskDateBegin)
.WhereIF(taskDateEnd != DateTime.MinValue, (t, bc) => t.CreatedTime < taskDateEnd)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskType), (t, bc) => t.TASK_TYPE.Equals(QuerySearch.TaskType))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskSource), (t, bc) => t.TASK_SOURCE.Equals(QuerySearch.TaskSource))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.EXCPTION.ToString(), (t, bc) => t.IS_EXCEPT == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PUBLIC.ToString(), (t, bc) => t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PERSON.ToString(), (t, bc) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.Status), (t, bc) => t.STATUS.Equals(QuerySearch.Status))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.PKId), (t, bc) => t.PK_ID.Equals(QuerySearch.PKId))
.WhereIF(userIds.Count>0, (t, bc) => userIds.Contains(t.DJYUserId))
.OrderBy(entityOrderCol + (QuerySearch.descSort ? " desc " : " asc "))
.Select((t, bc) => new
{
PK_ID = t.PK_ID.SelectAll(),
bc.BUSI_TYPE,
bc.SHIPPER,
bc.CONSIGNEE,
bc.NOTIFYPARTY,
bc.BC_MODIFY_TIMES,
bc.BC_MODIFY_DATE,
//bc.MBL_NO,
bc.VESSEL,
bc.VOYNO,
bc.CARRIER,
bc.PLACERECEIPT,
bc.PORTLOAD,
bc.CLOSING_DATE,
bc.VGM_CUTOFF_TIME,
bc.ETA,
//bc.ETD,
bc.POD_ETA,
bc.CUT_SINGLE_TIME,
bc.PORTDISCHARGE,
bc.PLACEDELIVERY,
bc.SHIPPING_METHOD,
bc.SERVICE,
bc.PRETRANS_MODE,
bc.DESCRIPTION,
bc.ISSUEPLACE,
bc.COLLECTION_TERMINAL,
bc.CONTRACTNO,
bc.PREPARDAT,
bc.SHIP_AGENT,
bc.YARD,
bc.YARD_CONTACT_USR,
bc.YARD_CONTACT_TEL,
bc.FST_CUSTOMER_SER_USRNAME,
bc.FST_CUSTOMER_SER_TEL,
bc.FST_CUSTOMER_SER_EMAIL,
bc.REMARK1,
bc.CY_CUTOFF_TIME,
bc.CARRIERID,
bc.LANECODE,
bc.LANENAME,
bc.CARRIAGE_TYPE,
bc.CARRIAGE_TYPE_NAME,
bc.BOOKING_SLOT_TYPE,
bc.BOOKING_SLOT_TYPE_NAME,
bc.CTN_STAT,
bc.WEEK_AT,
bc.DETENSION_FREE_DAYS,
bc.SI_CUT_DATE,
bc.MANIFEST_CUT_DATE,
bc.MDGF_CUT_DATE,
bc.TRANSFER_PORT_1,
bc.TRANSFER_PORT_2,
bc.SECOND_VESSEL,
bc.SECOND_VOYNO,
bc.SECOND_ETD,
bc.SECOND_ETA,
//bc.STATUS,
bc.FILE_MD5,
bc.LAST_TOBOOKING_DATE,
bc.FROM_EMAIL,
bc.RECV_EMAIL,
bc.BOOKING_ORDER_ID,
bc.BOOKING_SLOT_ID,
bc.BOOKING_COMFIRM_DATE,
bc.BATCH_NO,
bc.CUSTOM_SI_CUT_DATE,
bc.IS_SET_AUTO_EMAIL,
bc.IS_SEND_EMAIL,
bc.DIFF_NUM,
bc.AUTO_SEND_USER,
bc.PROCESS_STATUS,
bc.PROCESS_RESULT,
bc.PROCESS_DATE,
bc.PRICE_CALCULATION_DATE
})
.ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize);
return bc.Adapt>();
case "SI_FEEDBACK":
var SI_FEEDBACK = await _taskBaseInfoRepository.AsQueryable().LeftJoin((t, bc) => t.PK_ID==bc.TASK_ID)
.Where((t, bc) => userlist.Contains(t.CreatedUserId) || (t.RealUserId != null && userlist.Contains(t.RealUserId.Value)) || t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.MBlNo), (t, bc) => mblList.Contains(t.MBL_NO))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskRecvName), (t, bc) => t.CreatedUserName.Contains(QuerySearch.TaskRecvName.Trim()))
.WhereIF(etdBegin != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value >= etdBegin)
.WhereIF(etdEnd != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value < etdEnd)
.WhereIF(taskDateBegin != DateTime.MinValue, (t, bc) => t.CreatedTime >= taskDateBegin)
.WhereIF(taskDateEnd != DateTime.MinValue, (t, bc) => t.CreatedTime < taskDateEnd)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskType), (t, bc) => t.TASK_TYPE.Equals(QuerySearch.TaskType))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskSource), (t, bc) => t.TASK_SOURCE.Equals(QuerySearch.TaskSource))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.EXCPTION.ToString(), (t, bc) => t.IS_EXCEPT == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PUBLIC.ToString(), (t, bc) => t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PERSON.ToString(), (t, bc) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.Status), (t, bc) => t.STATUS.Equals(QuerySearch.Status))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.PKId), (t, bc) => t.PK_ID.Equals(QuerySearch.PKId))
.WhereIF(userIds.Count>0, (t, bc) => userIds.Contains(t.DJYUserId))
.OrderBy(entityOrderCol + (QuerySearch.descSort ? " desc " : " asc "))
.Select((t, bc) => new
{
PK_ID = t.PK_ID.SelectAll(),
bc.CARRIER,
//bc.MBL_NO,
bc.TAKE_ISSUETYPE_NAME,
bc.ISSUETYPE,
bc.NOTICE_DATE,
bc.BOOKING_ID,
bc.SUBMITTED_DATE,
bc.BILLOF_NUM,
bc.RELEASE_INSTRUCTION,
bc.SI_SUBTYPE,
bc.SHIPPER,
bc.CONSIGNEE,
bc.NOTIFYPARTY,
bc.NOTIFYPARTY2,
bc.TRANSPORT_RECEIVER,
bc.MARKS,
bc.HSCODE,
bc.DESCRIPTION,
bc.PKGS,
bc.KINDPKGS,
bc.KGS,
bc.CBM,
bc.VESSEL,
bc.VOYNO,
bc.COMMODITY,
bc.PLACERECEIPTID,
bc.PLACERECEIPT,
bc.PORTLOADID,
bc.PORTLOAD,
bc.PORTDISCHARGEID,
bc.PORTDISCHARGE,
bc.PLACEDELIVERYID,
bc.PLACEDELIVERY,
bc.PROCESS_STATUS,
bc.IS_SET_AUTO_UPD_BOOKING,
bc.PROCESS_RESULT,
bc.PROCESS_DATE,
bc.DIFF_NUM,
bc.IS_UPDATE_BOOKING,
bc.UPDATE_BOOKING_DATE
}) .ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize);
return SI_FEEDBACK.Adapt>();
case "INVOICE_BILL_MAIL":
var INVOICE_BILL_MAIL = await _taskBaseInfoRepository.AsQueryable().LeftJoin((t, bc) => t.PK_ID==bc.TASK_PKID)
.Where((t, bc) => userlist.Contains(t.CreatedUserId) || (t.RealUserId != null && userlist.Contains(t.RealUserId.Value)) || t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.MBlNo), (t, bc) => mblList.Contains(t.MBL_NO))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskRecvName), (t, bc) => t.CreatedUserName.Contains(QuerySearch.TaskRecvName.Trim()))
.WhereIF(etdBegin != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value >= etdBegin)
.WhereIF(etdEnd != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value < etdEnd)
.WhereIF(taskDateBegin != DateTime.MinValue, (t, bc) => t.CreatedTime >= taskDateBegin)
.WhereIF(taskDateEnd != DateTime.MinValue, (t, bc) => t.CreatedTime < taskDateEnd)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskType), (t, bc) => t.TASK_TYPE.Equals(QuerySearch.TaskType))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskSource), (t, bc) => t.TASK_SOURCE.Equals(QuerySearch.TaskSource))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.EXCPTION.ToString(), (t, bc) => t.IS_EXCEPT == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PUBLIC.ToString(), (t, bc) => t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PERSON.ToString(), (t, bc) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.Status), (t, bc) => t.STATUS.Equals(QuerySearch.Status))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.PKId), (t, bc) => t.PK_ID.Equals(QuerySearch.PKId))
.WhereIF(userIds.Count>0, (t, bc) => userIds.Contains(t.DJYUserId))
.OrderBy(entityOrderCol + (QuerySearch.descSort ? " desc " : " asc "))
.Select((t, bc) => new
{
PK_ID = t.PK_ID.SelectAll(),
bc.TASK_PKID,
//bc.MBL_NO,
bc.INVOICE_NO,
bc.CANCEL_NO,
bc.TOTAL_AMOUNT,
bc.IS_DONGSH_RECV,
bc.IS_DONGSH_RESULT,
bc.DONGSH_RECV_TIME,
bc.DONGSH_RESULT_TIME,
bc.DONGSH_RECV_REASON
}).ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize);
return INVOICE_BILL_MAIL.Adapt>();
case "TRUCK_DISPATCH":
var TRUCK_DISPATCH = await _taskBaseInfoRepository.AsQueryable().LeftJoin((t, bc) => t.PK_ID==bc.TASK_ID)
.Where((t, bc) => userlist.Contains(t.CreatedUserId) || (t.RealUserId != null && userlist.Contains(t.RealUserId.Value)) || t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.MBlNo), (t, bc) => mblList.Contains(t.MBL_NO))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskRecvName), (t, bc) => t.CreatedUserName.Contains(QuerySearch.TaskRecvName.Trim()))
.WhereIF(etdBegin != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value >= etdBegin)
.WhereIF(etdEnd != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value < etdEnd)
.WhereIF(taskDateBegin != DateTime.MinValue, (t, bc) => t.CreatedTime >= taskDateBegin)
.WhereIF(taskDateEnd != DateTime.MinValue, (t, bc) => t.CreatedTime < taskDateEnd)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskType), (t, bc) => t.TASK_TYPE.Equals(QuerySearch.TaskType))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskSource), (t, bc) => t.TASK_SOURCE.Equals(QuerySearch.TaskSource))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.EXCPTION.ToString(), (t, bc) => t.IS_EXCEPT == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PUBLIC.ToString(), (t, bc) => t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PERSON.ToString(), (t, bc) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.Status), (t, bc) => t.STATUS.Equals(QuerySearch.Status))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.PKId), (t, bc) => t.PK_ID.Equals(QuerySearch.PKId))
.WhereIF(userIds.Count>0, (t, bc) => userIds.Contains(t.DJYUserId))
.OrderBy(entityOrderCol + (QuerySearch.descSort ? " desc " : " asc "))
.Select((t, bc) => new
{
PK_ID = t.PK_ID.SelectAll(),
bc.TASK_ID,
bc.BookingTruckId,
bc.BookingId,
bc.TruckId,
bc.TruckCode,
bc.TruckName,
bc.ToName,
bc.Attn,
bc.AttnTel,
bc.AttnMail,
bc.AttnFax,
bc.FromName,
bc.FromTel,
bc.FromMail,
bc.FromMobile,
bc.FromFax,
bc.KGS,
bc.Fee,
bc.PayMethod,
bc.PayMethodName,
bc.TruckTime,
bc.YARDID,
bc.YARD,
bc.YARDCONTRACT,
bc.YARDCONTRACTTEL,
bc.FactoryId,
bc.FactoryCode,
bc.FactoryName,
bc.FactoryContact,
bc.FactoryTel,
bc.ReturnTime,
bc.InYardID,
bc.InYard,
bc.InYardContact,
bc.InYardContractTel,
//bc.NeedArriveTime,
bc.ClosingTime,
bc.PickUpTime,
bc.IsGuaJi,
//bc.Status,
bc.Attention,
bc.Remark,
bc.DispatcherId,
bc.DispatcherName,
bc.TruckFlowNo,
bc.TaskNo,
bc.Vessel,
bc.VoyNo,
bc.MBLNo,
bc.CntrTotal,
bc.FactoryAddr
}).ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize);
return TRUCK_DISPATCH.Adapt>();
case "CUT_MODIFY":
var CUT_MODIFY = await _taskBaseInfoRepository.AsQueryable().LeftJoin((t, bc) => t.PK_ID==bc.TASK_ID)
.Where((t, bc) => userlist.Contains(t.CreatedUserId) || (t.RealUserId != null && userlist.Contains(t.RealUserId.Value)) || t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.MBlNo), (t, bc) => mblList.Contains(t.MBL_NO))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskRecvName), (t, bc) => t.CreatedUserName.Contains(QuerySearch.TaskRecvName.Trim()))
.WhereIF(etdBegin != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value >= etdBegin)
.WhereIF(etdEnd != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value < etdEnd)
.WhereIF(taskDateBegin != DateTime.MinValue, (t, bc) => t.CreatedTime >= taskDateBegin)
.WhereIF(taskDateEnd != DateTime.MinValue, (t, bc) => t.CreatedTime < taskDateEnd)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskType), (t, bc) => t.TASK_TYPE.Equals(QuerySearch.TaskType))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskSource), (t, bc) => t.TASK_SOURCE.Equals(QuerySearch.TaskSource))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.EXCPTION.ToString(), (t, bc) => t.IS_EXCEPT == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PUBLIC.ToString(), (t, bc) => t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PERSON.ToString(), (t, bc) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.Status), (t, bc) => t.STATUS.Equals(QuerySearch.Status))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.PKId), (t, bc) => t.PK_ID.Equals(QuerySearch.PKId))
.WhereIF(userIds.Count>0, (t, bc) => userIds.Contains(t.DJYUserId))
.OrderBy(entityOrderCol + (QuerySearch.descSort ? " desc " : " asc "))
.Select((t, bc) => new
{
PK_ID = t.PK_ID.SelectAll(),
bc.TASK_ID,
bc.CARRIER,
bc.VESSEL,
bc.VOYNO,
bc.NOTICE_DATE
}).ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize);
return CUT_MODIFY.Adapt>();
case "ROLLING_NOMINATION":
case "TRANSFER_NOMINATION":
var ysh = await _taskBaseInfoRepository.AsQueryable().LeftJoin((t, bc) => t.PK_ID==bc.TASK_ID)
.Where((t, bc) => userlist.Contains(t.CreatedUserId) || (t.RealUserId != null && userlist.Contains(t.RealUserId.Value)) || t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.MBlNo), (t, bc) => mblList.Contains(t.MBL_NO))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskRecvName), (t, bc) => t.CreatedUserName.Contains(QuerySearch.TaskRecvName.Trim()))
.WhereIF(etdBegin != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value >= etdBegin)
.WhereIF(etdEnd != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value < etdEnd)
.WhereIF(taskDateBegin != DateTime.MinValue, (t, bc) => t.CreatedTime >= taskDateBegin)
.WhereIF(taskDateEnd != DateTime.MinValue, (t, bc) => t.CreatedTime < taskDateEnd)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskType), (t, bc) => t.TASK_TYPE.Equals(QuerySearch.TaskType))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskSource), (t, bc) => t.TASK_SOURCE.Equals(QuerySearch.TaskSource))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.EXCPTION.ToString(), (t, bc) => t.IS_EXCEPT == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PUBLIC.ToString(), (t, bc) => t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PERSON.ToString(), (t, bc) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.Status), (t, bc) => t.STATUS.Equals(QuerySearch.Status))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.PKId), (t, bc) => t.PK_ID.Equals(QuerySearch.PKId))
.WhereIF(userIds.Count>0, (t, bc) => userIds.Contains(t.DJYUserId))
.OrderBy(entityOrderCol + (QuerySearch.descSort ? " desc " : " asc "))
.Select((t, bc) => new
{
PK_ID = t.PK_ID.SelectAll(),
bc.TASK_ID,
bc.PLAN_TYPE,
bc.BATCH_NO,
bc.CARRIERID,
bc.CARRIER,
bc.CONFIRM_DEAD_LINE,
bc.READ_CREATE_TIME,
bc.ROLL_DOUBLE_REMARK,
bc.PLAN_TXT,
//bc.REMARK,
bc.TASK_BATCH_TOTAL,
bc.TASK_BATCH_PER_TOTAL
}).ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize);
return ysh.Adapt>();
case "DRAFT":
var DRAFT = await _taskBaseInfoRepository.AsQueryable().LeftJoin((t, bc) => t.PK_ID==bc.TASK_ID)
.Where((t, bc) => userlist.Contains(t.CreatedUserId) || (t.RealUserId != null && userlist.Contains(t.RealUserId.Value)) || t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.MBlNo), (t, bc) => mblList.Contains(t.MBL_NO))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskRecvName), (t, bc) => t.CreatedUserName.Contains(QuerySearch.TaskRecvName.Trim()))
.WhereIF(etdBegin != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value >= etdBegin)
.WhereIF(etdEnd != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value < etdEnd)
.WhereIF(taskDateBegin != DateTime.MinValue, (t, bc) => t.CreatedTime >= taskDateBegin)
.WhereIF(taskDateEnd != DateTime.MinValue, (t, bc) => t.CreatedTime < taskDateEnd)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskType), (t, bc) => t.TASK_TYPE.Equals(QuerySearch.TaskType))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskSource), (t, bc) => t.TASK_SOURCE.Equals(QuerySearch.TaskSource))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.EXCPTION.ToString(), (t, bc) => t.IS_EXCEPT == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PUBLIC.ToString(), (t, bc) => t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PERSON.ToString(), (t, bc) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.Status), (t, bc) => t.STATUS.Equals(QuerySearch.Status))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.PKId), (t, bc) => t.PK_ID.Equals(QuerySearch.PKId))
.WhereIF(userIds.Count>0, (t, bc) => userIds.Contains(t.DJYUserId))
.OrderBy(entityOrderCol + (QuerySearch.descSort ? " desc " : " asc "))
.Select((t, bc) => new
{
PK_ID = t.PK_ID.SelectAll(),
bc.TASK_ID,
bc.CARRIER,
//bc.MBL_NO,
bc.BOOKING_ID,
bc.IS_CHANGE,
bc.IS_EMAIL_SEND,
bc.SEND_EMAIL_DATE,
bc.NOTICE_DATE,
}).ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize);
return DRAFT.Adapt>();
case "POD_DISCHARGE_FULL":
case "POD_GATEOUT_FULL":
var POD = await _taskBaseInfoRepository.AsQueryable().LeftJoin((t, bc) => t.PK_ID==bc.TASK_ID)
.Where((t, bc) => userlist.Contains(t.CreatedUserId) || (t.RealUserId != null && userlist.Contains(t.RealUserId.Value)) || t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.MBlNo), (t, bc) => mblList.Contains(t.MBL_NO))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskRecvName), (t, bc) => t.CreatedUserName.Contains(QuerySearch.TaskRecvName.Trim()))
.WhereIF(etdBegin != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value >= etdBegin)
.WhereIF(etdEnd != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value < etdEnd)
.WhereIF(taskDateBegin != DateTime.MinValue, (t, bc) => t.CreatedTime >= taskDateBegin)
.WhereIF(taskDateEnd != DateTime.MinValue, (t, bc) => t.CreatedTime < taskDateEnd)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskType), (t, bc) => t.TASK_TYPE.Equals(QuerySearch.TaskType))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskSource), (t, bc) => t.TASK_SOURCE.Equals(QuerySearch.TaskSource))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.EXCPTION.ToString(), (t, bc) => t.IS_EXCEPT == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PUBLIC.ToString(), (t, bc) => t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PERSON.ToString(), (t, bc) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.Status), (t, bc) => t.STATUS.Equals(QuerySearch.Status))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.PKId), (t, bc) => t.PK_ID.Equals(QuerySearch.PKId))
.WhereIF(userIds.Count>0, (t, bc) => userIds.Contains(t.DJYUserId))
.OrderBy(entityOrderCol + (QuerySearch.descSort ? " desc " : " asc "))
.Select((t, bc) => new
{
PK_ID = t.PK_ID.SelectAll(),
bc.TASK_ID,
bc.CARRIER,
bc.NOTICE_TYPE,
bc.NOTICE_TYPE_NAME,
//bc.MBL_NO,
bc.NOTICE_DATE
}).ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize);
return POD.Adapt>();
case "CAUTION_NOTICE":
var CAUTION_NOTICE = await _taskBaseInfoRepository.AsQueryable().LeftJoin((t, bc) => t.PK_ID==bc.TASK_ID)
.Where((t, bc) => userlist.Contains(t.CreatedUserId) || (t.RealUserId != null && userlist.Contains(t.RealUserId.Value)) || t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.MBlNo), (t, bc) => mblList.Contains(t.MBL_NO))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskRecvName), (t, bc) => t.CreatedUserName.Contains(QuerySearch.TaskRecvName.Trim()))
.WhereIF(etdBegin != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value >= etdBegin)
.WhereIF(etdEnd != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value < etdEnd)
.WhereIF(taskDateBegin != DateTime.MinValue, (t, bc) => t.CreatedTime >= taskDateBegin)
.WhereIF(taskDateEnd != DateTime.MinValue, (t, bc) => t.CreatedTime < taskDateEnd)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskType), (t, bc) => t.TASK_TYPE.Equals(QuerySearch.TaskType))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskSource), (t, bc) => t.TASK_SOURCE.Equals(QuerySearch.TaskSource))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.EXCPTION.ToString(), (t, bc) => t.IS_EXCEPT == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PUBLIC.ToString(), (t, bc) => t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PERSON.ToString(), (t, bc) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.Status), (t, bc) => t.STATUS.Equals(QuerySearch.Status))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.PKId), (t, bc) => t.PK_ID.Equals(QuerySearch.PKId))
.WhereIF(userIds.Count>0, (t, bc) => userIds.Contains(t.DJYUserId))
.OrderBy(entityOrderCol + (QuerySearch.descSort ? " desc " : " asc "))
.Select((t, bc) => new
{
PK_ID = t.PK_ID.SelectAll(),
bc.TASK_ID,
bc.SOURCE_SYSTEM,
bc.SOURCE_BUSI_TYPE,
bc.SOURCE_BUSI_TYPENAME,
bc.NOTIFY_CONTENT,
//bc.MBL_NO,
bc.CARRIER,
bc.CAUTION_NOTICE_TYPE,
bc.IS_WEEK_DIFF,
bc.IS_PRICE_DATE_DIFF,
bc.IS_TRANSFER,
bc.IS_VESSEL_CHANGE,
bc.IS_CUT_DATE_ADVANCED,
bc.BOOKING_ID,
bc.BOOKING_SLOT_ID,
bc.SOURCE_TASK_ID,
bc.OLD_VAL,
bc.NEW_VAL,
}).ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize);
return CAUTION_NOTICE.Adapt>();
case "ROUTE_CUT_CHANGE":
var ROUTE_CUT_CHANGE = await _taskBaseInfoRepository.AsQueryable().LeftJoin((t, bc) => t.PK_ID==bc.TASK_ID)
.Where((t, bc) => userlist.Contains(t.CreatedUserId) || (t.RealUserId != null && userlist.Contains(t.RealUserId.Value)) || t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.MBlNo), (t, bc) => mblList.Contains(t.MBL_NO))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskRecvName), (t, bc) => t.CreatedUserName.Contains(QuerySearch.TaskRecvName.Trim()))
.WhereIF(etdBegin != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value >= etdBegin)
.WhereIF(etdEnd != DateTime.MinValue, (t, bc) => t.ETD.HasValue && t.ETD.Value < etdEnd)
.WhereIF(taskDateBegin != DateTime.MinValue, (t, bc) => t.CreatedTime >= taskDateBegin)
.WhereIF(taskDateEnd != DateTime.MinValue, (t, bc) => t.CreatedTime < taskDateEnd)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskType), (t, bc) => t.TASK_TYPE.Equals(QuerySearch.TaskType))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskSource), (t, bc) => t.TASK_SOURCE.Equals(QuerySearch.TaskSource))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.EXCPTION.ToString(), (t, bc) => t.IS_EXCEPT == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PUBLIC.ToString(), (t, bc) => t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PERSON.ToString(), (t, bc) => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.Status), (t, bc) => t.STATUS.Equals(QuerySearch.Status))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.PKId), (t, bc) => t.PK_ID.Equals(QuerySearch.PKId))
.WhereIF(userIds.Count>0, (t, bc) => userIds.Contains(t.DJYUserId))
.OrderBy(entityOrderCol + (QuerySearch.descSort ? " desc " : " asc "))
.Select((t, bc) => new
{
PK_ID = t.PK_ID.SelectAll(),
bc.TASK_ID,
bc.VESSEL,
bc.VOYNO,
bc.CARRIER,
bc.READ_PORTLOAD,
bc.ORIG_ETD,
bc.MDGF_CUT_DATE,
bc.ETA,
//bc.ETD,
bc.SI_CUT_DATE,
bc.TM_SHIFT_CUT_DATE,
bc.VGM_CUTOFF_TIME,
bc.CY_CUT_DATE,
bc.ROUTE_CODE,
bc.EMAIL_SUBJECT,
bc.WEEK,
bc.PORTLOADID,
bc.PORTLOAD
}).ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize);
return ROUTE_CUT_CHANGE.Adapt>();
default:
var entities = await _taskBaseInfoRepository.AsQueryable()
.Where(t => userlist.Contains(t.CreatedUserId) || (t.RealUserId != null && userlist.Contains(t.RealUserId.Value)) || t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.MBlNo), t => mblList.Contains(t.MBL_NO))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskRecvName), t => t.CreatedUserName.Contains(QuerySearch.TaskRecvName.Trim()))
.WhereIF(etdBegin != DateTime.MinValue, t => t.ETD.HasValue && t.ETD.Value >= etdBegin)
.WhereIF(etdEnd != DateTime.MinValue, t => t.ETD.HasValue && t.ETD.Value < etdEnd)
.WhereIF(taskDateBegin != DateTime.MinValue, t => t.CreatedTime >= taskDateBegin)
.WhereIF(taskDateEnd != DateTime.MinValue, t => t.CreatedTime < taskDateEnd)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskType), t => t.TASK_TYPE.Equals(QuerySearch.TaskType))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskSource), t => t.TASK_SOURCE.Equals(QuerySearch.TaskSource))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.EXCPTION.ToString(), t => t.IS_EXCEPT == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PUBLIC.ToString(), t => t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskCategory) && QuerySearch.TaskCategory == TaskStatLevelEnum.PERSON.ToString(), t => t.IS_PUBLIC == 0 && t.IS_EXCEPT == 0)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.Status), t => t.STATUS.Equals(QuerySearch.Status))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.PKId), t => t.PK_ID.Equals(QuerySearch.PKId))
.WhereIF(userIds.Count>0, t => userIds.Contains(t.DJYUserId))
.OrderBy(entityOrderCol + (QuerySearch.descSort ? " desc " : " asc "))
.Select(t => new
{
PK_ID = t.PK_ID.SelectAll()
})
.ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize);
return entities.Adapt>();
break;
}
}
#endregion
#region 下载正本提单(可批量)
///
/// 下载正本提单(可批量)
///
/// 任务主键数组
/// 返回结果
[HttpPost("/TaskManage/DownloadOriginalTask")]
public async Task DownloadOriginalTask(string[] PKIds)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
_logger.LogInformation("批次={no} ids={ids} 下载正本提单开始", batchNo, string.Join(",", PKIds));
try
{
var taskList = _taskBaseInfoRepository.AsQueryable().Where(t => PKIds.Contains(t.PK_ID)).ToList();
_logger.LogInformation("批次={no} 获取任务完成,Num={Num}", batchNo, taskList.Count);
//获取个人对应的账户,这里GetAccountConfig逻辑优先取个人,个人没有配置取公司对应配置
var userWebAccountConfig = _webAccountConfig.GetAccountConfig(CONST_WEB_ACCOUNT_TYPE, UserManager.UserId).GetAwaiter().GetResult();
_logger.LogInformation("批次={no} 获取获取网站的账户完成,result={Num}", batchNo, JSON.Serialize(userWebAccountConfig));
if (userWebAccountConfig == null)
throw Oops.Bah($"个人/公司网站【{CONST_WEB_ACCOUNT_TYPE}】获取失败,请维护个人/公司网站账户信息");
taskList.ForEach(async tsk =>
{
await InnerDownloadOriginalTask(batchNo, tsk, userWebAccountConfig);
});
}
catch (Exception ex)
{
throw Oops.Bah("下载正本提单异常,{0}", ex.Message);
}
return result;
}
#endregion
#region 单票正本下载
///
/// 单票正本下载
///
/// 批次号
/// 任务详情
/// 网站账户配置
/// 返回回执
private async Task InnerDownloadOriginalTask(string batchNo, TaskBaseInfo taskBaseInfo,
DjyWebsiteAccountConfig webAccountConfig)
{
var result = new TaskManageOrderResultDto();
/*
1、TaskOriginalDownloadHisInfo表中处理任务是succ/temp不允许重复下载。failure/timeout的记录可以再次发起下载。
2、从任务表提取RESULT_NOTE回执信息,里面包含了JSON数据 {"pageUrl":"http://www.cnc-ebusiness.com/ebusiness/bl/detail/AASM104300"}
3、异步请求正本下载的链接,有超时时间。
4、下载完成后写入记录
*/
//正本下载URL
string originalUrl = string.Empty;
try
{
var hisList = _taskOriginalDownloadHisInfoRepository
.Where(t => t.TASK_ID == taskBaseInfo.PK_ID).ToList();
if (hisList.Any(t => new string[] { "succ", "temp" }.Contains(t.STATUS)))
throw Oops.Bah("下载URL不存在,请用最新任务数据");
if (string.IsNullOrWhiteSpace(taskBaseInfo.RESULT_NOTE))
throw Oops.Bah("下载URL不存在,请用最新任务数据");
var resultObj = JSON.Deserialize(taskBaseInfo.RESULT_NOTE);
originalUrl = resultObj.pageUrl.ToString();
if (string.IsNullOrWhiteSpace(originalUrl))
throw Oops.Bah("解析下载URL不存在,请用最新任务数据");
DateTime startDate = DateTime.Now;
var downloadUrl = _cache.GetAllDictData().GetAwaiter().GetResult()
.First(t => t.Code.Equals(CONST_BOOK_ORIGINAL_DOWN_URL_CODE, StringComparison.OrdinalIgnoreCase))?.Value;
if (string.IsNullOrWhiteSpace(downloadUrl))
throw Oops.Bah($"正本下载URL不存在,请确认字典是否配置 code={CONST_BOOK_ORIGINAL_DOWN_URL_CODE}");
TaskOriginalDownloadHisInfo taskOriginalDownloadHisInfo = new TaskOriginalDownloadHisInfo
{
PK_ID = IDGen.NextID().ToString(),
TASK_ID = taskBaseInfo.PK_ID,
REQUEST_URL = originalUrl,
CreatedUserId = UserManager.UserId,
CreatedUserName = UserManager.Name,
STATUS = "temp",
IS_TIMEOUT = 0,
START_DATE = startDate,
TenantId = UserManager.TENANT_ID,
TenantName = UserManager.TENANT_NAME
};
//写入记录
_taskOriginalDownloadHisInfoRepository.Insert(taskOriginalDownloadHisInfo);
//请求远程链接
Dictionary formDict = new Dictionary {
{"bno", taskBaseInfo.MBL_NO },
{"page_url", downloadUrl },
{"web_user", webAccountConfig.Account },
{"web_pwd", webAccountConfig.Password },
{"web_pwd", "myshipping_task" },
{"web_pwd", "" }
};
//请求下载正本
var postResult = await InnerRemoteDownOriginal(batchNo, downloadUrl, formDict);
//重新获取下载历史
var downloadHisInfo = _taskOriginalDownloadHisInfoRepository.AsQueryable()
.First(t => t.PK_ID == taskOriginalDownloadHisInfo.PK_ID);
//更新任务状态
var taskModel = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == taskBaseInfo.PK_ID);
downloadHisInfo.END_DATE = (DateTime)postResult.ext;
downloadHisInfo.RESULT_NOTE = postResult.msg;
bool isDownSucc = false;
//下载返回成功后,更新记录并生成扣费记录
if (postResult.succ)
{
downloadHisInfo.STATUS = "succ";
downloadHisInfo.RESULT_URL = postResult.msg;
taskModel.COMPLETE_DEAL = TaskCompleteDealEnum.MANUAL.ToString();
taskModel.COMPLETE_DEAL_NAME = TaskCompleteDealEnum.MANUAL.GetDescription();
taskModel.COMPLETE_DATE = DateTime.Now;
taskModel.STATUS = TaskStatusEnum.Complete.ToString();
taskModel.IS_COMPLETE = 1;
isDownSucc = true;
}
else
{
if (postResult.isTimeout)
{
downloadHisInfo.STATUS = "timeout";
}
else
{
downloadHisInfo.STATUS = "failure";
}
}
//更新下载历史
await _taskOriginalDownloadHisInfoRepository.AsUpdateable(downloadHisInfo).IgnoreColumns(it => new
{
it.TenantId,
it.CreatedUserId,
it.CreatedUserName
}).ExecuteCommandAsync();
//异步扣费,这里不管是否失败都生成扣费记录,只在状态上做标识。
var chargeResult = await InnerChargeFee(taskBaseInfo, isDownSucc);
_taskBaseInfoRepository.AsUpdateable(taskModel).UpdateColumns(it => new
{
it.COMPLETE_DATE,
it.COMPLETE_DEAL,
it.COMPLETE_DEAL_NAME
}).ExecuteCommand();
}
catch (Exception ex)
{
result.succ = false;
result.msg = ex.Message;
}
return result;
}
#endregion
#region 远程请求正本下载
///
/// 远程请求正本下载
///
/// 批次号
/// 请求URL
/// 请求参数
///
private async Task InnerRemoteDownOriginal(string batchNo, string url, Dictionary dic)
{
var result = new TaskManageOrderResultDto();
DateTime bDate = DateTime.Now;
try
{
_logger.LogInformation("批次={no} 请求报文开始", batchNo);
var res = await url.SetHttpMethod(HttpMethod.Post)
.SetBody(dic, "application/x-www-form-urlencoded")
.SetContentEncoding(Encoding.UTF8)
.PostAsync();
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation("批次={no} 请求完成,耗时:{timeDiff}ms. 结果{msg}", batchNo, timeDiff, JSON.Serialize(res));
if (res.StatusCode == System.Net.HttpStatusCode.OK)
{
var userResult = await res.Content.ReadAsStringAsync();
var downResult = JSON.Deserialize(userResult);
//返回详情
result.msg = downResult.message.ToString();
//返回代码
if (downResult.status.ToString() == "1")
{
result.succ = true;
}
else
{
result.succ = false;
}
}
result.ext = eDate;
}
catch (Exception ex)
{
//如果有异常直接抛出错误
throw Oops.Bah(ex.Message);
}
return result;
}
#endregion
#region 扣费
///
/// 扣费
///
/// 任务信息
/// 是否执行扣费 true-执行扣费 false-不执行扣费(主要是符合扣费条件但是由于超时没有得到准确回执)
/// 返回回执
private async Task InnerChargeFee(TaskBaseInfo taskBaseInfo, bool isCharge = true)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto { succ = false };
try
{
decimal balance = 0;
decimal price = 0;
decimal total = 0;
TaskChargesHisInfo model = new TaskChargesHisInfo
{
PK_ID = IDGen.NextID().ToString(),
TASK_ID = taskBaseInfo.PK_ID,
BEFORE_BALANCE = balance,
PRICE = price,
BUSI_TYPE = "21",
BUSI_TYPE_NAME = String.Empty,
SEND_TYPE = "1001",
SEND_TYPE_NAME = String.Empty,
REMARK = "正本下载",
QTY = 1,
TOTAL_AMOUNT = total,
};
if (!isCharge)
{
model.STATUS = TaskChargeStatusEnum.UNKNOW_RESULT.ToString();
model.STATUS_NAME = TaskChargeStatusEnum.UNKNOW_RESULT.GetDescription();
}
//写入记录
await _taskChargesHisInfoRepository.InsertAsync(model);
result.succ = false;
result.msg = "扣费失败";
}
catch (Exception ex)
{
result.succ = false;
result.msg = ex.Message;
}
return result;
}
#endregion
#region 完成任务(可批量)
///
/// 完成任务(可批量)
///
/// 任务主键数组
/// 返回结果
[HttpPost("/TaskManage/CompleteTask")]
public async Task CompleteTask([FromBody] string[] PKIds)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
List taskRunList = new List();
string batchNo = IDGen.NextID().ToString();
_logger.LogInformation("批次={no} ids={ids} 完成任务开始", batchNo, string.Join(",", PKIds));
try
{
var taskList = _taskBaseInfoRepository.AsQueryable().Where(t => PKIds.Contains(t.PK_ID)).ToList();
_logger.LogInformation("批次={no} 获取任务完成,Num={Num}", batchNo, taskList.Count);
var noList = PKIds.Select((a, idx) => new { no = idx + 1, id = a }).ToList();
foreach (var bk in taskList)
{
var sortNo = noList.FirstOrDefault(a => a.id == bk.PK_ID).no;
taskRunList.Add(InnerManualTask(batchNo,bk, TaskOperTypeEnum.COMPLETE_TASK, sortNo).GetAwaiter().GetResult());
}
//Task.WaitAll(taskRunList.ToArray());
result.succ = true;
result.msg = "执行成功";
var downResultList = taskRunList.Select(x => x).ToList();
if (downResultList.Any(x => !x.succ))
{
result.succ = false;
result.msg = "执行失败";
}
else
{
result.succ = true;
result.msg = downResultList.FirstOrDefault().msg;
}
result.ext = downResultList;
var succ = downResultList.Count(x => x.succ);
var fail = downResultList.Count(x => !x.succ);
if (succ > 0)
{
result.batchTotal = succ.ToString();
}
else
{
result.batchTotal = "- ";
}
if (fail > 0)
{
result.batchTotal += "/" + fail.ToString();
}
else
{
result.batchTotal += " -";
}
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"执行异常,原因:{ex.Message}";
}
return result;
}
#endregion
#region 单票执行任务
///
/// 单票执行任务
///
/// 批次号
/// 任务详情
/// 操作类型
/// 顺序号
/// 返回回执
private async Task InnerManualTask(string batchNo, TaskBaseInfo model,
TaskOperTypeEnum taskOperTypeEnum, int sortNo)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
result.bno = model.TASK_NO;
try
{
//var model = _taskBaseInfoRepository.Context.CopyNew().Queryable().First(t => t.PK_ID == taskBaseInfo.PK_ID);
if (taskOperTypeEnum == TaskOperTypeEnum.COMPLETE_TASK)
{
if(model.TASK_TYPE == TaskBusiTypeEnum.TRUCK_DISPATCH.ToString())
{
if(model.STATUS == TaskStatusEnum.Cancel.ToString())
{
throw Oops.Bah($"当前状态是{TaskStatusEnum.Cancel.GetDescription()} 不能执行完成");
}
}
if (model.TASK_TYPE == TaskBusiTypeEnum.CANCELLATION.ToString())
{
//收到订舱已被取消邮件后生成的任务,如果点击完成,(订舱状态变为【退舱】,注意这里还需要确认)
}
model.COMPLETE_DATE = DateTime.Now;
model.COMPLETE_DEAL = TaskCompleteDealEnum.MANUAL.ToString();
model.COMPLETE_DEAL = TaskCompleteDealEnum.MANUAL.GetDescription();
model.IS_COMPLETE = 1;
model.STATUS = TaskStatusEnum.Complete.ToString();
model.STATUS_NAME = TaskStatusEnum.Complete.GetDescription();
await _taskBaseInfoRepository.AsUpdateable(model).UpdateColumns(it => new
{
it.COMPLETE_DATE,
it.COMPLETE_DEAL,
it.COMPLETE_DEAL_NAME,
it.IS_COMPLETE,
it.STATUS,
it.STATUS_NAME
}).ExecuteCommandAsync();
}
else if (taskOperTypeEnum == TaskOperTypeEnum.CANCEL_TASK)
{
if (model.TASK_TYPE == TaskBusiTypeEnum.CHANGE_SHIP.ToString())
{
model.STATUS = TaskStatusEnum.Cancel.ToString();
model.STATUS_NAME = TaskStatusEnum.Cancel.GetDescription();
await _taskBaseInfoRepository.AsUpdateable(model).UpdateColumns(it => new
{
it.COMPLETE_DATE,
it.COMPLETE_DEAL,
it.COMPLETE_DEAL_NAME,
it.IS_COMPLETE,
it.STATUS,
it.STATUS_NAME
}).ExecuteCommandAsync();
}
else if (model.TASK_TYPE == TaskBusiTypeEnum.ABORT_CHANGE_SHIP.ToString())
{
/*
1.如果原换船通知已经接受,需要把原船名航次恢复并通知客户取消换船。
2.如果原换船通知未作处理,点击接受或者结束任务时提示:本票货存在未处理换船通知,请先结束原换船任务然后结束本任务。
3.如果原换船任务为结束任务,在取消换船任务点接受时,提示未做换船,请点击结束任务。
*/
//查询同票主单的是否有未处理的换船通知
//_taskBaseInfoRepository.AsQueryable().Where(t=>t.MBL_NO.Equals(taskBaseInfo.MBL_NO) && )
}
else
{
model.STATUS = TaskStatusEnum.Cancel.ToString();
model.STATUS_NAME = TaskStatusEnum.Cancel.GetDescription();
model.UpdatedTime = DateTime.Now;
model.UpdatedUserId = UserManager.UserId;
model.UpdatedUserName = UserManager.Name;
await _taskBaseInfoRepository.AsUpdateable(model).UpdateColumns(it => new
{
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName,
it.STATUS,
it.STATUS_NAME
}).ExecuteCommandAsync();
}
}
result.succ = true;
result.msg = "执行成功";
}
catch (Exception ex)
{
result.succ = false;
result.msg = ex.Message;
}
return result;
}
#endregion
#region 取消任务(可批量)
///
/// 取消任务(可批量)
///
/// 任务主键数组
/// 返回结果
[HttpPost("/TaskManage/CancelTask")]
public async Task CancelTask([FromBody] string[] PKIds)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
List taskRunList = new List();
_logger.LogInformation("批次={no} ids={ids} 取消任务开始", batchNo, string.Join(",", PKIds));
try
{
var taskList = _taskBaseInfoRepository.AsQueryable().Where(t => PKIds.Contains(t.PK_ID)).ToList();
_logger.LogInformation("批次={no} 获取任务完成,Num={Num}", batchNo, taskList.Count);
var noList = PKIds.Select((a, idx) => new { no = idx + 1, id = a }).ToList();
foreach (var bk in taskList)
{
var sortNo = noList.FirstOrDefault(a => a.id == bk.PK_ID).no;
taskRunList.Add(InnerManualTask(batchNo, bk, TaskOperTypeEnum.CANCEL_TASK, sortNo).GetAwaiter().GetResult());
}
//Task.WaitAll(taskRunList.ToArray());
result.succ = true;
result.msg = "执行成功";
var downResultList = taskRunList.Select(x => x).ToList();
if (downResultList.Any(x => !x.succ))
{
result.succ = false;
result.msg = "执行失败";
}
else
{
result.succ = true;
result.msg = downResultList.FirstOrDefault().msg;
}
result.ext = downResultList;
var succ = downResultList.Count(x => x.succ);
var fail = downResultList.Count(x => !x.succ);
if (succ > 0)
{
result.batchTotal = succ.ToString();
}
else
{
result.batchTotal = "- ";
}
if (fail > 0)
{
result.batchTotal += "/" + fail.ToString();
}
else
{
result.batchTotal += " -";
}
}
catch (Exception ex)
{
throw Oops.Bah("执行异常,{0}", ex.Message);
}
return result;
}
#endregion
#region 挂起任务(可批量)
///
/// 挂起任务(可批量)
///
/// 任务主键数组
/// 返回结果
[HttpPost("/TaskManage/PendingTask")]
public async Task PendingTask(string[] PKIds)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
_logger.LogInformation("批次={no} ids={ids} 挂起任务开始", batchNo, string.Join(",", PKIds));
List taskRunList = new List();
try
{
var taskList = _taskBaseInfoRepository.AsQueryable().Where(t => PKIds.Contains(t.PK_ID)).ToList();
_logger.LogInformation("批次={no} 获取任务完成,Num={Num}", batchNo, taskList.Count);
var noList = PKIds.Select((a, idx) => new { no = idx + 1, id = a }).ToList();
foreach (var bk in taskList)
{
var sortNo = noList.FirstOrDefault(a => a.id == bk.PK_ID).no;
taskRunList.Add(InnerManualTask(batchNo, bk, TaskOperTypeEnum.PENDING_TASK, sortNo).GetAwaiter().GetResult());
}
//Task.WaitAll(taskRunList.ToArray());
result.succ = true;
result.msg = "执行成功";
var downResultList = taskRunList.Select(x => x).ToList();
if (downResultList.Any(x => !x.succ))
{
result.succ = false;
result.msg = "执行失败";
}
else
{
result.succ = true;
result.msg = downResultList.FirstOrDefault().msg;
}
result.ext = downResultList;
var succ = downResultList.Count(x => x.succ);
var fail = downResultList.Count(x => !x.succ);
if (succ > 0)
{
result.batchTotal = succ.ToString();
}
else
{
result.batchTotal = "- ";
}
if (fail > 0)
{
result.batchTotal += "/" + fail.ToString();
}
else
{
result.batchTotal += " -";
}
}
catch (Exception ex)
{
throw Oops.Bah("完成任务异常,{0}", ex.Message);
}
return result;
}
#endregion
#region 提单纸页数计算
///
/// 提单纸页数计算
///
/// 任务主键数组
/// 返回结果
[HttpPost("/TaskManage/LaraPaperCalc")]
public async Task> LaraPaperCalc(string[] PKIds)
{
List list = new List();
string batchNo = IDGen.NextID().ToString();
_logger.LogInformation("批次={no} ids={ids} 提单纸页数计算开始", batchNo, string.Join(",", PKIds));
try
{
//根据任务主键获取所有主单号列表
var mblnoList = _taskBaseInfoRepository.AsQueryable().Where(t => PKIds.Contains(t.PK_ID) && !string.IsNullOrWhiteSpace(t.MBL_NO))
.Select(t => t.MBL_NO).Distinct().ToList();
if (mblnoList.Count > 0)
{
//根据主单号获取任务类型是DRAFT的任务,取时间最新的
var fileList = _taskBaseInfoRepository.EntityContext.Queryable()
.InnerJoin((tsk, file) => tsk.PK_ID == file.TASK_PKID)
.Where((tsk, file) =>
tsk.TASK_TYPE == TaskBusiTypeEnum.DRAFT.ToString() && mblnoList.Contains(tsk.MBL_NO))
.Select((tsk, file) => new { tsk = tsk, file = file }).ToList();
var calcList = fileList.GroupBy(t => t.tsk.PK_ID)
.Select(a =>
{
var currList = a.ToList();
return new
{
tsk = currList.FirstOrDefault().tsk,
clist = a.Select(x => x.file).ToList()
};
}).OrderByDescending(t => t.tsk.CreatedTime).ToList();
list = mblnoList.Select((mbl, idx) =>
{
var calcInfo = new LaraPaperCalcInfo();
calcInfo.MBLNo = mbl;
calcInfo.Indx = idx + 1;
var files = calcList.FirstOrDefault(t => t.tsk.MBL_NO.Equals(mbl, StringComparison.OrdinalIgnoreCase));
if (files != null)
{
calcInfo.DraftNum = files.clist.Select(t => t.FILE_NAME.GetPageNum()).Sum();
}
calcInfo.PaperNum = calcInfo.DraftNum * 3;
return calcInfo;
}).ToList();
}
}
catch (Exception ex)
{
throw Oops.Bah("提单纸页数计算异常,{0}", ex.Message);
}
return list;
}
#endregion
#region 请求提单纸登记
///
/// 请求提单纸登记
///
/// 提单纸登记请求参数列表
/// 返回结果
[HttpPost("/TaskManage/LaraPaperRegistPost")]
public async Task LaraPaperRegistPost(List laraPaperList)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
_logger.LogInformation("批次={no} num={num} LARA提单纸登记开始", batchNo, laraPaperList.Count);
/*
1、读取LARA网站的配置账户。
2、读取字典的URL。
3、组织请求参数。
4、写入TASK_LARA_PAPER。
5、远程请求。
6、更新状态
*/
try
{
var taskArg = laraPaperList.Select(t => t.TaskId).Distinct().ToArray();
var taskList = _taskBaseInfoRepository.AsQueryable().Where(t => taskArg.Contains(t.PK_ID)).ToList();
_logger.LogInformation("批次={no} 获取任务完成", batchNo);
//获取个人对应的账户,这里GetAccountConfig逻辑优先取个人,个人没有配置取公司对应配置
var userWebAccountConfig = _webAccountConfig.GetAccountConfig(CONST_WEB_LARA_ACCOUNT_TYPE, UserManager.UserId).GetAwaiter().GetResult();
_logger.LogInformation("批次={no} 获取获取网站的账户完成,result={Num}", batchNo, JSON.Serialize(userWebAccountConfig));
if (userWebAccountConfig == null)
throw Oops.Bah($"个人/公司网站【{CONST_WEB_LARA_ACCOUNT_TYPE}】获取失败,请维护个人/公司网站账户信息");
var downloadUrl = _cache.GetAllDictData().GetAwaiter().GetResult()
.First(t => t.Code.Equals(CONST_LARA_DOWN_URL_CODE, StringComparison.OrdinalIgnoreCase))?.Value;
if (string.IsNullOrWhiteSpace(downloadUrl))
throw Oops.Bah($"LARA纸下载URL不存在,请确认字典是否配置 code={CONST_LARA_DOWN_URL_CODE}");
JObject jobjPost = new JObject();
jobjPost.Add("customer_user", "myshipping");
jobjPost.Add("customer_pwd", "");
JArray jarr = new JArray();
jobjPost.Add("lara_list", jarr);
laraPaperList.ForEach(async lara =>
{
TaskLARAPaperInfo taskLARAPaperInfo = new TaskLARAPaperInfo
{
PK_ID = IDGen.NextID().ToString(),
TASK_ID = lara.TaskId,
BOOKING_ORDER_NO = "",
CreatedUserId = UserManager.UserId,
CreatedUserName = UserManager.Name,
STATUS = "temp",
IS_TIMEOUT = 0,
START_DATE = DateTime.Now,
TenantId = UserManager.TENANT_ID,
TenantName = UserManager.TENANT_NAME,
PAGE_NUMBERS = lara.PageNumbers,
PAGE_SUM = lara.PageSum,
ISSUE_TYPE = lara.ISSUETYPE,
MBL_NO = lara.MBLNO,
NUMBER_FROM = lara.NumberFrom,
NUMBER_TO = lara.NumberTo,
DRAFT_NUM = lara.DraftNum,
};
//写入记录
await _taskLARAPaperInfoRepository.InsertAsync(taskLARAPaperInfo);
JObject jobjItem = new JObject();
jobjItem.Add("customer_user", "myshipping");
jobjItem.Add("customer_pwd", "");
jobjItem.Add("web_user", userWebAccountConfig.Account);
jobjItem.Add("web_pwd", userWebAccountConfig.Password);
jobjItem.Add("bno", lara.MBLNO);
jobjItem.Add("num_from", lara.NumberFrom);
jobjItem.Add("num_to", lara.NumberTo);
jobjItem.Add("numbers", lara.PageNumbers);
jobjItem.Add("vessel_code", "");
jobjItem.Add("voyage_code", "");
jobjItem.Add("bl_status", "All");
jobjItem.Add("bl_type", "Original Bill");
jobjItem.Add("issue_code", "ALL");
jarr.Add(jobjItem);
});
//await InnerDownloadOriginalTask(batchNo, taskInfo, userWebAccountConfig);
var postResult = await InnerRemoteDownLaraPaper(batchNo, downloadUrl, JSON.Serialize(jobjPost));
if (postResult.succ)
{
result.succ = true;
result.msg = "成功";
}
else
{
result.succ = false;
result.msg = postResult.msg;
}
}
catch (Exception ex)
{
throw Oops.Bah("请求提单纸登记异常,{0}", ex.Message);
}
return result;
}
#endregion
#region 远程请求请求提单纸登记
///
/// 远程请求请求提单纸登记
///
/// 批次号
/// 请求URL
/// 请求参数
///
private async Task InnerRemoteDownLaraPaper(string batchNo, string url, string jsonMsg)
{
var result = new TaskManageOrderResultDto();
DateTime bDate = DateTime.Now;
try
{
_logger.LogInformation("批次={no} 请求报文开始", batchNo);
var res = await url.SetHttpMethod(HttpMethod.Post)
.SetBody(jsonMsg, "application/json")
.SetContentEncoding(Encoding.UTF8)
.PostAsync();
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation("批次={no} 请求完成,耗时:{timeDiff}ms. 结果{msg}", batchNo, timeDiff, JSON.Serialize(res));
if (res.StatusCode == System.Net.HttpStatusCode.OK)
{
var userResult = await res.Content.ReadAsStringAsync();
var downResult = JSON.Deserialize(userResult);
//返回详情
result.msg = downResult.message.ToString();
//返回代码
if (downResult.status.ToString() == "1")
{
result.succ = true;
}
else
{
result.succ = false;
}
}
result.ext = eDate;
}
catch (Exception ex)
{
//如果有异常直接抛出错误
throw Oops.Bah(ex.Message);
}
return result;
}
#endregion
#region LARA提单纸登记
///
/// LARA提单纸登记
///
/// 任务主键数组
/// 返回结果
[HttpPost("/TaskManage/LaraPaperRegist")]
public async Task LaraPaperRegist([FromQuery]string[] PKIds)
{
LaraPaperRegistDto result = new LaraPaperRegistDto();
List list = new List();
string batchNo = IDGen.NextID().ToString();
_logger.LogInformation("批次={no} ids={ids} LARA提单纸登记开始", batchNo, string.Join(",", PKIds));
/*
1、通过任务主键记录关联所有相同订舱主键相同并且任务类型是(DRAFT)的记录。
2、关联任务正本下载运行表(结束时间)
问题:提单纸页数计算是通过主单号来最新记录提取文件页数,为什么LARA提单纸登记没有用这个模式。(没理解)
*/
try
{
//
var List = _taskBaseInfoRepository.EntityContext.Queryable()
.InnerJoin((tsk, tsk2) => tsk.BOOK_ORDER_NO == tsk2.BOOK_ORDER_NO)
.Where((tsk, tsk2) => PKIds.Contains(tsk.PK_ID) && tsk2.TASK_TYPE == TaskBusiTypeEnum.DRAFT.ToString())
.Select((tsk, tsk2) => new { tsk = tsk, tsk2 = tsk2 }).ToList();
var list2 = List.GroupBy(t => t.tsk.PK_ID).Select(t =>
{
var curList = t.ToList();
if (curList.Count > 0)
{
return new { tsk = curList.FirstOrDefault().tsk, tsk2 = curList.OrderByDescending(a => a.tsk2.CreatedTime).FirstOrDefault().tsk2 };
}
return null;
}).Where(t => t != null).ToList();
if (list2.Count > 0)
{
var taskPKIdList = list2.Select(t => t.tsk2.PK_ID).Distinct().ToArray();
var originalDownloadHisInfo = _taskOriginalDownloadHisInfoRepository.AsQueryable()
.Where(t => taskPKIdList.Contains(t.TASK_ID))
.OrderByDescending(t => t.END_DATE)
.First();
var fileList = _taskBaseInfoRepository.EntityContext.Queryable()
.InnerJoin((tsk, file) => tsk.PK_ID == file.TASK_PKID)
.Where((tsk, file) =>
tsk.TASK_TYPE == TaskBusiTypeEnum.DRAFT.ToString() && taskPKIdList.Contains(tsk.PK_ID))
.Select((tsk, file) => new { tsk = tsk, file = file }).ToList();
var calcList = fileList.GroupBy(t => t.tsk.PK_ID)
.Select(a =>
{
var currList = a.ToList();
return new
{
tsk = currList.FirstOrDefault().tsk,
clist = a.Select(x => x.file).ToList()
};
}).OrderByDescending(t => t.tsk.CreatedTime).ToList();
var bookingNoList = list2.Select(t => !string.IsNullOrWhiteSpace(t.tsk.BOOK_ORDER_NO) ?long.Parse(t.tsk.BOOK_ORDER_NO):0)
.Where(t=>t > 0).Distinct().ToList();
var orderList = _bookingOrderRepository.AsQueryable().Where(t => bookingNoList.Contains(t.Id)).ToList();
list2.ForEach(t =>
{
LaraPaperRegistDetailDto laraInfo = new LaraPaperRegistDetailDto();
laraInfo.OrderNo = t.tsk.BOOK_ORDER_NO;
laraInfo.TaskId = t.tsk.PK_ID;
laraInfo.MBLNo = t.tsk.MBL_NO;
var files = calcList.FirstOrDefault(a => a.tsk.PK_ID.Equals(t.tsk2.PK_ID));
if (files != null)
{
laraInfo.DraftNum = files.clist.Select(t => t.FILE_NAME.GetPageNum()).Sum();
}
laraInfo.OriginalDownTime = originalDownloadHisInfo?.END_DATE;
var orderInfo = orderList.FirstOrDefault(a => a.Id == long.Parse(t.tsk.BOOK_ORDER_NO));
laraInfo.IssueType = orderInfo?.ISSUETYPE;
//laraInfo.IssueTypeName = t.tsk2.issu;
list.Add(laraInfo);
});
result.DetailList = list;
}
var laraPaperInfo = _taskLARAPaperInfoRepository.AsQueryable()
.Where(t => t.CreatedUserId == UserManager.UserId)
.OrderByDescending(t => t.NUMBER_TO).First();
result.NumberTo = laraPaperInfo != null ? laraPaperInfo.NUMBER_TO : "1".PadLeft(9, '0'); ;
result.CalcList = InnerCalcLaraPageNumbers(new CalcLaraPageNumbersDto
{
numberTo = result.NumberTo,
paperList = result.DetailList.Select((t, idx) =>
{
return new LaraPaperRegistPostDto
{
DraftNum = t.DraftNum,
ISSUETYPE = t.IssueType,
MBLNO = t.MBLNo,
TaskId = t.TaskId,
ORDNO = t.OrderNo,
SortNo = idx + 1,
};
}).ToList()
},true);
}
catch (Exception ex)
{
throw Oops.Bah("LARA提单纸登记异常,{0}", ex.Message);
}
return result;
}
#endregion
#region 下载任务附件
///