You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

7136 lines
332 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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
{
/// <summary>
/// 任务管理
/// </summary>
[ApiDescriptionSettings("Application", Name = "TaskManage", Order = 10)]
public class TaskManageService : ITaskManageService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<TaskBaseInfo> _taskBaseInfoRepository;
private readonly SqlSugarRepository<TaskSISubmitted> _taskSISubmittedRepository;
private readonly SqlSugarRepository<TaskSISubmittedCtn> _taskSISubmittedCtnRepository;
private readonly SqlSugarRepository<TaskBillFeeDetailInfo> _taskBillFeeDetailInfoRepository;
private readonly SqlSugarRepository<TaskFileInfo> _taskFileInfoRepository;
private readonly SqlSugarRepository<TaskEmailInfo> _taskEmailInfoRepository;
private readonly SqlSugarRepository<TaskVGMInfo> _taskVGMInfoRepository;
private readonly SqlSugarRepository<TaskVGMCtnInfo> _taskVGMCtnInfoRepository;
private readonly SqlSugarRepository<BookingCtnVGM> _bookingCtnVGMRepository;
private readonly SqlSugarRepository<SysUser> _sysUserRepository;
private readonly SqlSugarRepository<TaskStatManageInfo> _taskStatManageInfoRepository;
private readonly SqlSugarRepository<TaskOriginalDownloadHisInfo> _taskOriginalDownloadHisInfoRepository;
private readonly SqlSugarRepository<TaskChargesHisInfo> _taskChargesHisInfoRepository;
private readonly SqlSugarRepository<TaskLARAPaperInfo> _taskLARAPaperInfoRepository;
private readonly SqlSugarRepository<TaskPerBillBaseInfo> _taskPerBillBaseInfoRepository;
private readonly SqlSugarRepository<TaskStoreMsgInfo> _taskStoreMsgInfoRepository;
private readonly SqlSugarRepository<TaskChangeShipHisInfo> _taskChangeShipHisInfoRepository;
private readonly SqlSugarRepository<TaskBCInfo> _taskBCInfoRepository;
private readonly SqlSugarRepository<TaskBCCTNInfo> _taskBCCTNInfoRepository;
private readonly SqlSugarRepository<BookingSlotBase> _bookingSlotBaseRepository;
private readonly SqlSugarRepository<BookingOrder> _bookingOrderRepository;
private readonly SqlSugarRepository<BookingCtn> _bookingOrderContaRepository;
private readonly SqlSugarRepository<BookingCtnDetail> _bookingOrderContaCargoRepository;
private readonly SqlSugarRepository<BookingStatus> _bookingStatusRepository;
private readonly SqlSugarRepository<BookingOrderContact> _bookingOrderContactRepository;
private readonly SqlSugarRepository<DjyUserMailAccount> _djyUserMailAccountRepository;
private readonly SqlSugarRepository<TaskTruckInfo> _taskTruckInfoRepository;
private readonly SqlSugarRepository<TaskTruckCtn> _taskTruckCtnRepository;
private readonly SqlSugarRepository<TaskCutDateChangeInfo> _taskCutDateChangeInfoRepository;
private readonly SqlSugarRepository<TaskCutDateChangeDetailInfo> _taskCutDateChangeDetailInfoRepository;
private readonly SqlSugarRepository<TaskRollingNominationInfo> _taskRollingNominationInfoRepository;
private readonly SqlSugarRepository<TaskRollingNominationShipInfo> _taskRollingNominationShipInfoRepository;
private readonly SqlSugarRepository<TaskRollingNominationDetailInfo> _taskRollingNominationDetailInfoRepository;
private readonly SqlSugarRepository<TaskDraftInfo> _taskDraftInfoRepository;
private readonly SqlSugarRepository<TaskPODDischargeGateoutFullInfo> _taskPODDischargeGateoutFullInfoRepository;
private readonly SqlSugarRepository<TaskPODDischargeGateoutFullDetailInfo> _taskPODDischargeGateoutFullDetailInfoRepository;
private readonly SqlSugarRepository<TaskCautionNoticeInfo> _taskCautionNoticeInfoRepository;
private readonly SqlSugarRepository<TaskCautionNoticeDetailInfo> _taskCautionNoticeDetailInfoRepository;
private readonly SqlSugarRepository<TaskRouteChangeAdvisoryInfo> _taskRouteChangeAdvisoryInfoRepository;
private readonly SqlSugarRepository<TaskRouteChangeAdvisoryDetailInfo> _taskRouteChangeAdvisoryDetailInfoRepository;
private readonly SqlSugarRepository<TaskTransPlanHasChangeInfo> _taskTransPlanHasChangeInfoRepository;
private readonly SqlSugarRepository<TaskTransPlanHasChangeDetailInfo> _taskTransPlanHasChangeDetailInfoRepository;
private readonly SqlSugarRepository<TaskPOLContainerNotPickUpInfo> _taskPOLContainerNotPickUpInfoRepository;
private readonly SqlSugarRepository<TaskFlowTenant> _taskFlowTenant;
private readonly IDjyWebsiteAccountConfigService _webAccountConfig;
private readonly ISysCacheService _cache;
private readonly ILogger<BookingOrderService> _logger;
private readonly ISysDataUserMenu _sysDataUserMenuService;
private readonly INamedServiceProvider<IBookingOrderService> _namedBookingOrderServiceProvider;
private readonly INamedServiceProvider<ITaskManageRollingNominationService> _namedRollingNominationServiceProvider;
private readonly INamedServiceProvider<ITaskManageBCService> _namedTaskManageBCServiceProvider;
private readonly INamedServiceProvider<IBookingMSKAPIService> _namedBookingMSKAPIServiceProvider;
private readonly INamedServiceProvider<ITaskManageSISubmittedService> _namedtaskSISubmittedServiceProvider;
private readonly INamedServiceProvider<ITaskCautionNoticeService> _namedTaskCautionNoticeServiceProvider;
private readonly INamedServiceProvider<ITaskTransPlanHasChangeService> _namedTaskTransPlanHasChangeServiceProvider;
private readonly INamedServiceProvider<ITaskPOLContainerNotPickUpService> _namedTaskPOLContainerNotPickUpServiceProvider;
private readonly INamedServiceProvider<ITaskManageCutDateChangeService> _namedTaskManageCutDateChangeServiceProvider;
private readonly INamedServiceProvider<IRouteChangeAdvisoryService> _namedRouteChangeAdvisoryServiceServiceProvider;
private readonly INamedServiceProvider<IBookingLabelService> _namedBookingLabelServiceServiceProvider;
private readonly INamedServiceProvider<ITaskManagePODDischargeGateoutFullService> _namedPODDischargeGateoutFullProvider;
private readonly INamedServiceProvider<ITaskManageVGMService> _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<TaskBaseInfo> taskBaseInfoRepository,
SqlSugarRepository<TaskSISubmitted> taskSISubmittedRepository,
SqlSugarRepository<TaskSISubmittedCtn> taskSISubmittedCtnRepository,
SqlSugarRepository<TaskBillFeeDetailInfo> taskBillFeeDetailInfoRepository,
SqlSugarRepository<TaskFileInfo> taskFileInfoRepository,
SqlSugarRepository<TaskEmailInfo> taskEmailInfoRepository,
SqlSugarRepository<TaskVGMInfo> taskVGMInfoRepository,
SqlSugarRepository<TaskVGMCtnInfo> taskVGMCtnInfoRepository,
SqlSugarRepository<SysUser> sysUserRepository,
SqlSugarRepository<TaskStatManageInfo> taskStatManageInfoRepository,
SqlSugarRepository<TaskOriginalDownloadHisInfo> taskOriginalDownloadHisInfoRepository,
SqlSugarRepository<TaskChargesHisInfo> taskChargesHisInfoRepository,
SqlSugarRepository<BookingOrder> bookingOrderRepository,
SqlSugarRepository<TaskLARAPaperInfo> taskLARAPaperInfoRepository,
SqlSugarRepository<BookingCtn> bookingOrderContaRepository,
SqlSugarRepository<BookingCtnDetail> bookingOrderContaCargoRepository,
SqlSugarRepository<BookingStatus> bookingStatusRepository,
SqlSugarRepository<DjyUserMailAccount> djyUserMailAccountRepository,
SqlSugarRepository<TaskPerBillBaseInfo> taskPerBillBaseInfoRepository,
SqlSugarRepository<TaskStoreMsgInfo> taskStoreMsgInfoRepository,
SqlSugarRepository<TaskChangeShipHisInfo> taskChangeShipHisInfoRepository,
SqlSugarRepository<BookingOrderContact> bookingOrderContactRepository,
SqlSugarRepository<TaskTruckInfo> taskTruckInfoRepository,
SqlSugarRepository<TaskTruckCtn> taskTruckCtnRepository,
SqlSugarRepository<TaskBCInfo> taskBCInfoRepository,
SqlSugarRepository<TaskBCCTNInfo> taskBCCTNInfoRepository,
SqlSugarRepository<TaskCutDateChangeInfo> taskCutDateChangeInfoRepository,
SqlSugarRepository<TaskCutDateChangeDetailInfo> taskCutDateChangeDetailInfoRepository,
SqlSugarRepository<TaskRollingNominationInfo> taskRollingNominationInfoRepository,
SqlSugarRepository<TaskRollingNominationShipInfo> taskRollingNominationShipInfoRepository,
SqlSugarRepository<TaskRollingNominationDetailInfo> taskRollingNominationDetailInfoRepository,
SqlSugarRepository<BookingCtnVGM> bookingCtnVGMRepository,
SqlSugarRepository<BookingSlotBase> bookingSlotBaseRepository,
SqlSugarRepository<TaskDraftInfo> taskDraftInfoRepository,
SqlSugarRepository<TaskPODDischargeGateoutFullInfo> taskPODDischargeGateoutFullInfoRepository,
SqlSugarRepository<TaskPODDischargeGateoutFullDetailInfo> taskPODDischargeGateoutFullDetailInfoRepository,
SqlSugarRepository<TaskCautionNoticeInfo> taskCautionNoticeInfoRepository,
SqlSugarRepository<TaskCautionNoticeDetailInfo> taskCautionNoticeDetailInfoRepository,
SqlSugarRepository<TaskRouteChangeAdvisoryInfo> taskRouteChangeAdvisoryInfoRepository,
SqlSugarRepository<TaskRouteChangeAdvisoryDetailInfo> taskRouteChangeAdvisoryDetailInfoRepository,
SqlSugarRepository<TaskTransPlanHasChangeInfo> taskTransPlanHasChangeInfoRepository,
SqlSugarRepository<TaskTransPlanHasChangeDetailInfo> taskTransPlanHasChangeDetailInfoRepository,
SqlSugarRepository<TaskPOLContainerNotPickUpInfo> taskPOLContainerNotPickUpInfoRepository,
INamedServiceProvider<IBookingOrderService> namedBookingOrderServiceProvider,
IDjyWebsiteAccountConfigService webAccountConfig,
ISysCacheService cache,
ISysDataUserMenu sysDataUserMenuService,
INamedServiceProvider<ITaskManageRollingNominationService> namedRollingNominationServiceProvider,
INamedServiceProvider<ITaskManageBCService> namedTaskManageBCServiceProvider,
IBookingValueAddedService bookingValueAddedService,
INamedServiceProvider<IBookingMSKAPIService> namedBookingMSKAPIServiceProvider,
INamedServiceProvider<ITaskManageSISubmittedService> namedtaskSISubmittedServiceProvider,
INamedServiceProvider<ITaskCautionNoticeService> namedTaskCautionNoticeServiceProvider,
INamedServiceProvider<ITaskTransPlanHasChangeService> namedTaskTransPlanHasChangeServiceProvider,
INamedServiceProvider<ITaskPOLContainerNotPickUpService> namedTaskPOLContainerNotPickUpServiceProvider,
INamedServiceProvider<ITaskManageCutDateChangeService> namedTaskManageCutDateChangeServiceProvider,
INamedServiceProvider<IRouteChangeAdvisoryService> namedRouteChangeAdvisoryServiceServiceProvider,
INamedServiceProvider<IBookingLabelService> namedBookingLabelServiceServiceProvider,
INamedServiceProvider<ITaskManagePODDischargeGateoutFullService> namedPODDischargeGateoutFullProvider,
INamedServiceProvider<ITaskManageVGMService> namedVGMServiceProvider,
ILogger<BookingOrderService> logger, BookingOrderAutoService bookingOrderAuto,
SqlSugarRepository<TaskFlowTenant> 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 创建任务
/// <summary>
/// 创建任务
/// </summary>
/// <param name="info">任务详情</param>
/// <returns>返回回执</returns>
[HttpPost("/TaskManage/CreateTaskJob"), AllowAnonymous, ApiUser(ApiCode = "BCTaskManage")]
public async Task<TaskManageOrderResultDto> 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 新增任务
/// <summary>
/// 新增任务
/// </summary>
/// <param name="info">任务详情</param>
/// <param name="batchNo">批次号</param>
/// <param name="file">文件</param>
/// <param name="modifyFile">变更文件内容后的文件</param>
/// <returns>返回回执</returns>
[SqlSugarUnitOfWork]
private async Task<TaskManageOrderResultDto> 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<TaskManageOrderFileInfo>();
}
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<TaskManageOrderFileInfo>();
}
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<TaskManageOrderFileInfo>();
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<TaskManageOrderFileInfo>();
}
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>();
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<TaskSISubmittedCtn>();
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<ITransient>(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<TaskBillFeeDetailInfo>();
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<TaskPerBillBaseInfo>();
//写入
await _taskPerBillBaseInfoRepository.InsertAsync(taskPerBillBaseInfo);
if (info.Main.FeeList != null && info.Main.FeeList.Count > 0)
{
info.Main.FeeList.ForEach(async fee =>
{
var feeInfo = fee.Adapt<TaskBillFeeDetailInfo>();
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<TaskTruckInfo>();
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<List<TaskTruckCtn>>();
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<TaskBCInfo>();
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<TaskBCCTNInfo>();
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<ITransient>(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<ITransient>(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<ITransient>(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<TaskCutDateChangeInfo>();
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<TaskCutDateChangeDetailInfo>();
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<ITransient>(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<TaskVGMInfo> vgmList = new List<TaskVGMInfo>();
info.Main.VGMFeedBack.ForEach(p =>
{
//异步写入
var vgmInfo = p.Adapt<TaskVGMInfo>();
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<TaskVGMCtnInfo>();
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<ModifyServiceProjectStatusDetailDto> {
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<ITransient>(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<TaskRollingNominationInfo>();
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<TaskRollingNominationShipInfo>();
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<TaskRollingNominationShipInfo>();
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<TaskRollingNominationDetailInfo>();
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<ITransient>(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>();
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<TaskPODDischargeGateoutFullInfo>();
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<TaskPODDischargeGateoutFullDetailInfo>();
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<ITransient>(nameof(TaskManagePODDischargeGateoutFullService));
await name.AutoTransferNotice(taskInfo.PK_ID);
}
#endregion
#region 重要提醒
if (info.Main.TaskType == TaskBaseTypeEnum.CAUTION_NOTICE)
{
TaskCautionNoticeInfo taskCautionNoticeInfo = info.Main.CautionNoticeInfo.Adapt<TaskCautionNoticeInfo>();
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<TaskCautionNoticeDetailInfo>();
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<ITransient>(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>();
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<ITransient>(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>();
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<ITransient>(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>();
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<ITransient>(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
/// <summary>
/// 执行方法
/// </summary>
/// <param name="flow">当前流程配置</param>
/// <param name="depth">循环深度</param>
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 查询订舱表查询用户和租户信息
/// <summary>
/// 查询订舱表查询用户和租户信息
/// </summary>
/// <param name="userId">用户ID</param>
/// <returns>返回用户和租户信息</returns>
private UserTendDto GetUserTendInfo(string userId)
{
UserTendDto userTendDto = null;
//这里因为接口是不做授权验证的所以这里直接写的动态sql提取了用户和租户信息
var userTendInfo = _sysUserRepository.EntityContext.Queryable<dynamic>("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 查询订舱表查询用户和租户信息
/// <summary>
/// 查询订舱表查询用户和租户信息
/// </summary>
/// <param name="djyUserId">大简云用户ID</param>
/// <param name="djyUserEmail">大简云用户邮箱</param>
/// <returns>返回用户和租户信息</returns>
private UserTendDto GetUserTendInfoByDJYUserId(string djyUserId,string djyUserEmail)
{
UserTendDto userTendDto = null;
//这里因为接口是不做授权验证的所以这里直接写的动态sql提取了用户和租户信息
var userTendInfo = _sysUserRepository.EntityContext.Queryable<dynamic>("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和邮箱获取用户信息
/// <summary>
/// 通过租户ID和邮箱获取用户信息
/// </summary>
/// <param name="tenantId">大简云租户ID</param>
/// <param name="emailAccount">大简云用户邮箱</param>
/// <returns>返回用户和租户信息</returns>
private UserTendDto GetUserTendInfoByEmail(long tenantId, string emailAccount)
{
UserTendDto userTendDto = null;
//这里因为接口是不做授权验证的所以这里直接写的动态sql提取了用户和租户信息
var userTendInfo = _sysUserRepository.EntityContext.Queryable<dynamic>("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 获取查询参数
/// <summary>
/// 获取查询参数
/// </summary>
/// <param name="ParaType">参数类型 STATUS-任务状态;TASK_TYPE-任务类型;SOURCE-任务来源 CATEGORY-分类</param>
/// <returns>返回回执</returns>
/// <example>TASK_TYPE</example>
[HttpGet("/TaskManage/GetParaInfo")]
public async Task<TaskManageOrderResultDto> GetParaInfo([QueryString] string ParaType)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
Dictionary<string, string> dict = new Dictionary<string, string>();
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 获取登陆人相关的任务统计信息
/// <summary>
/// 获取登陆人相关的任务统计信息
/// </summary>
/// <param name="isReCalc">是否强制计算</param>
/// <returns>返回回执</returns>
[HttpGet("/TaskManage/GetCurrentTotalStat")]
public async Task<TaskUserStatResultInfo> GetCurrentTotalStat([FromQuery] bool isReCalc = false)
{
TaskUserStatResultInfo resultInfo = new TaskUserStatResultInfo
{
LevelTop = new List<TaskUserStatItem>(),
LevelNext = new List<TaskUserStatItemNext>(),
LevelTree = new List<TaskUserStatItemTree>()
};
/*
1、首先判断当前登陆人是否有统计记录如果没有触发统计生成统计记录。
2、如果isReCalc=true表示强制重新统计数据并重新更新统计数据。
3、按照统计类型个人/公共)、任务状态、是否异常分组汇总,并写入统计表。
*/
try
{
var userTendInfo = await _sysUserRepository.AsQueryable()
.LeftJoin<SysTenant>((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<long> 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<TaskUserStatItemNext>();
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<TaskUserStatItemNext>();
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<TaskUserStatItemNext>();
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 任务台账查询
/// <summary>
/// 任务台账查询
/// </summary>
/// <param name="QuerySearch">任务台账查询请求</param>
/// <returns>返回结果</returns>
[HttpPost("/TaskManage/GetPage")]
public async Task<SqlSugarPagedList<dynamic>> GetPageAsync(QueryTaskManageDto QuerySearch)
{
List<string> mblList = new List<string>();
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<TaskBaseInfoDto, TaskBaseInfo>(QuerySearch.SortField);
//菜单375504048771141=我的任务台账
List<long> userlist = await _sysDataUserMenuService.GetDataScopeList(MenuConst.MenuTaskManage);
if (userlist == null)
userlist = new List<long> { UserManager.UserId };
if (userlist.Count > 0)
userlist = userlist.Distinct().ToList();
_logger.LogInformation("任务台账权限范围 {list}", userlist);
List<string> userIds = new List<string>();
if (!string.IsNullOrWhiteSpace( QuerySearch.DJYUserId))
{
//获取缓存数据
if (!_cache.Exists(QuerySearch.DJYUserId+ "Authorization"))
{
throw Oops.Bah("无效授权");
}
userIds = JsonConvert.DeserializeObject<List<string>>( _cache.Get(QuerySearch.DJYUserId));
}
switch (QuerySearch.TaskType)
{
case "BC":
var bc = await _taskBaseInfoRepository.AsQueryable().LeftJoin<TaskBCInfo>((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<dynamic>((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<SqlSugarPagedList<dynamic>>();
case "SI_FEEDBACK":
var SI_FEEDBACK = await _taskBaseInfoRepository.AsQueryable().LeftJoin<TaskSISubmitted>((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<dynamic>((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<SqlSugarPagedList<dynamic>>();
case "INVOICE_BILL_MAIL":
var INVOICE_BILL_MAIL = await _taskBaseInfoRepository.AsQueryable().LeftJoin<TaskPerBillBaseInfo>((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<dynamic>((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<SqlSugarPagedList<dynamic>>();
case "TRUCK_DISPATCH":
var TRUCK_DISPATCH = await _taskBaseInfoRepository.AsQueryable().LeftJoin<TaskTruckInfo>((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<dynamic>((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<SqlSugarPagedList<dynamic>>();
case "CUT_MODIFY":
var CUT_MODIFY = await _taskBaseInfoRepository.AsQueryable().LeftJoin<TaskCutDateChangeInfo>((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<dynamic>((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<SqlSugarPagedList<dynamic>>();
case "ROLLING_NOMINATION":
case "TRANSFER_NOMINATION":
var ysh = await _taskBaseInfoRepository.AsQueryable().LeftJoin<TaskRollingNominationInfo>((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<dynamic>((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<SqlSugarPagedList<dynamic>>();
case "DRAFT":
var DRAFT = await _taskBaseInfoRepository.AsQueryable().LeftJoin<TaskDraftInfo>((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<dynamic>((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<SqlSugarPagedList<dynamic>>();
case "POD_DISCHARGE_FULL":
case "POD_GATEOUT_FULL":
var POD = await _taskBaseInfoRepository.AsQueryable().LeftJoin<TaskPODDischargeGateoutFullInfo>((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<dynamic>((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<SqlSugarPagedList<dynamic>>();
case "CAUTION_NOTICE":
var CAUTION_NOTICE = await _taskBaseInfoRepository.AsQueryable().LeftJoin<TaskCautionNoticeInfo>((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<dynamic>((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<SqlSugarPagedList<dynamic>>();
case "ROUTE_CUT_CHANGE":
var ROUTE_CUT_CHANGE = await _taskBaseInfoRepository.AsQueryable().LeftJoin<TaskRouteChangeAdvisoryInfo>((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<dynamic>((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<SqlSugarPagedList<dynamic>>();
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<dynamic>(t => new
{
PK_ID = t.PK_ID.SelectAll()
})
.ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize);
return entities.Adapt<SqlSugarPagedList<dynamic>>();
break;
}
}
#endregion
#region 下载正本提单(可批量)
/// <summary>
/// 下载正本提单(可批量)
/// </summary>
/// <param name="PKIds">任务主键数组</param>
/// <returns>返回结果</returns>
[HttpPost("/TaskManage/DownloadOriginalTask")]
public async Task<TaskManageOrderResultDto> 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 单票正本下载
/// <summary>
/// 单票正本下载
/// </summary>
/// <param name="batchNo">批次号</param>
/// <param name="taskBaseInfo">任务详情</param>
/// <param name="webAccountConfig">网站账户配置</param>
/// <returns>返回回执</returns>
private async Task<TaskManageOrderResultDto> 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<dynamic>(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<string, string> formDict = new Dictionary<string, string> {
{"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 远程请求正本下载
/// <summary>
/// 远程请求正本下载
/// </summary>
/// <param name="batchNo">批次号</param>
/// <param name="url">请求URL</param>
/// <param name="dic">请求参数</param>
/// <returns></returns>
private async Task<TaskManageOrderResultDto> InnerRemoteDownOriginal(string batchNo, string url, Dictionary<string, string> 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<dynamic>(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 扣费
/// <summary>
/// 扣费
/// </summary>
/// <param name="taskBaseInfo">任务信息</param>
/// <param name="isCharge">是否执行扣费 true-执行扣费 false-不执行扣费(主要是符合扣费条件但是由于超时没有得到准确回执)</param>
/// <returns>返回回执</returns>
private async Task<TaskManageOrderResultDto> 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 完成任务(可批量)
/// <summary>
/// 完成任务(可批量)
/// </summary>
/// <param name="PKIds">任务主键数组</param>
/// <returns>返回结果</returns>
[HttpPost("/TaskManage/CompleteTask")]
public async Task<TaskManageOrderResultDto> CompleteTask([FromBody] string[] PKIds)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
List<TaskManageOrderResultDto> taskRunList = new List<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);
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 单票执行任务
/// <summary>
/// 单票执行任务
/// </summary>
/// <param name="batchNo">批次号</param>
/// <param name="taskBaseInfo">任务详情</param>
/// <param name="taskOperTypeEnum">操作类型</param>
/// <param name="sortNo">顺序号</param>
/// <returns>返回回执</returns>
private async Task<TaskManageOrderResultDto> 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<TaskBaseInfo>().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 取消任务(可批量)
/// <summary>
/// 取消任务(可批量)
/// </summary>
/// <param name="PKIds">任务主键数组</param>
/// <returns>返回结果</returns>
[HttpPost("/TaskManage/CancelTask")]
public async Task<TaskManageOrderResultDto> CancelTask([FromBody] string[] PKIds)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
List<TaskManageOrderResultDto> taskRunList = new List<TaskManageOrderResultDto>();
_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 挂起任务(可批量)
/// <summary>
/// 挂起任务(可批量)
/// </summary>
/// <param name="PKIds">任务主键数组</param>
/// <returns>返回结果</returns>
[HttpPost("/TaskManage/PendingTask")]
public async Task<TaskManageOrderResultDto> PendingTask(string[] PKIds)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
_logger.LogInformation("批次={no} ids={ids} 挂起任务开始", batchNo, string.Join(",", PKIds));
List<TaskManageOrderResultDto> taskRunList = new List<TaskManageOrderResultDto>();
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 提单纸页数计算
/// <summary>
/// 提单纸页数计算
/// </summary>
/// <param name="PKIds">任务主键数组</param>
/// <returns>返回结果</returns>
[HttpPost("/TaskManage/LaraPaperCalc")]
public async Task<List<LaraPaperCalcInfo>> LaraPaperCalc(string[] PKIds)
{
List<LaraPaperCalcInfo> list = new List<LaraPaperCalcInfo>();
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<TaskBaseInfo>()
.InnerJoin<TaskFileInfo>((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 请求提单纸登记
/// <summary>
/// 请求提单纸登记
/// </summary>
/// <param name="laraPaperList">提单纸登记请求参数列表</param>
/// <returns>返回结果</returns>
[HttpPost("/TaskManage/LaraPaperRegistPost")]
public async Task<TaskManageOrderResultDto> LaraPaperRegistPost(List<LaraPaperRegistPostDto> 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 远程请求请求提单纸登记
/// <summary>
/// 远程请求请求提单纸登记
/// </summary>
/// <param name="batchNo">批次号</param>
/// <param name="url">请求URL</param>
/// <param name="jsonMsg">请求参数</param>
/// <returns></returns>
private async Task<TaskManageOrderResultDto> 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<dynamic>(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提单纸登记
/// <summary>
/// LARA提单纸登记
/// </summary>
/// <param name="PKIds">任务主键数组</param>
/// <returns>返回结果</returns>
[HttpPost("/TaskManage/LaraPaperRegist")]
public async Task<LaraPaperRegistDto> LaraPaperRegist([FromQuery]string[] PKIds)
{
LaraPaperRegistDto result = new LaraPaperRegistDto();
List<LaraPaperRegistDetailDto> list = new List<LaraPaperRegistDetailDto>();
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<TaskBaseInfo>()
.InnerJoin<TaskBaseInfo>((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<TaskBaseInfo>()
.InnerJoin<TaskFileInfo>((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 下载任务附件
/// <summary>
/// 下载任务附件
/// </summary>
/// <param name="taskPKId"></param>
/// <returns>返回文件流</returns>
[HttpGet("/TaskManage/DownloadTaskAttach")]
public async Task<IActionResult> DownloadTaskAttach([FromQuery] string taskPKId)
{
FileStreamResult result = null;
string batchNo = IDGen.NextID().ToString();
var fileList = _taskFileInfoRepository.AsQueryable().Where(t => t.TASK_PKID == taskPKId).OrderByDescending(t=>t.CreatedTime).ToList();
var fileInfo = fileList.FirstOrDefault();
if (fileInfo.FILE_PATH.StartsWith("http://"))
{
var fileStream = await InnerGetDownloadFile(fileInfo.FILE_PATH, taskPKId, batchNo);
result = new FileStreamResult(fileStream, "application/octet-stream") { FileDownloadName = fileInfo.FILE_NAME };
}
else if (System.IO.File.Exists(fileInfo.FILE_PATH))
{
result = new FileStreamResult(new FileStream(fileInfo.FILE_PATH, FileMode.Open), "application/octet-stream") { FileDownloadName = fileInfo.FILE_NAME };
}
return result;
}
#endregion
#region 异步下载文件
/// <summary>
/// 异步下载文件
/// </summary>
/// <param name="fileUrl">文件请求URL</param>
/// <param name="taskPKId">任务主键</param>
/// <param name="batchNo">批次号</param>
/// <returns>返回文件流</returns>
private async Task<Stream> InnerGetDownloadFile(string fileUrl,string taskPKId,string batchNo)
{
Stream stream = null;
try
{
DateTime bDate = DateTime.Now;
stream = await fileUrl.GetAsStreamAsync();
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation("批次={no} url={url} 请求完成,耗时:{timeDiff}ms.", batchNo, fileUrl, timeDiff);
}
catch (Exception ex)
{
_logger.LogInformation("批次={no} url={url} 下载文件异常, 结果{msg}", batchNo, fileUrl, ex.Message);
throw Oops.Bah(nameof(InnerGetDownloadFile)+"下载文件异常,{0}", ex.Message);
}
return stream;
}
#endregion
#region 正本附件批量打印
/// <summary>
/// 正本附件批量打印
/// </summary>
/// <param name="PKIds">任务主键数组</param>
/// <returns>返回文件流</returns>
[HttpPost("/TaskManage/PrintBatch")]
public async Task<IActionResult> PrintBatch(string[] PKIds)
{
FileStreamResult result = null;
/*
1、通过任务主键获取所有的文件列表。只合并PDF文件其他的文件不处理。
2、创建临时文件存放目录。
3、如果是http://开头的文档,需要使用下载文件,并变更为本地文件
4、PDF合成所有文件。
5、写入下载记录表。
6、返回文件流。
*/
try
{
var fileList = _taskBaseInfoRepository.EntityContext.Queryable<TaskBaseInfo>()
.InnerJoin<TaskFileInfo>((tsk, file) => tsk.PK_ID == file.TASK_PKID)
.Where((tsk, file) => PKIds.Contains(tsk.PK_ID) && file.FILE_TYPE.Equals(".pdf"))
.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 pdfList = calcList.SelectMany(t => t.clist).Select((t, idx) => new
{
Idx = idx,
file = t
}).ToList();
if (pdfList.Count == 0)
throw Oops.Oh($"没有可以合并的PDF文件");
string filePath = string.Empty;
string tempFileName = IDGen.NextID().ToString();
var opt = App.GetOptions<TempFileOptions>().Path;
filePath = $"{Path.Combine(App.WebHostEnvironment.WebRootPath, opt)}\\TempPDFMerge\\";//服务器路径
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
filePath = filePath.Replace("\\", "/");
}
//预先创建目录
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
var mergePdfPath = Path.Combine(filePath, $"{tempFileName}.pdf");
/*
Document document = null;
PdfCopy copy = null;
pdfList.ForEach(t => {
if(t.Idx == 0)
{
if(t.file.FILE_PATH.IndexOf("http://") >=0)
{
//var dw = InnerRemoteDownFile(t.file.FILE_PATH).GetAwaiter().GetResult();
WebClient wc = new WebClient();
wc.DownloadFile(t.file.FILE_PATH, Path.Combine(filePath, $"{tempFileName}abc.pdf"));
//document = new Document(new PdfReader(dw).GetPageSize(1));
}
else
{
document = new Document(new PdfReader(t.file.FILE_PATH).GetPageSize(1));
}
copy = new PdfCopy(document, new FileStream(mergePdfPath, FileMode.Create));
}
else
{
PdfReader reader = null;
if (t.file.FILE_PATH.IndexOf("http://") >= 0)
{
var dw = InnerRemoteDownFile(t.file.FILE_PATH).GetAwaiter().GetResult();
reader = new PdfReader(dw);
}
else
{
reader = new PdfReader(t.file.FILE_PATH);
}
int n = reader.NumberOfPages;
for (int j = 1; j <= n; j++)
{
document.NewPage();
PdfImportedPage page = copy.GetImportedPage(reader, j);
copy.AddPage(page);
}
reader.Close();
}
});
document.Close();
*/
result = new FileStreamResult(new FileStream(mergePdfPath, FileMode.Open), "application/octet-stream") { FileDownloadName = $"{tempFileName}.pdf" };
}
catch (Exception ex)
{
throw Oops.Bah("LARA提单纸登记异常,{0}", ex.Message);
}
return result;
}
#endregion
#region 下载文件
private async Task<Stream> InnerRemoteDownFile(string filePath)
{
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(filePath);
if (response.IsSuccessStatusCode)
{
System.Net.Http.HttpContent content = response.Content;
var contentStream = await content.ReadAsStreamAsync(); // get the actual content stream
return contentStream;
}
else
{
throw new FileNotFoundException($"{filePath} 文件下载失败");
}
}
}
#endregion
#region 接收换船
/// <summary>
/// 接收换船
/// </summary>
/// <param name="taskPKId">任务主键</param>
/// <returns>返回结果</returns>
[HttpGet("/TaskManage/AcceptChangeShip")]
public async Task<TaskManageOrderResultDto> AcceptChangeShip([FromQuery]string taskPKId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
try
{
var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == taskPKId);
if (taskInfo == null)
Oops.Oh($"任务信息获取失败");
_logger.LogInformation("批次={no} ids={ids} 获取任务完成", batchNo, taskPKId);
if (taskInfo.TASK_TYPE != TaskBusiTypeEnum.CHANGE_SHIP.ToString())
Oops.Oh($"当前任务类型不是{TaskBusiTypeEnum.CHANGE_SHIP.GetDescription()},不能接收换船");
if (string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
Oops.Oh($"任务信息的订舱主键不存在");
if (taskInfo.STATUS != TaskStatusEnum.Create.ToString())
Oops.Oh($"任务状态不是{0},不能【接收换船】", TaskStatusEnum.Create.GetDescription());
var orderInfo = _bookingOrderRepository.AsQueryable()
.First(t => t.Id == long.Parse(taskInfo.BOOK_ORDER_NO));
if (orderInfo == null)
{
orderInfo = _bookingOrderRepository.AsQueryable().First(t => t.MBLNO == taskInfo.MBL_NO);
_logger.LogInformation("批次={no} 订舱主键{id}获取任务失败,通过主单号{mblno}提取完成", batchNo, taskInfo.BOOK_ORDER_NO, taskInfo.MBL_NO);
}
if (orderInfo == null)
Oops.Oh($"订舱信息获取失败");
var userMail = _djyUserMailAccountRepository.AsQueryable().First(x => x.CreatedUserId == orderInfo.CreatedUserId);
if (userMail == null || string.IsNullOrWhiteSpace(userMail.SmtpServer) || userMail.SmtpPort == 0)
{
Oops.Oh($"发件邮箱未配置,或者配置不完整");
}
_logger.LogInformation("批次={no} 获取用户邮箱配置完成", batchNo);
if (!string.IsNullOrWhiteSpace(taskInfo.RESULT_NOTE))
Oops.Oh($"获取换船任务详情失败");
_logger.LogInformation("批次={no} 获取换船任务详情,{note}", batchNo, taskInfo.RESULT_NOTE);
var jsonObj = JSON.Deserialize<dynamic>(taskInfo.RESULT_NOTE);
var taskChangeShipModel = new TaskChangeShipHisInfo {
PK_ID = IDGen.NextID().ToString(),
TASK_PKID = taskInfo.PK_ID,
BOOK_ORDER_NO = orderInfo.Id.ToString(),
MBL_NO = orderInfo.MBLNO,
VESSEL_TO = jsonObj.vessel.ToString(),
VOYNO_TO = jsonObj.voyno.ToString(),
SHIP_AGENCY_TO = jsonObj.shipagency != null ? jsonObj.shipagency : "",
VESSEL_SRC = orderInfo.VESSEL,
VOYNO_SRC = orderInfo.VOYNO,
SHIP_AGENCY_SRC = orderInfo.SHIPAGENCY,
CreatedTime = DateTime.Now,
CreatedUserId = UserManager.UserId,
CreatedUserName = UserManager.Name
};
//写入换船历史表
await _taskChangeShipHisInfoRepository.InsertAsync(taskChangeShipModel);
_logger.LogInformation("批次={no} 写入换船历史表完成{id}", batchNo, taskChangeShipModel.PK_ID);
//更新任务状态
orderInfo = _bookingOrderRepository.AsQueryable().First(t => t.Id == orderInfo.Id);
var oldOrderInfo = orderInfo.Adapt<BookingOrder>();
orderInfo.VESSEL = taskChangeShipModel.VESSEL_TO;
orderInfo.VOYNO = taskChangeShipModel.VOYNO_TO;
orderInfo.SHIPAGENCY = taskChangeShipModel.SHIP_AGENCY_TO;
orderInfo.CreatedTime = DateTime.Now;
orderInfo.CreatedUserId = UserManager.UserId;
orderInfo.CreatedUserName = UserManager.Name;
//更新订舱详情
await _bookingOrderRepository.AsUpdateable(orderInfo).UpdateColumns(it => new
{
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName,
it.VESSEL,
it.VOYNO
}).ExecuteCommandAsync();
// 记录日志
var bookingOrderService = _namedBookingOrderServiceProvider.GetService<ITransient>(nameof(BookingOrderService));
await bookingOrderService.SaveLog(orderInfo, oldOrderInfo, "接收换船后更新订舱");
_logger.LogInformation("批次={no} 更新订舱完成", batchNo);
taskInfo.STATUS = TaskStatusEnum.Complete.ToString();
taskInfo.STATUS_NAME = TaskStatusEnum.Complete.GetDescription();
taskInfo.COMPLETE_DATE = DateTime.Now;
taskInfo.COMPLETE_DEAL = TaskCompleteDealEnum.MANUAL.ToString();
taskInfo.COMPLETE_DEAL_NAME = TaskCompleteDealEnum.MANUAL.GetDescription();
taskInfo.UpdatedTime = DateTime.Now;
taskInfo.UpdatedUserId = UserManager.UserId;
taskInfo.UpdatedUserName = UserManager.Name;
//更新任务表
await _taskBaseInfoRepository.AsUpdateable(taskInfo).UpdateColumns(it => new
{
it.STATUS,
it.STATUS_NAME,
it.COMPLETE_DATE,
it.COMPLETE_DEAL,
it.COMPLETE_DEAL_NAME,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync();
_logger.LogInformation("批次={no} 更新任务完成", batchNo);
//提取订舱相关联系的邮箱信息
var bookContactEmailList = _bookingOrderContactRepository.AsQueryable().Where(t => t.BookingId == orderInfo.Id && !string.IsNullOrWhiteSpace(t.Email))
.Select(t => t.Email).Distinct().ToList();
if(bookContactEmailList.Count > 0)
{
string sendTo = string.Join(";", bookContactEmailList.ToArray());
string emailSubject = $"换船通知-{orderInfo.MBLNO}";
string emailBody = $"提单号为{orderInfo.MBLNO}的订舱已换船<br/>";
var sendResult = await MailSendHelper.SendMail(userMail, emailSubject, emailBody, sendTo);
_logger.LogInformation("批次={no} 发送邮件完成 {rlt}", batchNo,JSON.Serialize(sendResult));
//接受之后重新发送放舱
}
result.succ = true;
result.msg = "操作成功";
}
catch (Exception ex)
{
throw Oops.Bah("接收换船异常,{0}", ex.Message);
}
return result;
}
#endregion
#region 取消换船
/// <summary>
/// 取消换船
/// </summary>
/// <param name="taskPKId">任务主键</param>
/// <returns>返回结果</returns>
[HttpGet("/TaskManage/AcceptCancelChangeShip")]
public async Task<TaskManageOrderResultDto> AcceptCancelChangeShip([FromQuery] string taskPKId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
try
{
var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == taskPKId);
if (taskInfo == null)
Oops.Oh($"任务信息获取失败");
_logger.LogInformation("批次={no} ids={ids} 获取任务完成", batchNo, taskPKId);
if (taskInfo.TASK_TYPE != TaskBusiTypeEnum.ABORT_CHANGE_SHIP.ToString())
Oops.Oh($"当前任务类型不是{TaskBusiTypeEnum.ABORT_CHANGE_SHIP.GetDescription()},不能取消换船");
if (string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
Oops.Oh($"任务信息的订舱主键不存在");
if (taskInfo.STATUS != TaskStatusEnum.Create.ToString())
Oops.Oh($"任务状态不是{0},不能【取消换船】", TaskStatusEnum.Create.GetDescription());
var orderInfo = _bookingOrderRepository.AsQueryable()
.First(t => t.Id == long.Parse(taskInfo.BOOK_ORDER_NO));
if (orderInfo == null)
Oops.Oh($"订舱信息获取失败");
_logger.LogInformation("批次={no} 订舱主键{id}获取订舱完成", batchNo, taskInfo.BOOK_ORDER_NO);
var userMail = _djyUserMailAccountRepository.AsQueryable().First(x => x.CreatedUserId == orderInfo.CreatedUserId);
if (userMail == null || string.IsNullOrWhiteSpace(userMail.SmtpServer) || userMail.SmtpPort == 0)
{
Oops.Oh($"发件邮箱未配置,或者配置不完整");
}
if (!string.IsNullOrWhiteSpace(taskInfo.RESULT_NOTE))
Oops.Oh($"获取换船任务详情失败");
_logger.LogInformation("批次={no} 获取换船任务详情,{note}", batchNo, taskInfo.RESULT_NOTE);
var jsonObj = JSON.Deserialize<dynamic>(taskInfo.RESULT_NOTE);
//获取任务历史
var lastChangShipTask = await _taskBaseInfoRepository.AsQueryable().Where(t=>t.BOOK_ORDER_NO == taskInfo.BOOK_ORDER_NO && t.TASK_TYPE == TaskBusiTypeEnum.CHANGE_SHIP.ToString())
.OrderByDescending(t=>t.CreatedTime).FirstAsync();
if(lastChangShipTask != null)
{
if (lastChangShipTask.STATUS == TaskStatusEnum.Create.ToString()) //原换船通知未作处理
{
throw Oops.Bah("本票货存在未处理换船通知,请先结束原换船任务然后结束本任务。");
}
if (lastChangShipTask.STATUS == TaskStatusEnum.Cancel.ToString()) //原换船任务为结束任务
{
throw Oops.Bah("未做换船,请点击结束任务。");
}
if (lastChangShipTask.STATUS == TaskStatusEnum.Complete.ToString()) //原换船通知已经接受
{
//查询换船历史,恢复换船
var lastChangeShip = await _taskChangeShipHisInfoRepository.AsQueryable().Where(t => t.BOOK_ORDER_NO == orderInfo.Id.ToString())
.OrderByDescending(t => t.CreatedTime).FirstAsync();
if (lastChangeShip == null)
throw Oops.Bah("查询换船历史失败");
//更新任务状态
orderInfo = _bookingOrderRepository.AsQueryable().First(t => t.Id == orderInfo.Id);
orderInfo.VESSEL = lastChangeShip.VESSEL_SRC;
orderInfo.VOYNO = lastChangeShip.VOYNO_SRC;
orderInfo.SHIPAGENCY = lastChangeShip.SHIP_AGENCY_SRC;
_logger.LogInformation($"{orderInfo.MBLNO}接受取消换船,从{orderInfo.VESSEL}/{orderInfo.VOYNO} 到 {jsonObj.vessel.ToString()}/{jsonObj.voyno.ToString()}");
orderInfo.CreatedTime = DateTime.Now;
orderInfo.CreatedUserId = UserManager.UserId;
orderInfo.CreatedUserName = UserManager.Name;
//更新订舱详情
await _bookingOrderRepository.AsUpdateable(orderInfo).UpdateColumns(it => new
{
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName,
it.VESSEL,
it.VOYNO
}).ExecuteCommandAsync();
_logger.LogInformation("批次={no} 更新订舱完成", batchNo);
taskInfo.STATUS = TaskStatusEnum.Complete.ToString();
taskInfo.STATUS_NAME = TaskStatusEnum.Complete.GetDescription();
taskInfo.COMPLETE_DATE = DateTime.Now;
taskInfo.COMPLETE_DEAL = TaskCompleteDealEnum.MANUAL.ToString();
taskInfo.COMPLETE_DEAL_NAME = TaskCompleteDealEnum.MANUAL.GetDescription();
taskInfo.UpdatedTime = DateTime.Now;
taskInfo.UpdatedUserId = UserManager.UserId;
taskInfo.UpdatedUserName = UserManager.Name;
//更新任务表
await _taskBaseInfoRepository.AsUpdateable(taskInfo).UpdateColumns(it => new
{
it.STATUS,
it.STATUS_NAME,
it.COMPLETE_DATE,
it.COMPLETE_DEAL,
it.COMPLETE_DEAL_NAME,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync();
_logger.LogInformation("批次={no} 更新任务完成", batchNo);
//提取订舱相关联系的邮箱信息
var bookContactEmailList = _bookingOrderContactRepository.AsQueryable().Where(t => t.BookingId == orderInfo.Id && !string.IsNullOrWhiteSpace(t.Email))
.Select(t => t.Email).Distinct().ToList();
if (bookContactEmailList.Count > 0)
{
string sendTo = string.Join(";", bookContactEmailList.ToArray());
string emailSubject = $"取消换船通知-{orderInfo.MBLNO}";
string emailBody = $"取消换船通知-{orderInfo.MBLNO}\", $\"提单号为{orderInfo.MBLNO}的订舱已取消换船<br/>";
var sendResult = await MailSendHelper.SendMail(userMail, emailSubject, emailBody, sendTo);
_logger.LogInformation("批次={no} 发送邮件完成 {rlt}", batchNo, JSON.Serialize(sendResult));
//接受之后重新发送放舱
}
}
}
result.succ = true;
result.msg = "操作成功";
}
catch (Exception ex)
{
throw Oops.Bah("取消换船异常,{0}", ex.Message);
}
return result;
}
#endregion
#region 转发电放邮件
/// <summary>
/// 转发电放邮件
/// </summary>
/// <param name="taskPKId">任务主键</param>
/// <param name="toMail">指定邮件地址</param>
/// <returns>返回结果</returns>
[HttpGet("/TaskManage/SendTelexEmail")]
public async Task<TaskManageOrderResultDto> SendTelexEmail([FromQuery] string taskPKId, [FromQuery] string toMail)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == taskPKId);
if (taskInfo == null)
Oops.Oh($"任务信息获取失败");
if (taskInfo.TASK_TYPE != TaskBusiTypeEnum.TELEX_NOTICE.ToString() || taskInfo.TASK_TYPE != TaskBusiTypeEnum.SEAWAYBILL_DOWN.ToString())
Oops.Oh($"当前任务类型不是{TaskBusiTypeEnum.TELEX_NOTICE.GetDescription()}、{TaskBusiTypeEnum.SEAWAYBILL_DOWN.GetDescription()},不能转发邮件");
if (string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
Oops.Oh($"任务信息的订舱主键不存在");
var orderInfo = _bookingOrderRepository.AsQueryable()
.First(t => t.Id == long.Parse(taskInfo.BOOK_ORDER_NO));
if (orderInfo == null)
Oops.Oh($"订舱信息获取失败");
var userMail = _djyUserMailAccountRepository.AsQueryable().First(x => x.CreatedUserId == orderInfo.CreatedUserId);
if (userMail == null || string.IsNullOrWhiteSpace(userMail.SmtpServer) || userMail.SmtpPort == 0)
{
Oops.Oh($"发件邮箱未配置,或者配置不完整");
}
string emailSubject = string.Empty;
string emailBody = string.Empty;
var sendResult = await MailSendHelper.SendMail(userMail, emailSubject, emailBody, toMail);
if (!sendResult.Key)
{
Oops.Oh(sendResult.Value);
}
}
catch(Exception ex)
{
throw Oops.Bah("获取发送下货纸异常,{0}", ex.Message);
}
return result;
}
#endregion
#region 发送下货纸
/// <summary>
/// 发送下货纸
/// </summary>
/// <param name="taskPKId">任务主键</param>
/// <param name="fileRole">文件功能 (9原始)</param>
/// <returns>返回结果</returns>
[HttpGet("/TaskManage/SendShippingOrder")]
public async Task<TaskManageOrderResultDto> SendShippingOrder([FromQuery] string taskPKId, [FromQuery] string fileRole = "9")
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
/*
1、查询任务关联的订舱信息。
2、触发下货纸发送。
3、发送成功更新任务状态为成功。
4、查看用户公司是否配置了反馈地址如果有配置则触发反馈推送否则显示反馈失败提示。
5、触发扣费
*/
try
{
var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == taskPKId);
if (taskInfo == null)
Oops.Oh($"任务信息获取失败");
if(taskInfo.TASK_TYPE != TaskBusiTypeEnum.SHIPPING_ORDER.ToString())
Oops.Oh($"当前任务类型不是{TaskBusiTypeEnum.SHIPPING_ORDER.GetDescription()},不能发送下货纸");
if (string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
Oops.Oh($"任务信息的订舱主键不存在");
var orderInfo = _bookingOrderRepository.AsQueryable()
.First(t => t.Id == long.Parse(taskInfo.BOOK_ORDER_NO));
if (orderInfo == null)
Oops.Oh($"订舱信息获取失败");
//推送下货纸业务
var rtn = await XiahuozhiHelpler.Send(orderInfo.Id, fileRole);
if (!rtn.Key)
{
throw Oops.Bah($"发送失败:{rtn.Value}");
}
//订舱状态写入
await SaveBookingStatus(orderInfo.Id, "sta_xhz", "下货纸");
taskInfo.STATUS = TaskStatusEnum.Complete.ToString();
taskInfo.STATUS_NAME = TaskStatusEnum.Complete.GetDescription();
taskInfo.COMPLETE_DATE = DateTime.Now;
taskInfo.COMPLETE_DEAL = TaskCompleteDealEnum.MANUAL.ToString();
taskInfo.COMPLETE_DEAL_NAME = TaskCompleteDealEnum.MANUAL.GetDescription();
taskInfo.UpdatedTime = DateTime.Now;
taskInfo.UpdatedUserId = UserManager.UserId;
taskInfo.UpdatedUserName = UserManager.Name;
//更新任务表
await _taskBaseInfoRepository.AsUpdateable(taskInfo).UpdateColumns(it => new
{
it.STATUS,
it.STATUS_NAME,
it.COMPLETE_DATE,
it.COMPLETE_DEAL,
it.COMPLETE_DEAL_NAME,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync();
await InnerChargeFeeShippingOrder(taskInfo);
//反馈用户(这里预留,主要考虑是否通过用户配置确定是否需要推送回执)
await FeedbackXiaHuoZhi("");
}
catch(Exception ex)
{
throw Oops.Bah("发送下货纸异常,{0}", ex.Message);
}
return result;
}
#endregion
#region 更新订舱的状态
/// <summary>
/// 更新订舱的状态
/// </summary>
/// <param name="bookingId">订舱主键</param>
/// <param name="code">状态代码</param>
/// <param name="name">状态名称</param>
/// <returns></returns>
private async Task SaveBookingStatus(long bookingId, string code, string name)
{
var bookSta = _bookingStatusRepository.FirstOrDefault(x => x.BookingId == bookingId && x.StaCode == code);
if (bookSta == null)
{
//记录状态
bookSta = new BookingStatus();
bookSta.BookingId = bookingId;
bookSta.StaCode = code;
bookSta.StaName = name;
bookSta.StaTime = DateTime.Now;
await _bookingStatusRepository.InsertAsync(bookSta);
}
else
{
bookSta.StaTime = DateTime.Now;
await _bookingStatusRepository.UpdateAsync(bookSta);
}
}
#endregion
#region 扣费
/// <summary>
/// 扣费
/// </summary>
/// <param name="taskBaseInfo">任务信息</param>
/// <param name="isCharge">是否执行扣费 true-执行扣费 false-不执行扣费(主要是符合扣费条件但是由于超时没有得到准确回执)</param>
/// <returns>返回回执</returns>
private async Task<TaskManageOrderResultDto> InnerChargeFeeShippingOrder(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 获取订舱详情
/// <summary>
/// 获取订舱详情
/// </summary>
/// <param name="taskPKId">任务主键</param>
/// <returns>返回结果</returns>
[HttpGet("/TaskManage/GetBookingOrderInfo")]
public async Task<TaskBookingOrderDto> GetBookingOrderInfo([FromQuery]string taskPKId)
{
TaskBookingOrderDto model = new TaskBookingOrderDto();
string batchNo = IDGen.NextID().ToString();
try
{
var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == taskPKId);
if (taskInfo == null)
Oops.Oh($"任务信息获取失败");
var orderInfo = _bookingOrderRepository.AsQueryable()
.First(t => t.Id == long.Parse(taskInfo.BOOK_ORDER_NO));
if(orderInfo != null)
{
//订舱
model = orderInfo.Adapt<TaskBookingOrderDto>();
var contaList = await _bookingOrderContaRepository.AsQueryable().Where(x => x.BILLID == orderInfo.Id).ToListAsync();
//获取集装箱的主键
var ctnArg = contaList.Select(t => t.Id).ToArray();
//查询集装箱所有的货物信息
var cargoList = await _bookingOrderContaCargoRepository.AsQueryable()
.Where(x => ctnArg.Contains(x.CTNID.Value)).ToListAsync();
_logger.LogInformation("批次={no} 提取货物明细完成 数量={total}", batchNo, cargoList.Count);
if (cargoList.Count > 0)
{
model.ContaList = contaList.GroupJoin(cargoList, l => l.Id, r => r.CTNID, (l, r) => {
var currList = r.ToList();
if (currList.Count > 0)
{
var info = l.Adapt<TaskBookingOrderContaDto>();
info.CargoList = currList.Adapt<List<TaskBookingOrderCargoDto>>();
return info;
}
return l.Adapt<TaskBookingOrderContaDto>();
}).ToList();
}
else
{
model.ContaList = contaList.Adapt<List<TaskBookingOrderContaDto>>();
}
//任务
model.TaskBaseInfo = taskInfo.Adapt<TaskBaseInfoDto>();
}
}
catch (Exception ex)
{
throw Oops.Bah("获取订舱详情异常,{0}", ex.Message);
}
return model;
}
#endregion
#region 下货纸反馈
/// <summary>
/// 下货纸反馈
/// </summary>
/// <param name="bsno"></param>
/// <returns></returns>
private async Task FeedbackXiaHuoZhi(string bsno)
{
/*
var para = commonData.ParamValues.AsNoTracking().FirstOrDefault(x => x.CompId == compid && x.ParaCode == "XHZ_FEEDBACK_URL");
if (para == null || string.IsNullOrEmpty(para.ItemCode))
{
msg = "下货纸反馈地址未配置";
return false;
}
var feedbask = new BackgroundTaskCommon();
feedbask.GID = Guid.NewGuid().ToString();
feedbask.Status = BackgroundTaskCommon.StatusCreate;
feedbask.Type = BackgroundTaskCommon.TypeHttpFeedback;
feedbask.CreateTime = DateTime.Now;
feedbask.ParamData = JsonConvert.SerializeObject(new
{
url = para.ItemCode,
method = "POST",
json = JsonConvert.SerializeObject(new
{
bsno,
status
})
});
commonData.BackgroundTaskCommon.Add(feedbask);
msg = "成功";
return true;
*/
}
#endregion
#region 获取航次账单详情
/// <summary>
/// 获取航次账单详情
/// </summary>
/// <param name="taskPKId">任务主键</param>
/// <returns>返回结果</returns>
[HttpGet("/TaskManage/GetInvoiceBillInfo")]
public async Task<TaskInvoiceBillBaseInfo> GetInvoiceBillInfo([FromQuery] string taskPKId)
{
TaskInvoiceBillBaseInfo model = new TaskInvoiceBillBaseInfo();
string batchNo = IDGen.NextID().ToString();
try
{
var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == taskPKId);
if (taskInfo == null)
Oops.Oh($"任务信息获取失败");
if (string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
Oops.Oh($"任务信息的订舱主键不存在");
if(taskInfo.TASK_TYPE != TaskBusiTypeEnum.INVOICE_BILL_MAIL.ToString())
Oops.Oh($"当前任务类型不是{TaskBusiTypeEnum.INVOICE_BILL_MAIL.GetDescription()}");
var orderInfo = _bookingOrderRepository.AsQueryable()
.First(t => t.Id == long.Parse(taskInfo.BOOK_ORDER_NO));
model.TaskId = taskInfo.PK_ID;
if (orderInfo != null)
{
//订舱
model.BookingOrder = orderInfo.Adapt<TaskBookingOrderDto>();
}
//获取文件
var fileList = _taskFileInfoRepository.AsQueryable().Where(t => t.TASK_PKID == taskInfo.PK_ID).ToList();
model.TaskFile = fileList.Adapt<List<TaskManageOrderFileInfo>>();
var feeList = _taskBillFeeDetailInfoRepository.AsQueryable().Where(t => t.TASK_PKID == taskInfo.PK_ID).ToList();
model.FeeList = feeList.Where(t => t.IS_TOTAL == 0).Select(t=>t.Adapt<TaskInvoiceBillFeeDto>()).ToList();
var totalUSD = feeList.FirstOrDefault(t => t.IS_TOTAL == 1 && t.FEE_NAME == "TotalUSD" && t.CURRENCY == "USD");
model.TotalAmountUSD = totalUSD != null ? totalUSD.TOTAL_AMOUNT : 0;
var totalCNY = feeList.FirstOrDefault(t => t.IS_TOTAL == 1 && t.FEE_NAME == "TotalCNY" && t.CURRENCY == "CNY");
model.TotalAmountCNY = totalCNY != null ? totalCNY.TOTAL_AMOUNT : 0;
model.InvoiceBillSendList = new List<TaskInvoiceBillFileHis>();
}
catch (Exception ex)
{
throw Oops.Bah("获取获取航次账单详情异常,{0}", ex.Message);
}
return model;
}
#endregion
#region 获取单票账单详情
/// <summary>
/// 获取单票账单详情
/// </summary>
/// <param name="taskPKId">任务主键</param>
/// <returns>返回结果</returns>
[HttpGet("/TaskManage/GetTaskPerBillInfo")]
public async Task<TaskPerBillResultInfo> GetTaskPerBillInfo([FromQuery] string taskPKId)
{
TaskPerBillResultInfo model = new TaskPerBillResultInfo();
string batchNo = IDGen.NextID().ToString();
try
{
var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == taskPKId);
if (taskInfo == null)
Oops.Oh($"任务信息获取失败");
if (string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
Oops.Oh($"任务信息的订舱主键不存在");
if (taskInfo.TASK_TYPE != TaskBusiTypeEnum.PER_BILL.ToString())
Oops.Oh($"当前任务类型不是{TaskBusiTypeEnum.PER_BILL.GetDescription()}");
var orderInfo = _bookingOrderRepository.AsQueryable()
.First(t => t.Id == long.Parse(taskInfo.BOOK_ORDER_NO));
model.TaskId = taskInfo.PK_ID;
var perBillInfo = _taskPerBillBaseInfoRepository.AsQueryable().First(t => t.TASK_PKID == taskInfo.PK_ID);
if (perBillInfo == null)
Oops.Oh($"单票账单不存在");
model.TaskPerBillBaseInfoDto = perBillInfo.Adapt<TaskPerBillBaseInfoDto>();
if (orderInfo != null)
{
//订舱
model.BookingOrder = orderInfo.Adapt<TaskBookingOrderDto>();
}
//获取文件
var fileList = _taskFileInfoRepository.AsQueryable().Where(t => t.TASK_PKID == taskInfo.PK_ID).ToList();
model.TaskFile = fileList.Adapt<List<TaskManageOrderFileInfo>>();
var feeList = _taskBillFeeDetailInfoRepository.AsQueryable().Where(t => t.TASK_PKID == taskInfo.PK_ID).ToList();
model.FeeList = feeList.Where(t => t.IS_TOTAL == 0).Select(t => t.Adapt<TaskPerBillFeeDto>()).ToList();
}
catch (Exception ex)
{
throw Oops.Bah("获取获取单票账单详情异常,{0}", ex.Message);
}
return model;
}
#endregion
#region 获取提单纸登记记录
/// <summary>
/// 获取提单纸登记记录
/// </summary>
/// <param name="querySearch">查询条件</param>
/// <returns>返回结果</returns>
[HttpPost("/TaskManage/GetLaraPaperRecordPage")]
public async Task<SqlSugarPagedList<LaraPaperRecordDto>> GetLaraPaperRecordPageAsync(QueryTaskManageBaseDto querySearch)
{
string entityOrderCol = "CreatedTime";
//这里因为返回给前端的台账数据是DTO所以这里排序时候需要转换成Entity对应的字段
if (!string.IsNullOrWhiteSpace(querySearch.SortField))
entityOrderCol = MapsterExtHelper.GetAdaptProperty<LaraPaperRecordDto, TaskLARAPaperInfo>(querySearch.SortField);
var entities = await _taskLARAPaperInfoRepository.AsQueryable()
.OrderBy(entityOrderCol + (querySearch.descSort ? " asc " : " desc "))
.ToPagedListAsync(querySearch.PageNo, pageSize: querySearch.PageSize);
return entities.Adapt<SqlSugarPagedList<LaraPaperRecordDto>>();
}
#endregion
#region 导出LARA提单纸登记记录
/// <summary>
/// 导出LARA提单纸登记记录
/// </summary>
/// <param name="sortField">排序字段</param>
/// <param name="pageNo">当前页码</param>
/// <param name="pageSize">页码容量</param>
/// <param name="descSort">排序方法,默认降序</param>
/// <returns>返回结果</returns>
[HttpGet("/TaskManage/LaraPaperRecordExport")]
public async Task<IActionResult> LaraPaperRecordExport([FromQuery] string sortField,[FromQuery] int pageNo = 1, [FromQuery] int pageSize = 30, [FromQuery] bool descSort = true)
{
QueryTaskManageBaseDto querySearch = new QueryTaskManageBaseDto
{
SortField = sortField,
PageNo = pageNo,
PageSize = pageSize,
descSort = descSort
};
string entityOrderCol = "CreatedTime";
var entities = await _taskLARAPaperInfoRepository.AsQueryable()
.OrderBy(entityOrderCol + (querySearch.descSort ? " asc " : " desc "))
.ToPagedListAsync(querySearch.PageNo, pageSize: querySearch.PageSize);
if(entities.Items.Count() == 0)
{
throw Oops.Oh($"没有可以导出的数据");
}
var list = entities.Items.Adapt<List<LaraPaperRecordDto>>();
//导出Excel文件流
var ms = ExportXlsLaraPaperRecord(list);
return new FileStreamResult(ms, "application/vnd.ms-excel") { FileDownloadName = $"{DateTime.Now.ToString("yyyyMMddHHmmss")}_LaraPaperRecord.xls" };
}
#endregion
#region 导出提单纸登记记录生成Excel
/// <summary>
/// 导出提单纸登记记录生成Excel
/// </summary>
/// <param name="list">LARA提单纸登记记录列表</param>
/// <returns>返回Excel文件流</returns>
private MemoryStream ExportXlsLaraPaperRecord(List<LaraPaperRecordDto> list)
{
MemoryStream ms = new MemoryStream();
try
{
IWorkbook workbook = new HSSFWorkbook();
ISheet sheet = workbook.CreateSheet();
IRow headerRow = sheet.CreateRow(0);
var headers = new string[] { "打印日期", "提单号", "Paper Number From", "Paper Number To", "Sum", "签单方式", "LARA登记时间", "LARA登记人" };
for (int i = 0; i < headers.Length; i++)
{
string head = headers[i];
var headCell = headerRow.CreateCell(i);
headCell.SetCellValue(head);
}
int rowIndex = 1;
foreach (var item in list)
{
IRow dataRow = sheet.CreateRow(rowIndex);
var cell0 = dataRow.CreateCell(0);
cell0.SetCellValue(item.OriginalDownTime);
var cell1 = dataRow.CreateCell(1);
cell1.SetCellValue(item.MBLNo);
var cell2 = dataRow.CreateCell(2);
cell2.SetCellValue(item.NumberFrom);
var cell3 = dataRow.CreateCell(3);
cell3.SetCellValue(item.NumberTo);
var cell4 = dataRow.CreateCell(4);
cell4.SetCellValue(item.PageSum);
var cell5 = dataRow.CreateCell(5);
cell5.SetCellValue(item.IssueTypeName);
var cell6 = dataRow.CreateCell(6);
cell6.SetCellValue(item.CreatedTime);
var cell7 = dataRow.CreateCell(7);
cell7.SetCellValue(item.CreatedUserName);
rowIndex++;
}
workbook.Write(ms, true);
ms.Flush();
ms.Position = 0;
}
catch (Exception ex)
{
throw Oops.Bah("导出提单纸登记记录生成Excel异常,{0}", ex.Message);
}
return ms;
}
#endregion
#region 保存SI信息
/// <summary>
/// 保存SI信息
/// </summary>
/// <param name="model">订舱信息</param>
/// <returns>返回结果</returns>
[HttpPost("/TaskManage/SaveBookingSI")]
public async Task<TaskManageOrderResultDto> SaveBookingSI(TaskBookingOrderDto model)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
/*
1、比较原始数据和修改数据内容记录差异。
2、更新订舱主信息和集装箱信息。
3、写入本地历史记录表。
*/
try
{
if (string.IsNullOrWhiteSpace(model.TaskBaseInfo.PKId))
throw Oops.Oh($"任务主键TaskBaseInfo.PKId不能为空");
var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == model.TaskBaseInfo.PKId);
if (taskInfo == null)
throw Oops.Oh($"任务信息获取失败");
if (string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
throw Oops.Oh($"任务信息的订舱主键不存在");
if (taskInfo.TASK_TYPE != TaskBusiTypeEnum.SI_FEEDBACK.ToString())
throw Oops.Oh($"当前任务类型不是{TaskBusiTypeEnum.SI_FEEDBACK.GetDescription()}");
//取订舱详情(包含集装箱)
var bookOrderList = _bookingOrderRepository.EntityContext.Queryable<BookingOrder>()
.LeftJoin(_bookingOrderRepository.EntityContext.Queryable<BookingCtn>(),(bk, ctn) => bk.Id == ctn.BILLID)
.Where((bk, ctn) => bk.Id == long.Parse(taskInfo.BOOK_ORDER_NO) && bk.TenantId == UserManager.TENANT_ID)
.Select((bk, ctn) => new { bk = bk, ctn = ctn }).ToList();
var orderInfo = bookOrderList.FirstOrDefault().bk;
List<BookingCtn> orderCtnList = new List<BookingCtn>();
//这里是左连接查询,解决集装箱为空的情况
if(bookOrderList.Any(t=>t.ctn.Id > 0))
orderCtnList = bookOrderList.Select(t => t.ctn).ToList();
var mdBookingOrder = model.Adapt<BookingOrder>();
mdBookingOrder.Id = orderInfo.Id;
mdBookingOrder.UpdatedTime = DateTime.Now;
mdBookingOrder.UpdatedUserId = UserManager.UserId;
mdBookingOrder.UpdatedUserName = UserManager.Name;
//比对主订舱信息
var orderDiff = InnerCompare(orderInfo, mdBookingOrder);
//比对箱信息
var contaList = model.ContaList.Select(x => x.Adapt<BookingCtn>()).ToList();
/**/
//这里参考原有的更新逻辑只更新了SI回执有的字段信息其他字段不更新如果后期有调整可以自行增加更新字段
await _bookingOrderRepository.AsUpdateable(mdBookingOrder).UpdateColumns(it => new
{
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName,
it.SHIPPER,
it.CONSIGNEE,
it.NOTIFYPARTY,
it.MARKS,
it.DESCRIPTION,
it.BLFRT,
it.SERVICE,
it.ISSUETYPE,
it.PORTLOADID,
it.PORTLOAD,
it.PORTDISCHARGEID,
it.PORTDISCHARGE,
it.TRANSPORTID,
it.TRANSPORT,
it.DESTINATIONID,
it.DESTINATION,
it.PKGS,
it.KINDPKGS,
it.KGS,
it.CBM,
it.THIRDPAYADDR,
it.SIREMARK
}).ExecuteCommandAsync();
var ctnlist = await _bookingOrderContaRepository.AsQueryable().Where(x => x.BILLID == mdBookingOrder.Id).ToListAsync();
var si2orderCtnList = contaList.GroupJoin(ctnlist, l => l.CNTRNO?.Trim(), r => r.CNTRNO?.Trim(), (l, r) => {
var currInfo = r.FirstOrDefault();
if(currInfo == null)
{
l.BILLID = orderInfo.Id;
l.CreatedTime = DateTime.Now;
l.CreatedUserId = UserManager.UserId;
l.CreatedUserName = UserManager.Name;
l.UpdatedTime = l.CreatedTime;
l.UpdatedUserId = UserManager.UserId;
l.UpdatedUserName = UserManager.Name;
return new { OperType = "insert", obj = l };
}
else
{
currInfo.Id = l.Id;
currInfo.BILLID = l.BILLID;
currInfo.UpdatedTime = DateTime.Now;
currInfo.UpdatedUserId = UserManager.UserId;
currInfo.UpdatedUserName = UserManager.Name;
return new { OperType = "update", obj = currInfo };
}
}).ToList();
var delList = ctnlist.GroupJoin(contaList, l => l.CNTRNO?.Trim(), r => r.CNTRNO?.Trim(), (l, r) => {
var currInfo = r.FirstOrDefault();
if (currInfo == null)
{
l.UpdatedTime = DateTime.Now;
l.UpdatedUserId = UserManager.UserId;
l.UpdatedUserName = UserManager.Name;
return new { OperType = "delete", obj = l };
}
return new { OperType = string.Empty, obj = l };
}).Where(t=>t.OperType != string.Empty).ToList();
if (delList.Count > 0)
si2orderCtnList.AddRange(delList);
if (si2orderCtnList.Count > 0)
{
si2orderCtnList.ForEach(async ctn =>
{
if (ctn.OperType == "insert")
{
//插入
await _bookingOrderContaRepository.InsertAsync(ctn.obj);
}
else if (ctn.OperType == "update")
{
//更新
await _bookingOrderContaRepository.AsUpdateable(ctn.obj).UpdateColumns(it => new
{
it.CTNALL,
it.SEALNO,
it.PKGS,
it.KGS,
it.CBM,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName,
}).ExecuteCommandAsync();
}
else if (ctn.OperType == "delete")
{
await _bookingOrderContaRepository.DeleteAsync(x => x.Id == ctn.obj.Id);
}
});
}
result.succ = true;
result.msg = "保存SI信息成功";
}
catch(Exception ex)
{
throw Oops.Bah("保存SI信息异常,{0}", ex.Message);
}
return result;
}
#endregion
#region 获取SI反馈信息
/// <summary>
/// 获取SI反馈信息
/// </summary>
/// <param name="taskPKId">任务主键</param>
/// <returns>返回结果</returns>
[HttpGet("/TaskManage/GetSIFeedBackInfo")]
public async Task<TaskSIFeedBackResultDto> GetSIFeedBackInfo(string taskPKId)
{
TaskSIFeedBackResultDto model = new TaskSIFeedBackResultDto();
try
{
var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == taskPKId);
if (taskInfo == null)
throw Oops.Oh($"任务信息获取失败");
if (string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
throw Oops.Oh($"任务信息的订舱主键不存在");
if (taskInfo.TASK_TYPE != TaskBusiTypeEnum.SI_FEEDBACK.ToString())
throw Oops.Oh($"当前任务类型不是{TaskBusiTypeEnum.SI_FEEDBACK.GetDescription()}");
var bookOrderList = _bookingOrderRepository.EntityContext.Queryable<BookingOrder>()
.InnerJoin<BookingCtn>((bk, ctn) => bk.Id == ctn.BILLID)
.Where((bk, ctn) => bk.Id == long.Parse(taskInfo.BOOK_ORDER_NO) && bk.TenantId == UserManager.TENANT_ID)
.Select((bk, ctn) => new { bk = bk, ctn = ctn }).ToList();
var orderInfo = bookOrderList.FirstOrDefault().bk;
model.TaskId = taskInfo.PK_ID;
var siFeedBackList = _taskSISubmittedRepository.EntityContext.Queryable<TaskSIFeedBackInfo>()
.InnerJoin<TaskSIFeedBackContaInfo>((si, ctn) => si.PK_ID == ctn.P_PKID)
.Where((si, ctn) => si.TASK_PKID == model.TaskId && si.TenantId == UserManager.TENANT_ID)
.Select((si, ctn) => new { si = si, ctn = ctn }).ToList();
if (siFeedBackList.Count == 0)
throw Oops.Oh($"SI反馈信息不存在");
var siFeedBackInfo = siFeedBackList.FirstOrDefault().si;
var resultInfo = siFeedBackInfo.Adapt<TaskSIFeedBackResultBusiDto>();
resultInfo.ContaList = siFeedBackList.Select(t => t.ctn.Adapt<TaskSIFeedBackResultContaDto>()).ToList();
model.BusiInfo = resultInfo;
if (orderInfo != null)
{
//订舱
model.BookingOrder = orderInfo.Adapt<TaskBookingOrderDto>();
}
//进行数据比对确认差异字段KEY
var mainDiff = await InnerCompareMainInfoDiff(orderInfo, siFeedBackInfo);
model.SICompareOrderKeyList = mainDiff;
var contaDiff = await InnerCompareContaInfoDiff(bookOrderList.Select(t=>t.ctn).ToList(),
siFeedBackList.Select(t=>t.ctn).ToList());
model.SICompareOrderContaKeyList = contaDiff;
}
catch (Exception ex)
{
throw Oops.Bah("获取获取单票账单详情异常,{0}", ex.Message);
}
return model;
}
#endregion
private List<TaskCompareResultDto> InnerCompare(object srcModel,object targetModel)
{
List<TaskCompareResultDto> list = new List<TaskCompareResultDto>();
if(srcModel is BookingOrder)
{
var srcBK = (BookingOrder)srcModel;
var targetBK = (BookingOrder)targetModel;
var bookProps = typeof(BookingOrder).GetProperties();
list = bookProps.Select(prop =>
{
var bk1Val = prop.GetValue(srcBK);
var bk2Val = prop.GetValue(targetBK);
if (prop.PropertyType == typeof(string))
{
string st1 = (bk1Val as string).AdjustString();
string st2 = (bk2Val as string).AdjustString();
if (st1 != st2)
{
return new TaskCompareResultDto { Code = prop.Name, SrcVal = bk1Val, TargetVal = bk2Val, IsDiff = true, ValType = prop.PropertyType };
}
return new TaskCompareResultDto { Code = prop.Name, SrcVal = bk1Val, TargetVal = bk2Val, IsDiff = false, ValType = prop.PropertyType };
}
else if (prop.PropertyType == typeof(int?))
{
var dt1 = bk1Val as int?;
var dt2 = bk2Val as int?;
if (dt1 != dt2)
{
return new TaskCompareResultDto { Code = prop.Name, SrcVal = bk1Val, TargetVal = bk2Val, IsDiff = true, ValType = prop.PropertyType };
}
return new TaskCompareResultDto { Code = prop.Name, SrcVal = bk1Val, TargetVal = bk2Val, IsDiff = true, ValType = prop.PropertyType };
}
else if (prop.PropertyType == typeof(decimal?))
{
var dt1 = bk1Val as decimal?;
var dt2 = bk2Val as decimal?;
if (dt1 != dt2)
{
return new TaskCompareResultDto { Code = prop.Name, SrcVal = bk1Val, TargetVal = bk2Val, IsDiff = true, ValType = prop.PropertyType };
}
return new TaskCompareResultDto { Code = prop.Name, SrcVal = bk1Val, TargetVal = bk2Val, IsDiff = true, ValType = prop.PropertyType };
}
if (bk1Val != bk2Val)
return new TaskCompareResultDto { Code = prop.Name, SrcVal = bk1Val, TargetVal = bk2Val, IsDiff = true, ValType = prop.PropertyType };
return new TaskCompareResultDto { Code = prop.Name, SrcVal = bk1Val, TargetVal = bk2Val, IsDiff = false, ValType = prop.PropertyType };
}).ToList();
}
return list;
}
#region 比较主信息
/// <summary>
/// 比较主信息
/// </summary>
/// <param name="bookingOrder">订舱详情</param>
/// <param name="taskSIFeedBackInfo">SI反馈详情</param>
/// <returns>返回差异</returns>
private async Task<List<string>> InnerCompareMainInfoDiff(BookingOrder bookingOrder, TaskSIFeedBackInfo taskSIFeedBackInfo)
{
List<string> resultList = new List<string>();
//需要比对的字段
var compareField = new string[] { "SHIPPER", "CONSIGNEE", "NOTIFYPARTY", "MARKS", "DESCRIPTION", "BLFRT", "SERVICE", "ISSUETYPE", "PORTLOAD", "PORTDISCHARGE",
"TRANSPORT", "DESTINATION", "PKGS", "KGS", "CBM", "KINDPKGS", "THIRDPAYADDR" };
var bookProps = typeof(BookingOrder).GetProperties();
var feedProps = typeof(TaskSIFeedBackInfo).GetProperties();
resultList = bookProps.GroupJoin(feedProps, l => l.Name.ToUpper(),
r => r.Name.ToUpper(), (l, r) =>
{
if (compareField.Any(x => x.Equals(l.Name, StringComparison.OrdinalIgnoreCase)))
{
var currList = r.ToList();
if (currList.Count > 0)
{
var si = r.FirstOrDefault();
var bkVal = l.GetValue(bookingOrder);
var siVal = si.GetValue(taskSIFeedBackInfo);
if (l.PropertyType == typeof(string))
{
string st1 = (bkVal as string).AdjustString();
string st2 = (siVal as string).AdjustString();
if (!st1.Equals(st2))
{
return l.Name.ToUpper();
}
return string.Empty;
}
else if (l.PropertyType == typeof(int?))
{
var dt1 = bkVal as int?;
var dt2 = siVal as int?;
if (!dt1.Equals(dt2))
{
return l.Name.ToUpper();
}
return string.Empty;
}
else if (l.PropertyType == typeof(decimal?))
{
var dt1 = bkVal as decimal?;
var dt2 = siVal as decimal?;
if (!dt1.Equals(dt2))
{
return l.Name.ToUpper();
}
return string.Empty;
}
}
return string.Empty;
}
return string.Empty;
}).Where(t => !string.IsNullOrWhiteSpace(t)).ToList();
return resultList;
}
#endregion
#region 比较箱信息
/// <summary>
/// 比较箱信息
/// </summary>
/// <param name="bookContaList">订舱箱信息</param>
/// <param name="siContaList">SI反馈箱信息</param>
/// <returns>返回差异</returns>
private async Task<List<string>> InnerCompareContaInfoDiff(List<BookingCtn> bookContaList,List<TaskSIFeedBackContaInfo> siContaList)
{
List<string> resultList = new List<string>();
var bookProps = typeof(BookingCtn).GetProperties();
var feedProps = typeof(TaskSIFeedBackContaInfo).GetProperties();
resultList = siContaList.GroupJoin(bookContaList, l => l.CONTA_NO, r => r.CNTRNO, (l, r) =>
{
var currList = r.ToList();
if (currList.Count > 0)
{
var bkCtn = currList.FirstOrDefault();
if (!l.KGS.Equals(bkCtn.KGS)
|| !l.PKGS.Equals(bkCtn.PKGS)
|| !l.SEAL_NO.Equals(bkCtn.SEALNO)
|| !l.CONTA_TYPE.Equals(bkCtn.CTNALL)
|| !l.CBM.Equals(bkCtn.CBM))
{
return l.CONTA_NO;
}
return String.Empty;
}
return l.CONTA_NO;
}).Where(t => !string.IsNullOrWhiteSpace(t)).ToList();
return resultList;
}
#endregion
#region 获取VGM比较结果
/// <summary>
/// 获取VGM比较结果
/// </summary>
/// <param name="taskPKId">任务主键</param>
/// <returns>返回结果</returns>
[HttpGet("/TaskManage/GetVGMCompareResult")]
public async Task<TaskVgmCompareResultDto> GetVGMCompareResult(string taskPKId)
{
TaskVgmCompareResultDto model = new TaskVgmCompareResultDto();
List<TaskVgmCompareDto> list = new List<TaskVgmCompareDto>();
List<TaskVgmCompareDto> list2 = new List<TaskVgmCompareDto>();
try
{
var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == taskPKId);
if (taskInfo == null)
throw Oops.Oh($"任务信息获取失败");
if (string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
throw Oops.Oh($"任务信息的订舱主键不存在");
if (taskInfo.TASK_TYPE != TaskBusiTypeEnum.VGM_COMPARE.ToString())
throw Oops.Oh($"当前任务类型不是{TaskBusiTypeEnum.VGM_COMPARE.GetDescription()}");
/*
var vgmList = _taskVGMFeedBackInfoRepository.AsQueryable().Where(t => t.TASK_PKID == taskInfo.PK_ID)
.ToList();
if(vgmList.Count == 0)
throw Oops.Oh($"VGM反馈信息不存在");
var contaList = _bookingOrderContaRepository.AsQueryable().Where(t => t.BILLID == long.Parse(taskInfo.BOOK_ORDER_NO)).ToList();
list = contaList.GroupJoin(vgmList, l => l.CNTRNO?.Trim(), r => r.CONTA_NO?.Trim(), (l, r) => {
var currInfo = r.FirstOrDefault();
TaskVgmCompareDto md = l.Adapt<TaskVgmCompareDto>();
md.compareDiffList = new List<string>();
if (currInfo != null)
{
if(l.SEALNO != currInfo.SEAL_NO)
{
md.compareDiffList.Add(nameof(TaskVgmCompareDto.SealNo));
}
if (l.CTNCODE != currInfo.CONTA_TYPE)
{
md.compareDiffList.Add(nameof(TaskVgmCompareDto.ContaType));
}
if (l.CTNALL != currInfo.CONTA_TYPE_NAME)
{
md.compareDiffList.Add(nameof(TaskVgmCompareDto.ContaTypeName));
}
if (l.KGS != currInfo.KGS)
{
md.compareDiffList.Add(nameof(TaskVgmCompareDto.KGS));
}
if (l.TAREWEIGHT != currInfo.TAREWEIGHT)
{
md.compareDiffList.Add(nameof(TaskVgmCompareDto.TareWeight));
}
if (l.WEIGHKGS != currInfo.WEIGHKGS)
{
md.compareDiffList.Add(nameof(TaskVgmCompareDto.WeighKGs));
}
if (l.WEIGHTYPE != currInfo.WEIGHTYPE)
{
md.compareDiffList.Add(nameof(TaskVgmCompareDto.WeighType));
}
}
else
{
md.compareDiffList = new List<string> { nameof(TaskVgmCompareDto.ContaNo),
nameof(TaskVgmCompareDto.SealNo),
nameof(TaskVgmCompareDto.ContaType),
nameof(TaskVgmCompareDto.ContaTypeName),
nameof(TaskVgmCompareDto.KGS),
nameof(TaskVgmCompareDto.TareWeight),
nameof(TaskVgmCompareDto.WeighKGs),
nameof(TaskVgmCompareDto.WeighType),
};
}
return md;
}).ToList();
model.bookOrderCompareList = list;
list2 = vgmList.GroupJoin(contaList, l => l.CONTA_NO?.Trim(), r => r.CNTRNO?.Trim(), (l, r) => {
var currInfo = r.FirstOrDefault();
TaskVgmCompareDto md = l.Adapt<TaskVgmCompareDto>();
md.compareDiffList = new List<string>();
if (currInfo != null)
{
if (l.SEAL_NO != currInfo.SEALNO)
{
md.compareDiffList.Add(nameof(TaskVgmCompareDto.SealNo));
}
if (l.CONTA_TYPE != currInfo.CTNCODE)
{
md.compareDiffList.Add(nameof(TaskVgmCompareDto.ContaType));
}
if (l.CONTA_TYPE_NAME != currInfo.CTNALL)
{
md.compareDiffList.Add(nameof(TaskVgmCompareDto.ContaTypeName));
}
if (l.KGS != currInfo.KGS)
{
md.compareDiffList.Add(nameof(TaskVgmCompareDto.KGS));
}
if (l.TAREWEIGHT != currInfo.TAREWEIGHT)
{
md.compareDiffList.Add(nameof(TaskVgmCompareDto.TareWeight));
}
if (l.WEIGHKGS != currInfo.WEIGHKGS)
{
md.compareDiffList.Add(nameof(TaskVgmCompareDto.WeighKGs));
}
if (l.WEIGHTYPE != currInfo.WEIGHTYPE)
{
md.compareDiffList.Add(nameof(TaskVgmCompareDto.WeighType));
}
}
else
{
md.compareDiffList = new List<string> { nameof(TaskVgmCompareDto.ContaNo),
nameof(TaskVgmCompareDto.SealNo),
nameof(TaskVgmCompareDto.ContaType),
nameof(TaskVgmCompareDto.ContaTypeName),
nameof(TaskVgmCompareDto.KGS),
nameof(TaskVgmCompareDto.TareWeight),
nameof(TaskVgmCompareDto.WeighKGs),
nameof(TaskVgmCompareDto.WeighType),
};
}
return md;
}).ToList();
model.vgmCompareList = list2;
*/
}
catch (Exception ex)
{
throw Oops.Bah("获取VGM比较结果异常,{0}", ex.Message);
}
return model;
}
#endregion
#region 更新订舱VGM比较更新
/// <summary>
/// 更新订舱VGM比较更新
/// </summary>
/// <param name="taskPKId">任务主键</param>
/// <returns>返回结果</returns>
[HttpPost("/TaskManage/SaveBookingVGM")]
public async Task<TaskManageOrderResultDto> SaveBookingVGM(string taskPKId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == taskPKId);
if (taskInfo == null)
throw Oops.Oh($"任务信息获取失败");
if (string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
throw Oops.Oh($"任务信息的订舱主键不存在");
if (taskInfo.TASK_TYPE != TaskBusiTypeEnum.VGM_COMPARE.ToString())
throw Oops.Oh($"当前任务类型不是{TaskBusiTypeEnum.VGM_COMPARE.GetDescription()}");
//取订舱详情(包含集装箱)
var bookOrderList = _bookingOrderRepository.EntityContext.Queryable<BookingOrder>()
.LeftJoin(_bookingOrderRepository.EntityContext.Queryable<BookingCtn>(), (bk, ctn) => bk.Id == ctn.BILLID)
.Where((bk, ctn) => bk.Id == long.Parse(taskInfo.BOOK_ORDER_NO) && bk.TenantId == UserManager.TENANT_ID)
.Select((bk, ctn) => new { bk = bk, ctn = ctn }).ToList();
var orderInfo = bookOrderList.FirstOrDefault().bk;
List<BookingCtn> orderCtnList = new List<BookingCtn>();
//这里是左连接查询,解决集装箱为空的情况
if (bookOrderList.Any(t => t.ctn.Id > 0))
orderCtnList = bookOrderList.Select(t => t.ctn).ToList();
/*
var contaList = _taskVGMFeedBackInfoRepository.AsQueryable().Where(t => t.TASK_PKID == taskInfo.PK_ID).ToList();
var si2orderCtnList = contaList.GroupJoin(orderCtnList, l => l.CONTA_NO?.Trim(), r => r.CNTRNO?.Trim(), (l, r) => {
var currInfo = r.FirstOrDefault();
var contaInfo = l.Adapt<BookingCtn>();
if (currInfo == null)
{
contaInfo.BILLID = orderInfo.Id;
contaInfo.CreatedTime = DateTime.Now;
contaInfo.CreatedUserId = UserManager.UserId;
contaInfo.CreatedUserName = UserManager.Name;
contaInfo.UpdatedTime = contaInfo.CreatedTime;
contaInfo.UpdatedUserId = UserManager.UserId;
contaInfo.UpdatedUserName = UserManager.Name;
return new { OperType = "insert", obj = contaInfo };
}
else
{
currInfo.Id = contaInfo.Id;
currInfo.BILLID = contaInfo.BILLID;
currInfo.UpdatedTime = DateTime.Now;
currInfo.UpdatedUserId = UserManager.UserId;
currInfo.UpdatedUserName = UserManager.Name;
return new { OperType = "update", obj = currInfo };
}
}).ToList();
var delList = orderCtnList.GroupJoin(contaList, l => l.CNTRNO?.Trim(), r => r.CONTA_NO?.Trim(), (l, r) => {
var currInfo = r.FirstOrDefault();
if (currInfo == null)
{
l.UpdatedTime = DateTime.Now;
l.UpdatedUserId = UserManager.UserId;
l.UpdatedUserName = UserManager.Name;
return new { OperType = "delete", obj = l };
}
return new { OperType = string.Empty, obj = l };
}).Where(t => t.OperType != string.Empty).ToList();
if (delList.Count > 0)
si2orderCtnList.AddRange(delList);
if (si2orderCtnList.Count > 0)
{
si2orderCtnList.ForEach(async ctn =>
{
if (ctn.OperType == "insert")
{
//插入
await _bookingOrderContaRepository.InsertAsync(ctn.obj);
}
else if (ctn.OperType == "update")
{
//更新
await _bookingOrderContaRepository.AsUpdateable(ctn.obj).UpdateColumns(it => new
{
it.CTNALL,
it.SEALNO,
it.PKGS,
it.KGS,
it.CBM,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName,
}).ExecuteCommandAsync();
}
else if (ctn.OperType == "delete")
{
await _bookingOrderContaRepository.DeleteAsync(x => x.Id == ctn.obj.Id);
}
});
}
*/
result.succ = true;
result.msg = "更新订舱成功";
}
catch(Exception ex)
{
throw Oops.Bah("更新订舱VGM比较更新异常,{0}", ex.Message);
}
return result;
}
#endregion
#region 获取换船详情
/// <summary>
/// 获取换船详情
/// </summary>
/// <param name="taskPKId">任务主键</param>
/// <returns>返回结果</returns>
[HttpGet("/TaskManage/GetChangeShipInfo")]
public async Task<TaskChangeShipResultDto> GetChangeShipInfo(string taskPKId)
{
TaskChangeShipResultDto model = new TaskChangeShipResultDto();
try
{
var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == taskPKId);
if (taskInfo == null)
throw Oops.Oh($"任务信息获取失败");
if (string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
throw Oops.Oh($"任务信息的订舱主键不存在");
if (taskInfo.TASK_TYPE != TaskBusiTypeEnum.CHANGE_SHIP.ToString())
throw Oops.Oh($"当前任务类型不是{TaskBusiTypeEnum.CHANGE_SHIP.GetDescription()}");
BookingOrder bookingOrder = null;
if (!string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
bookingOrder = _bookingOrderRepository.AsQueryable().First(t=>t.Id == long.Parse(taskInfo.BOOK_ORDER_NO));
//这里参考源程序,如果任务没有对应订舱数据则通过主单号匹配一条订舱数据
if(bookingOrder == null)
bookingOrder = _bookingOrderRepository.AsQueryable().First(t => t.MBLNO == taskInfo.MBL_NO && !t.ParentId.HasValue);
if (bookingOrder == null)
throw Oops.Oh($"订舱信息获取失败MBLNO={taskInfo.MBL_NO}");
if (string.IsNullOrWhiteSpace(taskInfo.RESULT_NOTE))
throw Oops.Oh($"任务反馈详情不存在");
var rtl = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(taskInfo.RESULT_NOTE);
model.TaskId = taskInfo.PK_ID;
model.TaskStatus = taskInfo.STATUS;
model.TaskStatusName = taskInfo.STATUS_NAME;
model.Vessel = rtl.vessel.ToString();
model.Voyno = rtl.voyno.ToString();
model.ShipAgency = rtl.shipagency == null? rtl.shipagency.ToString():"";
model.MailUrl = rtl.mail_url.ToString();
model.OriginalVessel = bookingOrder.VESSEL;
model.OriginalVoyno = bookingOrder.VOYNO;
model.MBlNo = bookingOrder.MBLNO;
//获得未处理的任务数量
model.TotalTask = await _taskBaseInfoRepository.AsQueryable().Where(t => t.CreatedTime < taskInfo.CreatedTime && t.STATUS == TaskStatusEnum.Create.ToString()
&& (t.TASK_TYPE == TaskBusiTypeEnum.CHANGE_SHIP.ToString() || t.TASK_TYPE == TaskBusiTypeEnum.ABORT_CHANGE_SHIP.ToString())).CountAsync();
}
catch (Exception ex)
{
throw Oops.Bah("获取换船详情异常,{0}", ex.Message);
}
return model;
}
#endregion
#region 获取取消换船详情
/// <summary>
/// 获取取消换船详情
/// </summary>
/// <param name="taskPKId">任务主键</param>
/// <returns>返回结果</returns>
[HttpGet("/TaskManage/GetAbortChangeShipInfo")]
public async Task<TaskChangeShipResultDto> GetAbortChangeShipInfo(string taskPKId)
{
TaskChangeShipResultDto model = new TaskChangeShipResultDto();
try
{
var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == taskPKId);
if (taskInfo == null)
throw Oops.Oh($"任务信息获取失败");
if (string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
throw Oops.Oh($"任务信息的订舱主键不存在");
if (taskInfo.TASK_TYPE != TaskBusiTypeEnum.ABORT_CHANGE_SHIP.ToString())
throw Oops.Oh($"当前任务类型不是{TaskBusiTypeEnum.ABORT_CHANGE_SHIP.GetDescription()}");
BookingOrder bookingOrder = null;
if (!string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
bookingOrder = _bookingOrderRepository.AsQueryable().First(t => t.Id == long.Parse(taskInfo.BOOK_ORDER_NO));
//这里参考源程序,如果任务没有对应订舱数据则通过主单号匹配一条订舱数据
if (bookingOrder == null)
bookingOrder = _bookingOrderRepository.AsQueryable().First(t => t.MBLNO == taskInfo.MBL_NO && !t.ParentId.HasValue);
if (bookingOrder == null)
throw Oops.Oh($"订舱信息获取失败MBLNO={taskInfo.MBL_NO}");
if (string.IsNullOrWhiteSpace(taskInfo.RESULT_NOTE))
throw Oops.Oh($"任务反馈详情不存在");
var rtl = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(taskInfo.RESULT_NOTE);
model.TaskId = taskInfo.PK_ID;
model.TaskStatus = taskInfo.STATUS;
model.TaskStatusName = taskInfo.STATUS_NAME;
model.Vessel = rtl.vessel.ToString();
model.Voyno = rtl.voyno.ToString();
model.ShipAgency = rtl.shipagency == null ? rtl.shipagency.ToString() : "";
model.MailUrl = rtl.mail_url.ToString();
model.OriginalVessel = bookingOrder.VESSEL;
model.OriginalVoyno = bookingOrder.VOYNO;
model.MBlNo = bookingOrder.MBLNO;
//获得未处理的任务数量
model.TotalTask = await _taskBaseInfoRepository.AsQueryable().Where(t => t.CreatedTime < taskInfo.CreatedTime && t.STATUS == TaskStatusEnum.Create.ToString()
&& (t.TASK_TYPE == TaskBusiTypeEnum.CHANGE_SHIP.ToString() || t.TASK_TYPE == TaskBusiTypeEnum.ABORT_CHANGE_SHIP.ToString())).CountAsync();
}
catch (Exception ex)
{
throw Oops.Bah("获取取消换船详情异常,{0}", ex.Message);
}
return model;
}
#endregion
#region 手工批量重新比对BC
/// <summary>
/// 手工批量重新比对BC
/// </summary>
/// <param name="PKIds">任务主键数组</param>
/// <returns>返回结果</returns>
[HttpPost("/TaskManage/ManualReCompareBC")]
public async Task<TaskManageOrderResultDto> ManualReCompareBC(string[] PKIds)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
_logger.LogInformation("批次={no} ids={ids} 手工批量重新比对BC开始", 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 list = new List<TaskManageOrderResultDto>();
taskList.ForEach(async tsk =>
{
var rlt = await InnerSingleManualReCompareBC(tsk);
list.Add(rlt);
});
if (list.Any(t => !t.succ))
{
result.msg = "失败";
result.succ = false;
}
else
{
result.msg = "成功";
result.succ = true;
}
}
catch (Exception ex)
{
throw Oops.Bah("手工批量重新比对BC异常,{0}", ex.Message);
}
return result;
}
#endregion
#region 手工单票重新比对BC
/// <summary>
/// 手工单票重新比对BC
/// </summary>
/// <param name="model">任务详情</param>
/// <returns>返回结果</returns>
private async Task<TaskManageOrderResultDto> InnerSingleManualReCompareBC(TaskBaseInfo model)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
/*
1、通过任务的报文表获取BC的报文。
*/
try
{
var storeInfo = await _taskStoreMsgInfoRepository.AsQueryable()
.Where(t => t.TASK_PKID == model.PK_ID && t.MSG_TYPE == TaskStoreMsgTypeEnum.BC_MSG.ToString()).FirstAsync();
if(storeInfo == null)
throw Oops.Oh("MBL_NO={0},获取{1}报文失败", model.MBL_NO,TaskStoreMsgTypeEnum.BC_MSG.GetDescription());
var rtl = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(storeInfo.MSG_JSON);
string msg = string.Empty;
//2023-02-02 测试过程中发现JSON数据格式有了变化这里增加兼容
if(rtl.mesage != null)
{
msg = JSON.Serialize(rtl.mesage);
}
else
{
msg = storeInfo.MSG_JSON;
}
if (string.IsNullOrWhiteSpace(msg))
throw Oops.Oh("MBL_NO={0},解析{1}报文详情异常", model.MBL_NO, TaskStoreMsgTypeEnum.BC_MSG.GetDescription());
var bookOrderList = _bookingOrderRepository.EntityContext.Queryable<BookingOrder>()
.InnerJoin<BookingCtn>((bk, ctn) => bk.Id == ctn.BILLID)
.Where((bk, ctn) => bk.Id == long.Parse(model.BOOK_ORDER_NO) && bk.TenantId == UserManager.TENANT_ID)
.Select((bk, ctn) => new { bk = bk, ctn = ctn }).ToList();
//获取订舱详情与BC进行比对
var orderInfo = bookOrderList.FirstOrDefault().bk;
List<BookingCtn> ctnList = new List<BookingCtn>();
if (bookOrderList.Any(t => t.ctn != null))
ctnList = bookOrderList.Select(t => t.ctn).ToList();
if (orderInfo == null)
throw Oops.Oh("MBL_NO={0},获取订舱详情失败", model.MBL_NO);
TaskBCStoreResultInfo bcStoreInfo = JSON.Deserialize<TaskBCStoreResultInfo>(msg);
//BC比较
var compareResult = InnerCompareBC(bcStoreInfo,orderInfo, ctnList);
if(!compareResult.succ)
{
//更新任务的反馈结果
model.RESULT_NOTE = compareResult.msg;
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.RESULT_NOTE,
}).ExecuteCommandAsync();
}
else
{
//置任务状态为完成
model.STATUS = TaskStatusEnum.Complete.ToString();
model.STATUS_NAME = TaskStatusEnum.Complete.GetDescription();
model.COMPLETE_DATE = DateTime.Now;
model.COMPLETE_DEAL = TaskCompleteDealEnum.MANUAL.ToString();
model.COMPLETE_DEAL_NAME = TaskCompleteDealEnum.MANUAL.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,
it.COMPLETE_DATE,
it.COMPLETE_DEAL,
it.COMPLETE_DEAL_NAME
}).ExecuteCommandAsync();
//更新订舱的ETD(记个日志)
if (!string.IsNullOrWhiteSpace(bcStoreInfo.ETD))
{
DateTime etd = DateTime.MinValue;
if(DateTime.TryParse(bcStoreInfo.ETD,out etd))
{
orderInfo.ETD = etd;
orderInfo.UpdatedTime = DateTime.Now;
orderInfo.UpdatedUserId = UserManager.UserId;
orderInfo.UpdatedUserName = UserManager.Name;
await _bookingOrderRepository.AsUpdateable(orderInfo).UpdateColumns(it => new
{
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName,
it.ETD
}).ExecuteCommandAsync();
}
}
//【预留】异步推送后台任务(订舱自动放舱-BookingFangCang
//【预留】异步推送后台任务(下货纸-Xiahuozhi
}
result.succ = true;
result.msg = "处理成功";
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"手工重新比对BC异常,{ex.Message}";
//throw Oops.Bah("手工重新比对BC异常,{0}", ex.Message);
}
return result;
}
#endregion
#region 单票比对BC
/// <summary>
/// 单票比对BC
/// </summary>
/// <param name="bcStoreInfo">BC回执详情</param>
/// <param name="orderInfo">订舱详情</param>
/// <param name="ctnList">订舱集装箱列表</param>
/// <returns>返回结果</returns>
private TaskManageOrderResultDto InnerCompareBC(TaskBCStoreResultInfo bcStoreInfo,BookingOrder orderInfo,List<BookingCtn> ctnList)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto { succ = true};
try
{
List<Tuple<bool, string>> rltTupleList = new List<Tuple<bool, string>>();
/*
迁移过来的注释
2021-9-28需求再变BC需要再次比对约号
2021-7-19 需求修改BC不需要再对比约号
*/
//约号
if (!string.IsNullOrWhiteSpace(orderInfo.CONTRACTNO))
{
if ((string.IsNullOrWhiteSpace(bcStoreInfo.BJH) || !Regex.IsMatch(orderInfo.CONTRACTNO, $"\\b{bcStoreInfo.BJH.Trim()}\\b"))
&& (string.IsNullOrWhiteSpace(bcStoreInfo.FWHT) || !Regex.IsMatch(orderInfo.CONTRACTNO, $"\\b{bcStoreInfo.FWHT.Trim()}\\b")))
{
rltTupleList.Add(new Tuple<bool, string>(false, "约号不一致"));
}
}
else
{
if (!string.IsNullOrWhiteSpace(bcStoreInfo.BJH) || !string.IsNullOrWhiteSpace(bcStoreInfo.FWHT))
{
rltTupleList.Add(new Tuple<bool, string>(false, "约号不一致"));
}
}
#region 集装箱
//集装箱
if (bcStoreInfo.CntrTotal != orderInfo.CNTRTOTAL)
{
//集装箱型
var ediCtnList = _cache.GetAllMappingCtn().GetAwaiter().GetResult()
.Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)
&& !string.IsNullOrWhiteSpace(t.CarrierCode) && t.CarrierCode.Equals(orderInfo.CARRIERID, StringComparison.OrdinalIgnoreCase)).ToList();
var storeCtnList = bcStoreInfo.CntrTotal.Split(new char[] { ';' }).Select(t =>
{
var currArg = t.Split(new char[] { 'x' });
return new { Code = currArg[1]?.Trim(), Num = int.Parse(currArg[0]?.Trim()) };
}).GroupBy(t => t.Code)
.Select(t =>
{
return new { Code = t.Key, Num = t.Sum(x => x.Num) };
}).ToList();
var orderCtnListctnList = ctnList.Select(t =>
{
var mapCtn = ediCtnList.FirstOrDefault(x => x.Code.Equals(t.CTNCODE));
if (mapCtn != null && !string.IsNullOrWhiteSpace(mapCtn.MapCode))
return new { Code = mapCtn.MapCode, Num = t.CTNNUM.HasValue ? t.CTNNUM.Value : 1 };
return new { Code = t.CTNCODE, Num = t.CTNNUM.HasValue ? t.CTNNUM.Value : 1 };
}).GroupBy(t => t.Code)
.Select(t =>
{
return new { Code = t.Key, Num = t.Sum(x => x.Num) };
}).ToList();
if (storeCtnList.Count != orderCtnListctnList.Count)
{
rltTupleList.Add(new Tuple<bool, string>(false, "箱型箱量不一致"));
}
else
{
var totalList = storeCtnList.GroupJoin(orderCtnListctnList, l => l.Code, r => r.Code, (l, r) =>
{
var rModel = r.FirstOrDefault();
if (rModel == null)
{
return false;
}
else
{
if (l.Num != rModel.Num)
return false;
}
return true;
}).ToList();
if (totalList.Any(t => !t))
{
rltTupleList.Add(new Tuple<bool, string>(false, "箱型箱量不一致"));
}
}
}
#endregion
//船名
if (bcStoreInfo.Vessel != orderInfo.VESSEL?.Trim())
{
rltTupleList.Add(new Tuple<bool, string>(false, "船名不一致"));
}
//航次
if (bcStoreInfo.Voyno?.Replace("1MA", "") != orderInfo.VOYNO?.Trim()
&& bcStoreInfo.Voyno2 != orderInfo.VOYNO?.Trim() && bcStoreInfo.Voyno3 != orderInfo.VOYNO?.Trim())
{
rltTupleList.Add(new Tuple<bool, string>(false, "航次不一致"));
}
/*
//2021-10-12增加最小、最大、运输温度湿度通风 的比较
//2021-11-23备注中含有NOR不比较温度湿度等信息
2023-02-02 这里补充了一下EDIREMARK的判断用正则匹配NOR信息。NOR(冻代干集装箱)
*/
if (orderInfo.CARGOID == "R" && (string.IsNullOrWhiteSpace(orderInfo.SOREMARK) || !Regex.IsMatch(orderInfo.SOREMARK, "\\bNOR\\b")))
{
//最低温度
var compareReult = CompareTemperatureNum(orderInfo.TEMPMIN, bcStoreInfo.TempMin, "temp");
if (!compareReult.Item1)
rltTupleList.Add(compareReult);
//最高温度
compareReult = CompareTemperatureNum(orderInfo.TEMPMAX, bcStoreInfo.TempMax, "temp", "最高温度");
if (!compareReult.Item1)
rltTupleList.Add(compareReult);
//运输温度
compareReult = CompareTemperatureNum(orderInfo.TEMPSET, bcStoreInfo.TempTransport, "temp", "运输温度");
if (!compareReult.Item1)
rltTupleList.Add(compareReult);
//湿度
compareReult = CompareTemperatureNum(orderInfo.HUMIDITY, bcStoreInfo.Humidity, "humidity", "湿度");
if (!compareReult.Item1)
rltTupleList.Add(compareReult);
//通风
compareReult = CompareTemperatureNum(orderInfo.REEFERF, bcStoreInfo.VentilationCubicMeter, "vent", "通风");
if (!compareReult.Item1)
rltTupleList.Add(compareReult);
}
/*
* 2021-12-3捷丰要求加卸货港和目的地校验规则
* A大简云里卸货港字段之前的字符和BC里卸货港之前的字段。
* 1.一致,自动发送下货纸
* 2.不一致,生成待处理下货纸任务。
* Bbc如果有最终交货地 那么要和系统目的港对比;最终交货地空白 就不用对比这个地方
*/
string orderPortDischarge = orderInfo.PORTDISCHARGE.Split(new char[] { ',' }).FirstOrDefault()?.Trim();
string storePortDischarge = bcStoreInfo.PortDischargeEName.Split(new char[] { ',' }).FirstOrDefault()?.Trim();
if (orderPortDischarge != storePortDischarge)
rltTupleList.Add(new Tuple<bool, string>(false, "卸货港不一致"));
string orderDest = orderInfo.DESTINATION.Split(new char[] { ',' }).FirstOrDefault()?.Trim();
string storeDest = bcStoreInfo.ZZJHD.Split(new char[] { ',' }).FirstOrDefault()?.Trim();
if (orderDest != storeDest)
rltTupleList.Add(new Tuple<bool, string>(false, "目的地不一致"));
if (rltTupleList.Any(t => !t.Item1))
{
result.succ = false;
result.msg = string.Join(";", rltTupleList.Select(t => t.Item2).ToArray());
}
}
catch(Exception ex)
{
throw Oops.Bah("{0}单票比对BC异常,{1}",nameof(InnerCompareBC), ex.Message);
}
return result;
}
#endregion
#region 对比温度
/// <summary>
/// 对比温度
/// </summary>
/// <param name="orderTemperature">订舱数值</param>
/// <param name="storeTemperature">回执数值</param>
/// <param name="operType">操作类型 temp-温度 humidity-湿度 vent-通风</param>
/// <param name="showName">显示名称</param>
/// <returns>返回结果</returns>
private Tuple<bool, string> CompareTemperatureNum(string orderTemperature,string storeTemperature,string operType = "temp",string showName = "最低温度")
{
decimal orderTemp = int.MaxValue;
decimal storeTemp = int.MaxValue;
decimal.TryParse(orderTemperature, out orderTemp);
if (!string.IsNullOrWhiteSpace(storeTemperature))
{
if (operType == "temp")
{
decimal.TryParse(Regex.Match(storeTemperature, "(\\-?([0-9]?|[0-9]+)\\.?[0-9]+)(?=C)").Value, out storeTemp);
}
else if (operType == "humidity")
{
decimal.TryParse(Regex.Match(storeTemperature, "\\[0-9]+").Value, out storeTemp);
}
else if (operType == "vent")
{
decimal.TryParse(storeTemperature, out storeTemp);
}
}
if (storeTemp != int.MaxValue && orderTemp != int.MaxValue)
{
if (storeTemp != orderTemp)
return new Tuple<bool, string>(false, $"{showName}不一致");
}
else
{
if (storeTemp != int.MaxValue || orderTemp != int.MaxValue)
return new Tuple<bool, string>(false, $"{showName}不一致");
}
return new Tuple<bool, string>(true, "");
}
#endregion
#region 下载截单EDI
/// <summary>
/// 下载截单EDI
/// </summary>
/// <param name="taskPKId">任务主键</param>
/// <param name="orderNo">订单号</param>
/// <param name="useForwarderCode">是否使用货代代码</param>
/// <param name="forwarderCode">货代代码</param>
/// <param name="forwarderName">货代称呼</param>
/// <param name="fileRole">文件功能 (9原始,1 更新,5 退舱 )</param>
/// <param name="sendType">发送类型 E-截单</param>
/// <param name="multilineid">多行文本拆分记录ID(SITC-收、发、通拆分)</param>
/// <returns>返回结果</returns>
[HttpGet("/TaskManage/DownloadClosingEDI")]
public async Task<IActionResult> DownloadClosingEDI([FromQuery] string taskPKId, [FromQuery] string orderNo, [FromQuery] bool useForwarderCode,
[FromQuery] string forwarderCode, [FromQuery] string forwarderName, [FromQuery] string fileRole, [FromQuery] string sendType, [FromQuery] string multilineid = "")
{
if (sendType?.ToUpper() != "E")
throw Oops.Oh($"sendType只接收E-截单");
var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == taskPKId);
if (taskInfo == null)
throw Oops.Oh($"任务信息获取失败");
if (string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
throw Oops.Oh($"任务信息的订舱主键不存在");
if (taskInfo.TASK_TYPE != TaskBusiTypeEnum.SI_FEEDBACK.ToString())
throw Oops.Oh($"当前任务类型不是{TaskBusiTypeEnum.SI_FEEDBACK.GetDescription()}");
BookingOrder bookingOrder = null;
if (!string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
bookingOrder = _bookingOrderRepository.AsQueryable().First(t => t.Id == long.Parse(taskInfo.BOOK_ORDER_NO));
if (bookingOrder == null)
throw Oops.Oh($"订舱信息获取失败MBLNO={taskInfo.MBL_NO}");
var model = new BookingOrClosingEDIOrderDto
{
Id = bookingOrder.Id,
orderNo = orderNo,
useForwarderCode = useForwarderCode,
forwarderCode = forwarderCode,
forwarderName = forwarderName,
fileRole = fileRole,
send = false,
sendType = sendType
};
if (!string.IsNullOrWhiteSpace(multilineid))
{
model.multilineid = long.Parse(multilineid);
}
var bookingOrderService = _namedBookingOrderServiceProvider.GetService<ITransient>(nameof(BookingOrderService));
var filePath = await bookingOrderService.InnerBookingOrClosingEDI(model);
var fileInfo = new FileInfo(filePath);
var result = new FileStreamResult(new FileStream(filePath, FileMode.Open), "application/octet-stream") { FileDownloadName = fileInfo.Name };
return result;
}
#endregion
#region 发送截单EDI
/// <summary>
/// 发送截单EDI
/// </summary>
/// <param name="taskPKId">任务主键</param>
/// <param name="orderNo">订单号</param>
/// <param name="useForwarderCode">是否使用货代代码</param>
/// <param name="forwarderCode">货代代码</param>
/// <param name="forwarderName">货代称呼</param>
/// <param name="fileRole">文件功能 (9原始,1 更新,5 退舱 )</param>
/// <param name="sendType">发送类型 E-截单</param>
/// <param name="multilineid">多行文本拆分记录ID(SITC-收、发、通拆分)</param>
/// <returns>返回结果</returns>
[HttpGet("/TaskManage/SendClosingEDI")]
public async Task<string> SendClosingEDI([FromQuery] string taskPKId, [FromQuery] string orderNo, [FromQuery] bool useForwarderCode,
[FromQuery] string forwarderCode, [FromQuery] string forwarderName, [FromQuery] string fileRole, [FromQuery] string sendType, [FromQuery] string multilineid = "")
{
if (sendType?.ToUpper() != "E")
throw Oops.Oh($"sendType只接收E-截单");
var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.PK_ID == taskPKId);
if (taskInfo == null)
throw Oops.Oh($"任务信息获取失败");
if (string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
throw Oops.Oh($"任务信息的订舱主键不存在");
if (taskInfo.TASK_TYPE != TaskBusiTypeEnum.SI_FEEDBACK.ToString())
throw Oops.Oh($"当前任务类型不是{TaskBusiTypeEnum.SI_FEEDBACK.GetDescription()}");
BookingOrder bookingOrder = null;
if (!string.IsNullOrWhiteSpace(taskInfo.BOOK_ORDER_NO))
bookingOrder = _bookingOrderRepository.AsQueryable().First(t => t.Id == long.Parse(taskInfo.BOOK_ORDER_NO));
if (bookingOrder == null)
throw Oops.Oh($"订舱信息获取失败MBLNO={taskInfo.MBL_NO}");
var model = new BookingOrClosingEDIOrderDto
{
Id = bookingOrder.Id,
orderNo = orderNo,
useForwarderCode = useForwarderCode,
forwarderCode = forwarderCode,
forwarderName = forwarderName,
fileRole = fileRole,
send = true,
sendType = sendType
};
if (!string.IsNullOrWhiteSpace(multilineid))
{
model.multilineid = long.Parse(multilineid);
}
var bookingOrderService = _namedBookingOrderServiceProvider.GetService<ITransient>(nameof(BookingOrderService));
return await bookingOrderService.InnerBookingOrClosingEDI(model);
}
#endregion
#region 计算LARA纸计算页数
/// <summary>
/// 计算LARA纸计算页数
/// </summary>
/// <param name="model">请求LARA纸详情</param>
/// <returns>返回结果</returns>
[HttpPost("/TaskManage/CalcLaraPageNumbers")]
public async Task<List<LaraPaperRegistPostDto>> CalcLaraPageNumbers(CalcLaraPageNumbersDto model)
{
List<LaraPaperRegistPostDto> list = new List<LaraPaperRegistPostDto>();
/*
LARA计算方法
1、判断是否为首次加载model.moveType为空时表示首次加载触发InitCalcLaraPageNumbers方法。
2、如果 model.moveType有值时判断是调整行位置根据指定的行位置重新计算编号。
*/
try
{
if(string.IsNullOrWhiteSpace(model.moveType))
{
list = InnerCalcLaraPageNumbers(model,true);
}
else
{
list = InnerCalcLaraPageNumbers(model);
}
}
catch (Exception ex)
{
throw Oops.Bah("计算LARA纸计算页数异常,{0}", ex.Message);
}
return list;
}
#endregion
#region 计算LARA纸
/// <summary>
/// 计算LARA纸
/// </summary>
/// <param name="model">请求LARA纸详情</param>
/// <param name="isInit">是否初始化 true-初始化</param>
/// <returns></returns>
private List<LaraPaperRegistPostDto> InnerCalcLaraPageNumbers(CalcLaraPageNumbersDto model,bool isInit = false)
{
List<LaraPaperRegistPostDto> list = new List<LaraPaperRegistPostDto>();
//如果判断不是首次加载,需要将移动的行从列表移动到指定位置后,重新计算。
if(!isInit)
{
model.paperList = model.paperList.Select(t =>
{
if (t.SortNo == model.origIndex.Value)
{
//up
if(model.currIndex < model.origIndex)
{
t.SortNo = (decimal)model.currIndex.Value - 0.1m;
}
else
{
t.SortNo = (decimal)model.currIndex.Value + 0.1m;
}
}
return t;
}).OrderBy(t => t.SortNo)
.Select((t, idx) =>
{
t.SortNo = (decimal)idx + 1;
return t;
}).ToList();
}
var mNumberTo = model.numberTo.TrimStart('0') == "" ? 0 : int.Parse(model.numberTo.TrimStart('0'));
if (mNumberTo > 0)
{
int lastNumberTo = 0;
int lastNumberFrom = 0;
model.paperList.OrderBy(t => t.SortNo).ToList().ForEach(t =>
{
LaraPaperRegistPostDto info = new LaraPaperRegistPostDto();
info.SortNo = t.SortNo;
info.DraftNum = t.DraftNum;
info.TaskId = t.TaskId;
info.ORDNO = t.ORDNO;
info.MBLNO = t.MBLNO;
info.ISSUETYPE = t.ISSUETYPE;
if (t.SortNo == 1)
{
lastNumberFrom = mNumberTo + 1;
info.NumberFrom = (lastNumberFrom).ToString().PadLeft(9, '0');
var currNumberTo = (t.DraftNum * LARA_PARER_DRAFT_VAR) + mNumberTo;
info.NumberTo = currNumberTo.ToString().PadLeft(9, '0');
info.PageSum = currNumberTo - lastNumberFrom + 1;
lastNumberTo = currNumberTo;
}
else
{
lastNumberFrom = lastNumberTo + 1;
info.NumberFrom = (lastNumberFrom).ToString().PadLeft(9, '0');
var currNumberTo = (t.DraftNum * LARA_PARER_DRAFT_VAR) + lastNumberTo;
info.NumberTo = currNumberTo.ToString().PadLeft(9, '0');
info.PageSum = currNumberTo - lastNumberFrom + 1;
lastNumberTo = currNumberTo;
}
list.Add(info);
});
}
return list;
}
#endregion
/// <summary>
/// 撤销任务
/// </summary>
/// <param name="info">任务详情</param>
/// <returns>返回回执</returns>
public async Task<TaskManageOrderResultDto> CancelTaskJob(TaskManageOrderMessageInfo info)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
/*
1、通过Head.GID检索任务表。
2、任务不存在提示检索失败。
3、任务存在判断当前状态已完成、已取消、已挂起不能撤销。
4、派车任务业务状态是SEND_DISPATCH不能撤销。
5、更新任务状态、更新派车任务状态。
6、返回结果
*/
try
{
var taskInfo = _taskBaseInfoRepository.AsQueryable().OrderByDescending(a => a.CreatedTime)
.First(t => t.OUT_BUSI_NO == $"{info.Head.SenderId}_{info.Head.GID}");
if (taskInfo == null)
throw Oops.Oh($"任务不存在");
if(new string[] { TaskStatusEnum.Pending.ToString(),TaskStatusEnum.Cancel.ToString() }
.Contains(taskInfo.STATUS))
throw Oops.Oh($"任务状态是已挂起/已取消的不能撤销");
var truckInfo = _taskTruckInfoRepository.AsQueryable().First(a => a.TASK_ID == taskInfo.PK_ID);
if (truckInfo == null)
throw Oops.Oh($"派车任务不存在");
//if(truckInfo.Status == BookingTruckStatus.SEND_DISPATCH.ToString())
// throw Oops.Oh($"派车任务状态是已派车不能撤销");
DateTime nowDate = DateTime.Now;
truckInfo.Status = BookingTruckStatus.CANCELED.ToString();
UserTendDto userTendInfo = GetUserTendInfo(info.Main.TaskUserId);
truckInfo.UpdatedUserId = userTendInfo.userId;
truckInfo.UpdatedUserName = userTendInfo.userName;
truckInfo.UpdatedTime = nowDate;
//更新派车任务
await _taskTruckInfoRepository.AsUpdateable(truckInfo).UpdateColumns(it => new
{
it.UpdatedUserId,
it.Status,
it.UpdatedUserName,
it.UpdatedTime
}).ExecuteCommandAsync();
taskInfo.UpdatedUserId = userTendInfo.userId;
taskInfo.UpdatedUserName = userTendInfo.userName;
taskInfo.UpdatedTime = nowDate;
taskInfo.STATUS = TaskStatusEnum.Cancel.ToString();
//更新任务
await _taskBaseInfoRepository.AsUpdateable(taskInfo).UpdateColumns(it => new
{
it.UpdatedUserId,
it.STATUS,
it.UpdatedUserName,
it.UpdatedTime
}).ExecuteCommandAsync();
result.succ = true;
result.msg = "撤销成功";
}
catch (Exception ex)
{
_logger.LogError("撤销任务异常,原因:{error}", ex.Message);
throw Oops.Oh($"{ex.Message}");
}
return result;
}
#region 创建BC任务
/// <summary>
/// 创建BC任务
/// </summary>
/// <param name="file">文件</param>
/// <param name="modifyFile">BC变更内容后文件</param>
/// <param name="jsonData">BC任务详情JSON</param>
/// <returns>返回回执</returns>
[HttpPost("/TaskManage/CreateBCTaskJob"), AllowAnonymous, ApiUser(ApiCode = "BCTaskManage")]
public async Task<TaskManageOrderResultDto> CreateBCTaskJob(IFormFile file, IFormFile modifyFile, [FromForm] string jsonData)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
_logger.LogInformation("批次={no} 接收到创建任务报文 报文={msg}", batchNo, jsonData);
try
{
TaskManageOrderMessageInfo info = JSON.Deserialize<TaskManageOrderMessageInfo>(jsonData);
if(info == null)
throw Oops.Bah("jsonData请求内容错误无法反序列化报文");
result = await InitTaskJob(info, batchNo, file, modifyFile);
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"请求任务异常,{ex.Message}";
}
return result;
}
#endregion
#region 创建DRAFT任务
/// <summary>
/// 创建DRAFT任务
/// </summary>
/// <param name="file">文件</param>
/// <param name="modifyFile">DRAFT变更内容后文件</param>
/// <param name="jsonData">DRAFT任务详情JSON</param>
/// <returns>返回回执</returns>
[AllowAnonymous, HttpPost("/TaskManage/CreateDRAFTTaskJob"), ApiUser(ApiCode = "BCTaskManage")]
public async Task<TaskManageOrderResultDto> CreateDRAFTTaskJob(IFormFile file, IFormFile modifyFile, [FromForm] string jsonData)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
_logger.LogInformation("批次={no} 接收到创建任务报文 报文={msg}", batchNo, jsonData);
try
{
TaskManageOrderMessageInfo info = JSON.Deserialize<TaskManageOrderMessageInfo>(jsonData);
if (info == null)
throw Oops.Bah("jsonData请求内容错误无法反序列化报文");
result = await InitTaskJob(info, batchNo, file, modifyFile);
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"请求任务异常,{ex.Message}";
}
return result;
}
#endregion
#region 创建截单回执任务
/// <summary>
/// 创建截单回执任务
/// </summary>
/// <param name="file">文件</param>
/// <param name="modifyFile">截单回执变更内容后文件</param>
/// <param name="jsonData">截单回执任务详情JSON</param>
/// <returns>返回回执</returns>
[HttpPost("/TaskManage/CreateSISubmittedTaskJob"), AllowAnonymous, ApiUser(ApiCode = "BCTaskManage")]
public async Task<TaskManageOrderResultDto> CreateSISubmittedTaskJob(IFormFile file, IFormFile modifyFile, [FromForm] string jsonData)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
_logger.LogInformation("批次={no} 接收到创建任务报文 报文={msg}", batchNo, jsonData);
try
{
TaskManageOrderMessageInfo info = JSON.Deserialize<TaskManageOrderMessageInfo>(jsonData);
if (info == null)
throw Oops.Bah("jsonData请求内容错误无法反序列化报文");
result = await InitTaskJob(info, batchNo, file, modifyFile);
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"请求任务异常,{ex.Message}";
}
return result;
}
#endregion
#region 创建Advisory任务
/// <summary>
/// 创建Advisory任务
/// </summary>
/// <param name="file">文件</param>
/// <param name="jsonData">BC任务详情JSON</param>
/// <returns>返回回执</returns>
[HttpPost("/TaskManage/CreateAdvisoryTaskJob"), AllowAnonymous, ApiUser(ApiCode = "BCTaskManage")]
public async Task<TaskManageOrderResultDto> CreateAdvisoryTaskJob(IFormFile file, IFormFile modifyFile, string jsonData)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
_logger.LogInformation("批次={no} 接收到创建任务报文 报文={msg}", batchNo, jsonData);
try
{
TaskManageOrderMessageInfo info = JSON.Deserialize<TaskManageOrderMessageInfo>(jsonData);
if (info == null)
throw Oops.Bah("jsonData请求内容错误无法反序列化报文");
result = await InitTaskJob(info, batchNo, file, null);
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"请求任务异常,{ex.Message}";
}
return result;
}
#endregion
#region 获取文件类型
/// <summary>
/// 获取文件类型
/// </summary>
/// <param name="fileName">文件完成路径</param>
/// <returns>返回文件类型枚举</returns>
private PrintFileTypeEnum GetFileType(string fileName)
{
PrintFileTypeEnum fileType = PrintFileTypeEnum.PDF;
switch (Path.GetExtension(fileName).ToLower())
{
case ".pdf":
fileType = PrintFileTypeEnum.PDF;
break;
case ".xlsx":
fileType = PrintFileTypeEnum.XLSX;
break;
case ".docx":
fileType = PrintFileTypeEnum.DOCX;
break;
case ".xls":
fileType = PrintFileTypeEnum.XLS;
break;
case ".doc":
fileType = PrintFileTypeEnum.DOC;
break;
}
return fileType;
}
#endregion
}
#region 样本业务提取帮助类
/// <summary>
/// 样本业务提取帮助类
/// </summary>
public static class DraftPaperExtension
{
public static int GetPageNum(this string Name)
{
try
{
if (string.IsNullOrWhiteSpace(Name))
return 0;
string s = Regex.Replace(Name.Substring(Name.LastIndexOf('-') + 1), "\\.[a-zA-Z]+", "");
return int.Parse(s);
}
catch(Exception ex)
{
throw Oops.Bah("文件名{0} 取页数异常,{1}", Name, ex.Message);
}
}
}
#endregion
#region 整理文本数据
public static class CompareObjExtension
{
/// <summary>
/// 整理文本数据
/// </summary>
/// <param name="str">文本</param>
/// <returns></returns>
public static string AdjustString(this string str)
{
if (string.IsNullOrWhiteSpace(str))
return str;
var rtn = str.Replace("\r\n", "\n").Trim();
if (rtn.EndsWith("\n"))
{
rtn = rtn.Substring(0, rtn.Length - 1);
}
return rtn;
}
/// <summary>
/// 文本转换成日期
/// </summary>
/// <param name="str">文本</param>
/// <param name="MemberName">字段名称</param>
/// <returns>返回日期</returns>
public static Nullable<DateTime> GetDateTime(this string str,string MemberName)
{
if (string.IsNullOrWhiteSpace(str))
return null;
DateTime currDate = DateTime.MinValue;
if (!DateTime.TryParse(str, out currDate))
throw Oops.Oh("字段{0}={1}转换日期失败,请检查日期格式", MemberName, str);
return currDate;
}
}
#endregion
}