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.

2899 lines
138 KiB
C#

using DS.Module.Core;
using DS.Module.Core.Condition;
4 months ago
using DS.Module.Core.Constants;
4 months ago
using DS.Module.Core.Data;
4 months ago
using DS.Module.Core.Enums;
using DS.Module.Core.Extensions;
using DS.Module.Core.Helpers;
using DS.Module.DjyServiceStatus;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
4 months ago
using DS.WMS.Core.Code.Dtos;
using DS.WMS.Core.Code.Interface;
4 months ago
using DS.WMS.Core.Map.Dtos;
using DS.WMS.Core.Map.Interface;
using DS.WMS.Core.Op.Dtos;
4 months ago
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.TaskPlat.Dtos;
using DS.WMS.Core.TaskPlat.Entity;
using DS.WMS.Core.TaskPlat.Interface;
5 months ago
using Mapster;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
4 months ago
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using SqlSugar;
using System.Linq.Expressions;
namespace DS.WMS.Core.TaskPlat.Method
{
4 months ago
public class TaskManageService : TaskManageBaseService<TaskManageService>, ITaskManageService
{
4 months ago
// 实例化时构建
private readonly ICodeCtnService codeCtnService;
4 months ago
private readonly ICodePortService codePortService;
private readonly IMappingPortService mappingPortService;
private readonly IMappingCarrierService mappingCarrierService;
4 months ago
// 按需构建
//private readonly Lazy<ISeaExportCommonService> seaExportCommonService;
4 months ago
/// <summary>
/// 上一次进行全局任务匹配的时间
/// </summary>
public static DateTime LastMatchTaskTime = DateTime.Now;
4 months ago
public TaskManageService(IUser user,
ILogger<TaskManageService> logger,
ISaasDbService saasDbService,
4 months ago
IServiceProvider serviceProvider,
IWebHostEnvironment environment,
4 months ago
ICodeCtnService codeCtnService,
ICodePortService codePortService,
IMappingPortService mappingPortService,
IMappingCarrierService mappingCarrierService) : base(user, logger, saasDbService, serviceProvider, environment)
{
this.codeCtnService = codeCtnService;
4 months ago
this.codePortService = codePortService;
this.mappingPortService = mappingPortService;
this.mappingCarrierService = mappingCarrierService;
3 months ago
//seaExportCommonService = new Lazy<ISeaExportCommonService>(serviceProvider.GetRequiredService<ISeaExportCommonService>);
}
4 months ago
#region 对工作流提供的接口
/// <summary>
/// 工作流设置任务在个人下的状态
/// </summary>
/// <param name="bsno">业务主键</param>
/// <param name="taskBaseTypeEnum">业务类型</param>
/// <param name="taskStatusEnum">业务状态</param>
/// <param name="statusTime">状态发生时间</param>
/// <param name="userInfos">要设置任务状态的人员列表</param>
public async Task<DataResult> SetTaskUserStatus(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, TaskStatusEnum taskStatusEnum, DateTime? statusTime, List<RecvUserInfo> userInfos)
{
SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
TaskBaseInfo taskInfo = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
4 months ago
.OrderByDescending(a => a.Id)
.FirstAsync(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskBaseTypeEnum.ToString());
if (taskInfo == null)
{
logger.LogInformation($"根据bsno:【{bsno}】,TaskBaseTypeEnum【{taskBaseTypeEnum}】未查询到任务");
return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData)));
}
logger.LogInformation("接收到任务个人状态修改报文 任务主键={id} 状态设置={status} 人员列表={userList}", taskInfo.Id, taskStatusEnum.ToString(), JsonConvert.SerializeObject(userInfos));
var userIdList = userInfos.Select(x => x.RecvUserId).ToList();
var taskBaseAllocationList = await tenantDb.Queryable<TaskBaseAllocation>()
.Where(x => x.TaskId == taskInfo.Id && userIdList.Contains(x.UserId))
.ToListAsync();
if (taskBaseAllocationList.Any())
{
taskBaseAllocationList.ForEach(x =>
{
x.Status = taskStatusEnum.ToString();
x.StatusName = taskStatusEnum.EnumDescription();
x.StatusTime = statusTime;
});
await tenantDb.Updateable(taskBaseAllocationList).UpdateColumns(x => new
{
x.UpdateBy,
x.UpdateTime,
x.UpdateUserName,
x.Status,
x.StatusName,
x.StatusTime
}).ExecuteCommandAsync();
}
return DataResult.Successed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataUpdateSuccess)));
}
/// <summary>
/// 通过业务Id设置任务状态(工作流使用)
/// </summary>
/// <param name="bsno">业务主键</param>
/// <param name="taskBaseTypeEnum">业务类型</param>
/// <param name="taskStatusEnum">业务状态</param>
/// <param name="statusTime">状态发生时间</param>
public async Task<DataResult> SetTaskStatusWithBsno(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, TaskStatusEnum taskStatusEnum, DateTime? statusTime)
{
SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
TaskBaseInfo taskInfo = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
4 months ago
.OrderByDescending(a => a.Id)
.FirstAsync(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskBaseTypeEnum.ToString());
if (taskInfo == null)
{
logger.LogInformation($"根据bsno:【{bsno}】,TaskBaseTypeEnum【{taskBaseTypeEnum}】未查询到任务");
return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData)));
}
3 months ago
return await SetTaskStatus(taskInfo, taskStatusEnum, statusTime, bsno);
}
/// <summary>
/// 工作流任务转交
/// </summary>
/// <param name="bsno">业务主键</param>
/// <param name="taskBaseTypeEnum">业务类型</param>
/// <param name="userInfos">要转交的人员信息列表</param>
public async Task<DataResult> TransferTask(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, List<RecvUserInfo> userInfos)
{
SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
try
{
var taskId = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.Where(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskBaseTypeEnum.ToString())
4 months ago
.OrderByDescending(a => a.Id)
.Select<long?>(t => t.Id)
.FirstAsync();
if (taskId == null || taskId == 0)
{
logger.LogInformation($"根据bsno:【{bsno}】,TaskBaseTypeEnum【{taskBaseTypeEnum}】未查询到任务");
return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData)));
}
logger.LogInformation("接收到任务转交报文 任务主键={id} 转交人员列表={userinfo}", taskId, JsonConvert.SerializeObject(userInfos));
//await tenantDb.Ado.BeginTranAsync();
await tenantDb.Deleteable<TaskBaseAllocation>(x => x.TaskId == taskId).ExecuteCommandHasChangeAsync();
var allocationList = userInfos.Select(x => new TaskBaseAllocation
{
TaskId = (long)taskId,
UserId = x.RecvUserId,
UserName = x.RecvUserName,
Status = TaskStatusEnum.Create.ToString(),
StatusName = TaskStatusEnum.Create.EnumDescription(),
}).ToList();
await tenantDb.Insertable(allocationList).ExecuteCommandAsync();
//await tenantDb.Ado.CommitTranAsync();
return DataResult.Successed("操作成功!", MultiLanguageConst.DataUpdateSuccess);
}
catch (Exception)
{
//await tenantDb.Ado.RollbackTranAsync();
throw;
}
}
/// <summary>
/// 工作流设置任务对象属性
/// </summary>
public async Task<DataResult> SetTaskBaseInfoPropertyWithBsno(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, params Expression<Func<TaskBaseInfo, bool>>[] columns)
{
SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
long? taskInfoId = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.OrderByDescending(a => a.Id)
.Where(t => t.OUT_BS_NO == bsno && t.TASK_TYPE == taskBaseTypeEnum.ToString())
.Select(t => t.Id)
.FirstAsync();
if (taskInfoId == null || taskInfoId == 0)
{
logger.LogInformation($"根据bsno:【{bsno}】,TaskBaseTypeEnum【{taskBaseTypeEnum}】未查询到任务");
return DataResult.Failed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData)));
}
else
{
logger.LogInformation($"根据bsno:【{bsno}】,查询出taskInfoId=【{taskInfoId}】");
}
var updateable = tenantDb.Updateable<TaskBaseInfo>();
foreach (var item in columns)
{
updateable.SetColumns(item);
}
updateable.SetColumns(x => x.UpdateBy == long.Parse(user.UserId))
.SetColumns(x => x.UpdateTime == DateTime.Now)
.SetColumns(x => x.UpdateUserName == user.UserName);
await updateable.Where(x => taskInfoId == x.Id)
.ExecuteCommandAsync();
return DataResult.Successed("操作成功");
}
#endregion
/// <summary>
/// 创建任务公共方法
/// </summary>
/// <param name="info"></param>
/// <param name="file"></param>
/// <param name="modifyFile"></param>
/// <returns></returns>
public async Task<DataResult> InitTaskJob(TaskManageOrderMessageInfo info, IFormFile file = null, IFormFile modifyFile = null)
{
string batchNo = Guid.NewGuid().ToString();
try
{
logger.LogInformation("批次={no} 接收到创建任务报文 报文={msg}", batchNo, JsonConvert.SerializeObject(info));
4 months ago
SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
//var sql = tenantDb.Queryable<SeaExport>().Where(x => x.Id > 232 ).ToSqlString();
//var a = user.UserId;
//var aa = user.TenantId;
//var a343 = user.GetTenantId();
//var sfdfd = user.TenantName;
//var b = user.GetOrgId();
//var b232 = user.OrgId;
TaskBaseInfo taskInfo = null;
// 如果业务主键不为空,则通过业务主键进行重复判断
if (info.Head.BSNO is not null or 0)
{
taskInfo = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.Where(t => t.OUT_BS_NO == info.Head.BSNO)
.WhereIF(info.Main.IsCheckExistsByTaskType, t => t.TASK_TYPE == info.Main.TaskType.ToString())
4 months ago
.OrderByDescending(a => a.Id)
.FirstAsync();
}
// 否则通过Head.GID进行判断
else
{
taskInfo = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.Where(t => t.OUT_BUSI_NO == $"{info.Head.SenderId}_{info.Head.GID}")
.WhereIF(info.Main.IsCheckExistsByTaskType, t => t.TASK_TYPE == info.Main.TaskType.ToString())
4 months ago
.OrderByDescending(a => a.Id)
.FirstAsync();
}
// 只要任务最后一次处理任务的状态是已取消、已完成,就可以重入新的任务
if (taskInfo != null
&& taskInfo.STATUS != TaskStatusEnum.Cancel.ToString()
&& taskInfo.STATUS != TaskStatusEnum.Complete.ToString())
{
logger.LogInformation("批次={no} 状态已存在,不能重复创建任务 status={status}", batchNo, taskInfo.STATUS);
throw new Exception($"状态已存在,不能重复创建任务");
}
logger.LogInformation("批次={no} 接收到创建任务报文 结束查询任务 {msg}", batchNo, taskInfo == null ? "不存在" : "存在");
//如果文件路径不为空 判断文件是否真实存在
if (!string.IsNullOrWhiteSpace(info.Main.FilePath) && !File.Exists(info.Main.FilePath))
{
throw new Exception(string.Format("{0}文件不存在", info.Main.FilePath));
}
//如果文件路径不为空 判断文件是否真实存在
if (!string.IsNullOrWhiteSpace(info.Main.ModifyFile) && !File.Exists(info.Main.ModifyFile))
{
throw new Exception(string.Format("{0}文件不存在", info.Main.ModifyFile));
}
taskInfo = new TaskBaseInfo
{
Id = SnowFlakeSingle.Instance.NextId(),
STATUS = TaskStatusEnum.Create.ToString(),
STATUS_NAME = TaskStatusEnum.Create.EnumDescription(),
IS_EXCEPT = 0,
IS_COMPLETE = 0,
MBL_NO = info.Main.MBlNo,
TASK_TYPE = info.Main.TaskType.ToString(),
//TASK_BASE_TYPE = info.Main.TaskType.ToString(),
//CARRIER_ID = info.Main.CarrierId?.Trim(),
//IS_PUBLIC = string.IsNullOrWhiteSpace(info.Main.TaskUserId) ? 1 : 0,
IS_PUBLIC = 1,
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_SOURCE_NAME = info.Main.TaskSource.EnumDescription(),
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,
OUT_BS_NO = info.Head.BSNO,
CUSTOMER_NO = info.Main.CUSTOMER_NO,
CreateTime = DateTime.Now,
};
if (Enum.TryParse(typeof(TaskBaseTypeEnum), taskInfo.TASK_TYPE, out object? taskTypeTemp))
{
taskInfo.TASK_TYPE_NAME = ((TaskBaseTypeEnum)taskTypeTemp).EnumDescription();
}
// 如果船公司主键不为空则直接保存船公司主键、Code、Name等信息
if (info.Main.CarrierPK != null)
{
taskInfo.CARRIER_ID = info.Main.CarrierPK;
taskInfo.CARRIER_CODE = info.Main.CarrierId;
taskInfo.CARRIER_NAME = info.Main.CarrierName;
}
// 如果船公司主键为空但是Code不为空则通过映射查出船公司信息并保存
else if (!string.IsNullOrEmpty(info.Main.CarrierId))
{
// 船公司转换
var allMapCarrierList = (await mappingCarrierService.GetAllList())?.Data ?? new List<MappingCarrierRes>();
MappingCarrierRes? carrierInfo = allMapCarrierList.Where(t => t.MapCode.Equals(info.Main.CarrierId, StringComparison.OrdinalIgnoreCase) && t.Module == MappingModuleConst.CONST_MAPPING_CARRIER_MODULE).FirstOrDefault();
if (carrierInfo != null)
{
taskInfo.CARRIER_ID = carrierInfo.LinkId;
taskInfo.CARRIER_CODE = carrierInfo.MapCode;
taskInfo.CARRIER_NAME = carrierInfo.MapName;
}
}
// 人员字段说明:
// TaskBaseInfo.CreateBy 创建人:谁创建的,只有一个人(可能是某个租户的管理员,因为任务可以由外部(邮件)创建,无法为每个人创建接口授权信息)
// TaskBaseInfo.TASK_REQ_USERID 制单人只有一个人使用任务创建报文中传入的TaskUserId
// TaskBaseAllocation.UserId 任务关系任务属于谁谁能够查看并处理可能是多个人可能是多个人一起处理取值优先级info.Main.RecvUserInfoList>关联订单
// TaskBaseInfo.RealUserId 实际操作人:谁实际处理的,只有一个人(但是工作流过来的任务会由多个人处理)
// 创建人
taskInfo.CreateBy = long.Parse(user.UserId);
taskInfo.CreateUserName = user.UserName;
// 制单人
long taskReqUserId = 0;
if (!string.IsNullOrWhiteSpace(info.Main.TaskUserId))
{
if (long.TryParse(info.Main.TaskUserId, out taskReqUserId))
{
taskInfo.TASK_REQ_USERID = taskReqUserId;
taskInfo.TASK_REQ_USERNAME = info.Main.TaskUserName;
}
}
logger.LogInformation("批次={no} 获取登录人详情 recvUserId={recvUserId} UserId={UserId}", batchNo,
info.Main.RecvUserId,
user.UserId);
// 任务所属人员列表
// 如果明确指出接收人(接收人列表),则将任务作为个人任务
if (info.Main.RecvUserInfoList?.Count > 0)
{
logger.LogInformation("批次={no} 接收人列表 recvUserList={recvUserList} ", batchNo,
JsonConvert.SerializeObject(info.Main.RecvUserInfoList));
taskInfo.IS_PUBLIC = 0;
var allocationList = info.Main.RecvUserInfoList.Select(x => new TaskBaseAllocation
{
TaskId = taskInfo.Id,
UserId = x.RecvUserId,
UserName = x.RecvUserName,
Status = TaskStatusEnum.Create.ToString(),
StatusName = TaskStatusEnum.Create.EnumDescription(),
StatusTime = DateTime.Now
}).ToList();
await tenantDb.Insertable(allocationList).ExecuteCommandAsync();
}
// 否则判断任务关联订单,如果能关联到,则判断任务设置的角色;如果有设置,则将任务挂载到订单的指定角色上;如果没关联到或者没有设置,则作为公共任务
//else
//{
// // 1.查找任务的匹配设置
// var allotSet = await tenantDb.Queryable<TaskAllotSet>().Where(x => x.TaskType == info.Main.TaskType.ToString()).FirstAsync();
// if (allotSet != null)
// {
// // 2. 根据提单号查找订单\根据订舱编号查找订单\...
// // 3. 查找订单之后获取匹配设置参数得到人员Id列表
// // 4. 获取任务Id
// // 5. 存关系
// }
//}
if (info.Main != null && info.Main.TruckInfo != null && info.Main.TruckInfo.NeedArriveTime.HasValue)
{
taskInfo.NeedArriveTime = info.Main.TruckInfo.NeedArriveTime;
}
if (string.IsNullOrWhiteSpace(info.Main.TaskBatchNo))
{
info.Main.TaskBatchNo = SnowFlakeSingle.Instance.NextId().ToString();
}
5 months ago
await tenantDb.Insertable(taskInfo).ExecuteCommandAsync();
if (!string.IsNullOrWhiteSpace(info.Main.FilePath))
{
string attachFileType = string.Empty;
string fileCategory = string.Empty;
if (TaskBaseTypeEnum.BC.ToString() == taskInfo.TASK_TYPE)
{
attachFileType = "bcfiles";
fileCategory = TaskFileCategoryEnum.BC.ToString();
}
else if (TaskBaseTypeEnum.BC_MODIFY.ToString() == taskInfo.TASK_TYPE)
{
attachFileType = "bcmodifyfiles";
fileCategory = TaskFileCategoryEnum.BC_MODIFY.ToString();
}
else if (TaskBaseTypeEnum.CANCELLATION.ToString() == taskInfo.TASK_TYPE)
{
attachFileType = "bccancelfiles";
fileCategory = TaskFileCategoryEnum.BC_CANCEL.ToString();
}
else if (TaskBaseTypeEnum.DRAFT.ToString() == taskInfo.TASK_TYPE)
{
attachFileType = "draftfiles";
fileCategory = TaskFileCategoryEnum.DRAFT.ToString();
}
else if (TaskBaseTypeEnum.SI_FEEDBACK.ToString() == taskInfo.TASK_TYPE)
{
attachFileType = "sisubmittedfiles";
fileCategory = TaskFileCategoryEnum.SI_SUBMITTED.ToString();
}
else if (TaskBaseTypeEnum.ROUTE_CUT_CHANGE.ToString() == taskInfo.TASK_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 = SnowFlakeSingle.Instance.NextId(),
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_TYPE)
{
attachFileType = "bcfiles";
fileCategory = TaskFileCategoryEnum.BC.ToString();
}
else if (TaskBaseTypeEnum.BC_MODIFY.ToString() == taskInfo.TASK_TYPE)
{
attachFileType = "bcmodifyfiles";
fileCategory = TaskFileCategoryEnum.BC_MODIFY.ToString();
}
else if (TaskBaseTypeEnum.CANCELLATION.ToString() == taskInfo.TASK_TYPE)
{
attachFileType = "bccancelfiles";
fileCategory = TaskFileCategoryEnum.BC_CANCEL.ToString();
}
else if (TaskBaseTypeEnum.DRAFT.ToString() == taskInfo.TASK_TYPE)
{
attachFileType = "draftfiles";
fileCategory = TaskFileCategoryEnum.DRAFT.ToString();
}
else if (TaskBaseTypeEnum.SI_FEEDBACK.ToString() == taskInfo.TASK_TYPE)
{
attachFileType = "sisubmittedfiles";
fileCategory = TaskFileCategoryEnum.SI_SUBMITTED.ToString();
}
else if (TaskBaseTypeEnum.ROUTE_CUT_CHANGE.ToString() == taskInfo.TASK_TYPE)
{
attachFileType = "advisoryfiles";
fileCategory = TaskFileCategoryEnum.ADVISORY.ToString();
}
var noExtensionFileName = Path.GetFileNameWithoutExtension(file.FileName);
var fileFullName = await SaveFile(taskInfo.Id.ToString(),
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 = SnowFlakeSingle.Instance.NextId(),
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_TYPE)
fileCategory = TaskFileCategoryEnum.BC_NOTICE.ToString();
else if (TaskBaseTypeEnum.BC_MODIFY.ToString() == taskInfo.TASK_TYPE)
fileCategory = TaskFileCategoryEnum.BC_MODIFY_NOTICE.ToString();
else if (TaskBaseTypeEnum.CANCELLATION.ToString() == taskInfo.TASK_TYPE)
fileCategory = TaskFileCategoryEnum.BC_CANCEL_NOTICE.ToString();
else if (TaskBaseTypeEnum.DRAFT.ToString() == taskInfo.TASK_TYPE)
fileCategory = TaskFileCategoryEnum.DRAFT_NOTICE.ToString();
if (info.Main.FileList == null)
info.Main.FileList = new List<TaskManageOrderFileInfo>();
info.Main.FileList.Add(new TaskManageOrderFileInfo
{
PKId = SnowFlakeSingle.Instance.NextId(),
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_TYPE)
{
attachFileType = "bcnoticefiles";
fileCategory = TaskFileCategoryEnum.BC_NOTICE.ToString();
}
else if (TaskBaseTypeEnum.BC_MODIFY.ToString() == taskInfo.TASK_TYPE)
{
attachFileType = "bcmodifynoticefiles";
fileCategory = TaskFileCategoryEnum.BC_MODIFY_NOTICE.ToString();
}
else if (TaskBaseTypeEnum.CANCELLATION.ToString() == taskInfo.TASK_TYPE)
{
attachFileType = "bccancelnoticefiles";
fileCategory = TaskFileCategoryEnum.BC_CANCEL_NOTICE.ToString();
}
else if (TaskBaseTypeEnum.DRAFT.ToString() == taskInfo.TASK_TYPE)
{
attachFileType = "draftnoticefiles";
fileCategory = TaskFileCategoryEnum.DRAFT_NOTICE.ToString();
}
var noExtensionFileName = Path.GetFileNameWithoutExtension(modifyFile.FileName);
var fileFullName = await SaveFile(taskInfo.Id.ToString(),
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 = SnowFlakeSingle.Instance.NextId(),
FileName = modifyFile.FileName,
FileType = Path.GetExtension(modifyFile.FileName).ToLower(),
FilePath = fileFullName,
FileCategory = fileCategory
});
}
}
}
#region 附件
//附件
if (info.Main.FileList != null && info.Main.FileList.Count > 0)
{
var fileList = info.Main.FileList.Select(file =>
{
var fileInfo = new TaskFileInfo();
fileInfo.Id = SnowFlakeSingle.Instance.NextId();
fileInfo.TASK_PKID = taskInfo.Id;
fileInfo.CreateBy = taskInfo.CreateBy;
fileInfo.CreateTime = taskInfo.CreateTime;
//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_TYPE)
{
fileInfo.FILE_CATEGORY = TaskFileCategoryEnum.BC.ToString();
fileInfo.FILE_CATEGORY_NAME = TaskFileCategoryEnum.BC.EnumDescription();
}
else if (TaskBaseTypeEnum.BC_MODIFY.ToString() == taskInfo.TASK_TYPE)
{
fileInfo.FILE_CATEGORY = TaskFileCategoryEnum.BC_MODIFY.ToString();
fileInfo.FILE_CATEGORY_NAME = TaskFileCategoryEnum.BC_MODIFY.EnumDescription();
}
}
else
{
TaskFileCategoryEnum fileCategoryEnum = TaskFileCategoryEnum.NONE;
System.Enum.TryParse(file.FileCategory, out fileCategoryEnum);
fileInfo.FILE_CATEGORY = fileCategoryEnum.ToString();
fileInfo.FILE_CATEGORY_NAME = fileCategoryEnum.EnumDescription();
}
if (string.IsNullOrWhiteSpace(fileInfo.FILE_NAME))
{
var fileModel = new FileInfo(file.FilePath);
fileInfo.FILE_NAME = fileModel.Name;
fileInfo.FILE_TYPE = fileModel.Extension?.Replace(".", "");
}
return fileInfo;
}).ToList();
await tenantDb.Insertable(fileList).ExecuteCommandAsync();
}
#endregion
#region 邮件
//邮件
if (info.Main.EmailList != null && info.Main.EmailList.Count > 0)
{
var emailList = info.Main.EmailList.Select(email =>
{
var emailInfo = new TaskEmail();
emailInfo.Id = SnowFlakeSingle.Instance.NextId();
emailInfo.TASK_PKID = taskInfo.Id;
emailInfo.CreateTime = taskInfo.CreateTime;
emailInfo.CreateBy = taskInfo.CreateBy;
emailInfo.MAIL_PATH = email.MailPath;
return emailInfo;
}).ToList();
await tenantDb.Insertable(emailList).ExecuteCommandAsync();
}
#endregion
#region SI反馈入库
//SI反馈入库
if (info.Main.TaskType == TaskBaseTypeEnum.SI_FEEDBACK)
{
if (info.Main.SIFeedBack == null)
throw new Exception($"任务类型={info.Main.TaskType.ToString()} SIFeedBack信息必传");
TaskSiSubmitted taskSISubmitted = info.Main.SIFeedBack.Adapt<TaskSiSubmitted>();
//taskSISubmitted.Id = SnowFlakeSingle.Instance.NextId();
taskSISubmitted.TASK_ID = taskInfo.Id;
taskSISubmitted.CreateTime = taskInfo.CreateTime;
taskSISubmitted.CreateBy = taskInfo.CreateBy;
await tenantDb.Insertable<TaskSiSubmitted>(taskSISubmitted).ExecuteReturnEntityAsync();
//SI反馈箱信息入库
if (info.Main.SIFeedBack.ContaList != null && info.Main.SIFeedBack.ContaList.Count > 0)
{
var codeCtnCache = (await codeCtnService.GetAllList())?.Data ?? new List<Code.Dtos.CodeCtnRes>();
4 months ago
var list = info.Main.SIFeedBack.ContaList.Select(ctn =>
{
var contaInfo = ctn.Adapt<TaskSiSubmittedCtn>();
4 months ago
contaInfo.P_PKID = taskSISubmitted.Id;
4 months ago
if (string.IsNullOrWhiteSpace(contaInfo.CTNCODE) && !string.IsNullOrWhiteSpace(contaInfo.CTNALL))
{
if (codeCtnCache != null && codeCtnCache.Count > 0)
{
var ctnCodeInfo = codeCtnCache.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.CtnName)
&& x.CtnName.Equals(contaInfo.CTNALL, StringComparison.OrdinalIgnoreCase));
4 months ago
if (ctnCodeInfo != null)
{
contaInfo.CTNCODE = ctnCodeInfo.EdiCode;
}
}
}
4 months ago
return contaInfo;
}).ToList();
await tenantDb.Insertable<TaskSiSubmittedCtn>(list).ExecuteCommandAsync();
}
// 执行自动化操作
TaskFlowDataContext dataContext = new(
(TaskFlowDataNameConst.TaskBCId, taskInfo.Id)
);
TaskFlowRuner taskFlow = new TaskFlowRuner(tenantDb, serviceProvider);
await taskFlow.Run(info.Main.TaskType, taskInfo.Id, dataContext);
}
#endregion
4 months ago
#region 费用明细
//费用明细
if (info.Main.TaskType == TaskBaseTypeEnum.INVOICE_BILL_MAIL)
{
if (info.Main.FeeList != null && info.Main.FeeList.Count > 0)
{
var list = info.Main.FeeList.Select(fee =>
{
var feeInfo = fee.Adapt<TaskBillFeeDetail>();
feeInfo.TASK_PKID = taskInfo.Id;
feeInfo.CreateTime = taskInfo.CreateTime;
feeInfo.CreateBy = taskInfo.CreateBy;
return feeInfo;
}).ToList();
await tenantDb.Insertable(list).ExecuteCommandAsync();
}
}
#endregion
#region 单票账单
if (info.Main.TaskType == TaskBaseTypeEnum.PER_BILL)
{
TaskPerBillBase taskPerBillBaseInfo = info.Main.PerBillInfo.Adapt<TaskPerBillBase>();
//写入
await tenantDb.Insertable(taskPerBillBaseInfo).ExecuteCommandAsync();
if (info.Main.FeeList != null && info.Main.FeeList.Count > 0)
{
var list = info.Main.FeeList.Select(fee =>
{
var feeInfo = fee.Adapt<TaskBillFeeDetail>();
feeInfo.TASK_PKID = taskInfo.Id;
feeInfo.CreateTime = taskInfo.CreateTime;
feeInfo.CreateBy = taskInfo.CreateBy;
return feeInfo;
}).ToList();
await tenantDb.Insertable(list).ExecuteCommandAsync();
}
}
#endregion
#region 派车任务
if (info.Main.TaskType == TaskBaseTypeEnum.TRUCK_DISPATCH)
{
//派车任务
if (info.Main.TruckInfo == null)
{
throw new Exception($"派车任务主信息不能为空,请查看请求报文");
}
var truckInfo = info.Main.TruckInfo.Adapt<TaskTruck>();
truckInfo.TASK_ID = taskInfo.Id;
truckInfo.BookingTruckId = info.Main.TruckInfo.Id;
truckInfo.CreateTime = taskInfo.CreateTime;
truckInfo.CreateBy = taskInfo.CreateBy;
truckInfo.Status = BookingTruckStatus.TEMP.ToString();
//异步写入
await tenantDb.Insertable(truckInfo).ExecuteCommandAsync();
if (info.Main.TruckInfo.ContaList != null && info.Main.TruckInfo.ContaList.Count > 0)
{
var contaList = info.Main.TruckInfo.ContaList.Adapt<List<TaskTruckCtn>>();
var list = contaList.Select(x =>
{
x.P_ID = taskInfo.Id;
x.CreateTime = taskInfo.CreateTime;
x.CreateBy = taskInfo.CreateBy;
return x;
}).ToList();
await tenantDb.Insertable(list).ExecuteCommandAsync();
}
}
#endregion
#region BC 任务
5 months ago
if (info.Main.TaskType == TaskBaseTypeEnum.BC
|| info.Main.TaskType == TaskBaseTypeEnum.BC_MODIFY
|| info.Main.TaskType == TaskBaseTypeEnum.CANCELLATION)
{
5 months ago
//异步写入
var bcInfo = info.Main.BCInfo.Adapt<TaskBCInfo>();
5 months ago
bcInfo.Id = SnowFlakeSingle.Instance.NextId();
bcInfo.TASK_ID = taskInfo.Id;
bcInfo.CreateBy = taskInfo.CreateBy;
bcInfo.CreateTime = taskInfo.CreateTime;
bcInfo.BATCH_NO = info.Main.TaskBatchNo;
5 months ago
if (info.Main.BCInfo.BookingSlotId.HasValue && info.Main.BCInfo.BookingSlotId.Value > 0)
bcInfo.BOOKING_SLOT_ID = info.Main.BCInfo.BookingSlotId.Value;
await tenantDb.Insertable(bcInfo).ExecuteCommandAsync();
//异步写入集装箱
var ctnCodeList = (await codeCtnService.GetAllList()).Data ?? new List<Code.Dtos.CodeCtnRes>();
4 months ago
var ctnList = info.Main.BCInfo.CtnList.Select(ctn =>
5 months ago
{
var bcCtnInfo = ctn.Adapt<TaskBCCTNInfo>();
bcCtnInfo.Id = SnowFlakeSingle.Instance.NextId();
bcCtnInfo.P_ID = bcInfo.Id;
if (string.IsNullOrEmpty(bcCtnInfo.CTNCODE))
{
var ctnCode = ctnCodeList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.CtnName) && a.CtnName.Equals(bcCtnInfo.CTNALL, StringComparison.OrdinalIgnoreCase));
bcCtnInfo.CTNCODE = ctnCode != null ? ctnCode.EdiCode : "";
}
bcCtnInfo.CreateBy = taskInfo.CreateBy;
bcCtnInfo.CreateTime = taskInfo.CreateTime;
4 months ago
return bcCtnInfo;
}).ToList();
5 months ago
4 months ago
await tenantDb.Insertable(ctnList).ExecuteCommandAsync();
5 months ago
/*
BC_MODIFY
1
2
3@
CANCELLATION
1
2@
*/
4 months ago
// 执行自动化操作
var bcFileInfo =
file == null ? null : new DynameFileInfo
{
FileBytes = file.ToByteArray(),
FileName = file.FileName
};
var bcNoticeFileInfo =
modifyFile == null ? null : new DynameFileInfo
{
FileBytes = modifyFile.ToByteArray(),
FileName = modifyFile.FileName
};
4 months ago
TaskFlowDataContext dataContext = new(
// 固定
(TaskFlowDataNameConst.TaskBaseInfo, taskInfo),
// 邮件接收任务特有
4 months ago
(TaskFlowDataNameConst.TaskManageOrderMessageInfo, info),
// BC任务特有
(TaskFlowDataNameConst.BCFileInfo, bcFileInfo),
(TaskFlowDataNameConst.BCNotifyFileInfo, bcNoticeFileInfo),
4 months ago
(TaskFlowDataNameConst.TaskBCInfo, bcInfo),
(TaskFlowDataNameConst.TaskBCCtnList, ctnList)
4 months ago
);
TaskFlowRuner taskFlow = new TaskFlowRuner(tenantDb, serviceProvider);
4 months ago
await taskFlow.Run(info.Main.TaskType, taskInfo.Id, dataContext);
}
#endregion
4 months ago
#region 截止时间变更通知
if (info.Main.TaskType == TaskBaseTypeEnum.CUT_MODIFY)
{
var cutInfo = info.Main.CutDateChange.Adapt<TaskCutDateChangeInfo>();
cutInfo.TASK_ID = taskInfo.Id;
cutInfo.CreateTime = taskInfo.CreateTime;
cutInfo.CreateBy = taskInfo.CreateBy;
await tenantDb.Insertable(cutInfo).ExecuteCommandAsync();
if (info.Main.CutDateChange.Details != null && info.Main.CutDateChange.Details.Count > 0)
{
//异步写入明细
var list = info.Main.CutDateChange.Details.Select(detail =>
{
var cutDetail = detail.Adapt<TaskCutDateChangeDetailInfo>();
cutDetail.P_ID = cutInfo.Id;
cutDetail.CreateTime = taskInfo.CreateTime;
cutDetail.CreateBy = taskInfo.CreateBy;
return cutDetail;
}).ToList();
await tenantDb.Insertable(list).ExecuteCommandAsync();
}
////触发推送消息
//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>();
foreach (var p in info.Main.VGMFeedBack)
{
//异步写入
var vgmInfo = p.Adapt<TaskVgmInfo>();
vgmInfo.TASK_ID = taskInfo.Id;
vgmInfo.CreateTime = taskInfo.CreateTime;
vgmInfo.CreateBy = taskInfo.CreateBy;
vgmInfo.TASK_TYPE = info.Main.TaskType.ToString();
await tenantDb.Insertable(vgmInfo).ExecuteCommandAsync();
vgmList.Add(vgmInfo);
var ctnList = p.CtnList.Select(ctn =>
{
var vgmCtnInfo = ctn.Adapt<TaskVgmCtnInfo>();
vgmCtnInfo.P_ID = vgmInfo.Id;
vgmCtnInfo.CreateTime = taskInfo.CreateTime;
vgmCtnInfo.CreateBy = taskInfo.CreateBy;
return vgmCtnInfo;
}).ToList();
await tenantDb.Insertable(ctnList).ExecuteCommandAsync();
}
//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<TaskRollingNomination>();
rollingNomination.TASK_ID = taskInfo.Id;
rollingNomination.CreateTime = taskInfo.CreateTime;
rollingNomination.CreateBy = taskInfo.CreateBy;
//这里把多条的预甩计划列表合并保存,展示时只需要用\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 tenantDb.Insertable(rollingNomination).ExecuteCommandAsync();
if (info.Main.RollingNomination.From != null && info.Main.RollingNomination.From.Count > 0)
{
var list = info.Main.RollingNomination.From.Select(k =>
{
var rollingNominationShip = k.Adapt<TaskRollingNominationShip>();
rollingNominationShip.TASK_ID = taskInfo.Id;
rollingNominationShip.NOM_ID = rollingNomination.Id;
rollingNominationShip.CreateTime = taskInfo.CreateTime;
rollingNominationShip.CreateBy = taskInfo.CreateBy;
return rollingNominationShip;
}).ToList();
await tenantDb.Insertable(list).ExecuteCommandAsync();
}
if (info.Main.RollingNomination.ToDetail != null && info.Main.RollingNomination.ToDetail.Count > 0)
{
var ctnCodeList = (await codeCtnService.GetAllList()).Data ?? new List<Code.Dtos.CodeCtnRes>();
foreach (var t in info.Main.RollingNomination.ToDetail)
{
var rollingNominationShip = t.Adapt<TaskRollingNominationShip>();
rollingNominationShip.TASK_ID = taskInfo.Id;
rollingNominationShip.NOM_ID = rollingNomination.Id;
rollingNominationShip.CreateTime = taskInfo.CreateTime;
await tenantDb.Insertable(rollingNominationShip).ExecuteCommandAsync();
if (t.NominationList != null && t.NominationList.Count > 0)
{
//这里直接批量检索订舱信息,如果有对应的提单号直接写入订舱主键
var billNoList = t.NominationList.Select(x => x.Shipment.ToUpper())
.Distinct().ToArray();
var bookList = await tenantDb.Queryable<SeaExport>().Where(x => billNoList.Contains(x.MBLNO)).ToListAsync();
foreach (var x in t.NominationList)
{
var rollingNominationDetail = x.Adapt<TaskRollingNominationDetail>();
if (!string.IsNullOrWhiteSpace(rollingNominationDetail.CTNALL))
{
var ctnCode = ctnCodeList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.CtnName) && a.CtnName.Equals(rollingNominationDetail.CTNALL, StringComparison.OrdinalIgnoreCase));
rollingNominationDetail.CTNCODE = ctnCode != null ? ctnCode.EdiCode : "(箱型未收录)";
}
rollingNominationDetail.NOM_SHIP_ID = rollingNominationShip.Id;
rollingNominationDetail.NOM_ID = rollingNomination.Id;
rollingNominationDetail.CreateTime = taskInfo.CreateTime;
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;
}
await tenantDb.Insertable(rollingNominationDetail).ExecuteCommandAsync();
};
}
}
}
//异步生成调度
//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.TASK_ID = taskInfo.Id;
taskDraftInfo.CreateTime = taskInfo.CreateTime;
await tenantDb.Insertable(taskDraftInfo).ExecuteCommandAsync();
}
#endregion
#region 任务目的港未提货/任务目的港提货未返空
if (info.Main.TaskType == TaskBaseTypeEnum.POD_DISCHARGE_FULL || info.Main.TaskType == TaskBaseTypeEnum.POD_GATEOUT_FULL)
{
TaskPodDischargeGateoutFull dischargeGateout = info.Main.PODDischargeGateoutFull.Adapt<TaskPodDischargeGateoutFull>();
dischargeGateout.TASK_ID = taskInfo.Id;
dischargeGateout.CreateTime = taskInfo.CreateTime;
await tenantDb.Insertable(dischargeGateout).ExecuteCommandAsync();
//明细入库
if (info.Main.PODDischargeGateoutFull.DetailList != null
&& info.Main.PODDischargeGateoutFull.DetailList.Count > 0)
{
4 months ago
var list = info.Main.PODDischargeGateoutFull.DetailList.Select(ctn =>
4 months ago
{
var detailInfo = ctn.Adapt<TaskPodDischargeGateoutFullDetail>();
detailInfo.P_ID = dischargeGateout.Id;
detailInfo.CreateTime = taskInfo.CreateTime;
4 months ago
return detailInfo;
}).ToList();
await tenantDb.Insertable(list).ExecuteCommandAsync();
4 months ago
}
////触发推送消息
//var name = _namedPODDischargeGateoutFullProvider
// .GetService<ITransient>(nameof(TaskManagePODDischargeGateoutFullService));
//await name.AutoTransferNotice(taskInfo.PK_ID);
}
#endregion
#region 重要提醒
if (info.Main.TaskType == TaskBaseTypeEnum.CAUTION_NOTICE)
{
TaskCautionNotice taskCautionNoticeInfo = info.Main.CautionNoticeInfo.Adapt<TaskCautionNotice>();
taskCautionNoticeInfo.TASK_ID = taskInfo.Id;
taskCautionNoticeInfo.CreateTime = taskInfo.CreateTime;
taskCautionNoticeInfo.CAUTION_NOTICE_TYPE = info.Main.CautionNoticeInfo.CautionNoticeType.ToString();
await tenantDb.Insertable(taskCautionNoticeInfo).ExecuteCommandAsync();
var list = info.Main.CautionNoticeInfo.NoticeList.Select(notice =>
{
var noticeInfo = notice.Adapt<TaskCautionNoticeDetail>();
noticeInfo.NOTIFY_METHOD = notice.CautionNoticeType.ToString();
noticeInfo.P_ID = taskCautionNoticeInfo.Id;
noticeInfo.CreateTime = taskInfo.CreateTime;
noticeInfo.STATUS = TaskCautionNoticeStatusEnum.TEMP.ToString();
noticeInfo.STATUS_NAME = TaskCautionNoticeStatusEnum.TEMP.EnumDescription();
return noticeInfo;
}).ToList();
//异步写入集装箱
await tenantDb.Insertable(list).ExecuteCommandAsync();
////这里加了个判断如果没有标记自动发送消息就不触发转发功能
//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)
{
TaskRouteChangeAdvisory taskRouteChangeAdvisoryInfo = info.Main.RouteChangeAdvisoryInfo.Adapt<TaskRouteChangeAdvisory>();
taskRouteChangeAdvisoryInfo.TASK_ID = taskInfo.Id;
taskRouteChangeAdvisoryInfo.CreateTime = taskInfo.CreateTime;
List<CodePortRes> portCodeList = new List<CodePortRes>();
if (!string.IsNullOrWhiteSpace(taskRouteChangeAdvisoryInfo.READ_PORTLOAD))
{
var portList = (await codePortService.GetAllList()).Data ?? new List<Code.Dtos.CodePortRes>();
var allPortCodeList = await codePortService.GetAllList();
if (allPortCodeList.Succeeded)
{
portCodeList = allPortCodeList.Data;
}
var portInfo = await PlaceReceiptToPortload(taskRouteChangeAdvisoryInfo.READ_PORTLOAD, portCodeList, () => mappingPortService.GetAllList());
if (!portInfo.Succeeded)
{
logger.LogInformation($"通过收货地城市名称未匹配到港口信息航线船舶截止时间调整的通知Id{taskRouteChangeAdvisoryInfo.Id}");
}
else
{
taskRouteChangeAdvisoryInfo.PORTLOADID = portInfo.Data.EdiCode;
taskRouteChangeAdvisoryInfo.PORTLOAD = portInfo.Data.PortName;
}
}
await tenantDb.Insertable(taskRouteChangeAdvisoryInfo).ExecuteCommandAsync();
////触发推送消息
//var name = _namedRouteChangeAdvisoryServiceServiceProvider
// .GetService<ITransient>(nameof(RouteChangeAdvisoryService));
//await name.AutoTransferNotice(taskInfo.PK_ID);
}
#endregion
#region 货物运输计划已变更
if (info.Main.TaskType == TaskBaseTypeEnum.TRNAS_PLAN_HAS_CHANGE)
{
TaskTransPlanHasChange taskTransPlanHasChangeInfo = info.Main.TransportPlanHasChangeInfo.Adapt<TaskTransPlanHasChange>();
taskTransPlanHasChangeInfo.TASK_ID = taskInfo.Id;
taskTransPlanHasChangeInfo.CreateTime = taskInfo.CreateTime;
await tenantDb.Insertable(taskTransPlanHasChangeInfo).ExecuteCommandAsync();
if (info.Main.TransportPlanHasChangeInfo.From != null)
{
if (info.Main.TransportPlanHasChangeInfo.From.portList != null
&& info.Main.TransportPlanHasChangeInfo.From.portList.Count > 0)
{
var list = info.Main.TransportPlanHasChangeInfo.From.portList.Select(p =>
{
TaskTransPlanHasChangeDetail detailInfo = new TaskTransPlanHasChangeDetail
{
PORTLOAD = p.PortName,
PORTLOAD_COUNTRY = p.CountryCode,
PORTLOAD_TERMINAL = p.TerminalName,
SORT_NO = p.Indx,
IS_REMOVED = p.IsRemoved
};
detailInfo.P_ID = taskTransPlanHasChangeInfo.Id;
detailInfo.PLAN_TYPE = "FROM";
detailInfo.COLUMN_TYPE = "PORT";
detailInfo.CreateTime = taskInfo.CreateTime;
return detailInfo;
}).ToList();
await tenantDb.Insertable(list).ExecuteCommandAsync();
}
if (info.Main.TransportPlanHasChangeInfo.From.dateList != null
&& info.Main.TransportPlanHasChangeInfo.From.dateList.Count > 0)
{
var list = info.Main.TransportPlanHasChangeInfo.From.dateList.Select(p =>
{
TaskTransPlanHasChangeDetail detailInfo = new TaskTransPlanHasChangeDetail
{
ETD = p.DateVal,
SORT_NO = p.Indx,
IS_REMOVED = p.IsRemoved
};
detailInfo.P_ID = taskTransPlanHasChangeInfo.Id;
detailInfo.PLAN_TYPE = "FROM";
detailInfo.COLUMN_TYPE = "EATD";
detailInfo.CreateTime = taskInfo.CreateTime;
return detailInfo;
}).ToList();
await tenantDb.Insertable(list).ExecuteCommandAsync();
}
if (info.Main.TransportPlanHasChangeInfo.From.vesselList != null
&& info.Main.TransportPlanHasChangeInfo.From.vesselList.Count > 0)
{
4 months ago
var list = info.Main.TransportPlanHasChangeInfo.From.vesselList.Select(p =>
{
TaskTransPlanHasChangeDetail detailInfo = new TaskTransPlanHasChangeDetail
{
VESSEL = p.Vessel,
VOYNO = p.Voyno,
SHIP_FLAG = p.Flag,
SORT_NO = p.Indx,
IS_REMOVED = p.IsRemoved
};
4 months ago
4 months ago
detailInfo.P_ID = taskTransPlanHasChangeInfo.Id;
4 months ago
4 months ago
detailInfo.PLAN_TYPE = "FROM";
detailInfo.COLUMN_TYPE = "VESSEL";
4 months ago
4 months ago
detailInfo.CreateTime = taskInfo.CreateTime;
4 months ago
4 months ago
return detailInfo;
4 months ago
4 months ago
}).ToList();
await tenantDb.Insertable(list).ExecuteCommandAsync();
4 months ago
}
}
if (info.Main.TransportPlanHasChangeInfo.To != null)
{
if (info.Main.TransportPlanHasChangeInfo.To.portList != null
&& info.Main.TransportPlanHasChangeInfo.To.portList.Count > 0)
{
var list = info.Main.TransportPlanHasChangeInfo.To.portList.Select(p =>
{
TaskTransPlanHasChangeDetail detailInfo = new TaskTransPlanHasChangeDetail
{
PORTDISCHARGE = p.PortName,
PORTDISCHARGE_COUNTRY = p.CountryCode,
PORTDISCHARGE_TERMINAL = p.TerminalName,
SORT_NO = p.Indx,
IS_REMOVED = p.IsRemoved
};
detailInfo.P_ID = taskTransPlanHasChangeInfo.Id;
detailInfo.PLAN_TYPE = "TO";
detailInfo.COLUMN_TYPE = "PORT";
detailInfo.CreateTime = taskInfo.CreateTime;
return detailInfo;
}).ToList();
await tenantDb.Insertable(list).ExecuteCommandAsync();
}
if (info.Main.TransportPlanHasChangeInfo.To.dateList != null
&& info.Main.TransportPlanHasChangeInfo.To.dateList.Count > 0)
{
var list = info.Main.TransportPlanHasChangeInfo.To.dateList.Select(p =>
{
TaskTransPlanHasChangeDetail detailInfo = new TaskTransPlanHasChangeDetail
{
ETA = p.DateVal,
SORT_NO = p.Indx,
IS_REMOVED = p.IsRemoved
};
detailInfo.P_ID = taskTransPlanHasChangeInfo.Id;
detailInfo.PLAN_TYPE = "TO";
detailInfo.COLUMN_TYPE = "EATD";
detailInfo.CreateTime = taskInfo.CreateTime;
return detailInfo;
}).ToList();
await tenantDb.Insertable(list).ExecuteCommandAsync();
}
if (info.Main.TransportPlanHasChangeInfo.To.vesselList != null
&& info.Main.TransportPlanHasChangeInfo.To.vesselList.Count > 0)
{
var list = info.Main.TransportPlanHasChangeInfo.To.vesselList.Select(p =>
{
TaskTransPlanHasChangeDetail detailInfo = new TaskTransPlanHasChangeDetail
{
VESSEL = p.Vessel,
VOYNO = p.Voyno,
SHIP_FLAG = p.Flag,
SORT_NO = p.Indx,
IS_REMOVED = p.IsRemoved
};
detailInfo.P_ID = taskTransPlanHasChangeInfo.Id;
detailInfo.PLAN_TYPE = "TO";
detailInfo.COLUMN_TYPE = "VESSEL";
detailInfo.CreateTime = taskInfo.CreateTime;
return detailInfo;
}).ToList();
await tenantDb.Insertable(list).ExecuteCommandAsync();
}
}
if (info.Main.TransportPlanHasChangeInfo.ContaNoList != null && info.Main.TransportPlanHasChangeInfo.ContaNoList.Count > 0)
{
var list = info.Main.TransportPlanHasChangeInfo.ContaNoList.Select(p =>
{
TaskTransPlanHasChangeDetail detailInfo = new TaskTransPlanHasChangeDetail
{
CONTA_NO = p,
};
detailInfo.P_ID = taskTransPlanHasChangeInfo.Id;
detailInfo.COLUMN_TYPE = "CTN";
detailInfo.CreateTime = taskInfo.CreateTime;
return detailInfo;
}).ToList();
await tenantDb.Insertable(list).ExecuteCommandAsync();
}
////触发推送消息
//var name = _namedTaskTransPlanHasChangeServiceProvider
// .GetService<ITransient>(nameof(TaskTransPlanHasChangeService));
//await name.AutoTransferNotice(taskInfo.PK_ID);
}
#endregion
#region 装货港未提箱通知
if (info.Main.TaskType == TaskBaseTypeEnum.POL_CTN_NOT_PICKUP)
{
TaskPolContainerNotPickup taskPOLContainerNotPickUpInfo = info.Main.POLContainerNotPickupInfo.Adapt<TaskPolContainerNotPickup>();
taskPOLContainerNotPickUpInfo.TASK_ID = taskInfo.Id;
taskPOLContainerNotPickUpInfo.CreateTime = taskInfo.CreateTime;
await tenantDb.Insertable(taskPOLContainerNotPickUpInfo).ExecuteCommandAsync();
3 months ago
//出发任务流程
TaskFlowDataContext dataContext = new(
// 固定
(TaskFlowDataNameConst.TaskPKId, taskInfo.Id)
);
4 months ago
3 months ago
TaskFlowRuner taskFlow = new TaskFlowRuner(tenantDb, serviceProvider);
await taskFlow.Run(info.Main.TaskType, taskInfo.Id, dataContext);
4 months ago
}
#endregion
#region 黑名单
#endregion
#region 截单补料异常提醒
#endregion
#region 启运港箱使费通知
#endregion
var taskNo = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId)).Where(a => a.Id == taskInfo.Id).Select(a => a.TASK_NO).FirstAsync();
//回写任务号
var result = new DataResult(ResultCode.Success, "新增任务成功", data: taskNo);
4 months ago
return await Task.FromResult(result);
}
catch (Exception ex)
{
logger.LogError(ex, "任务台:初始化任务的过程中发生未知异常,批次号={no}", batchNo);
return DataResult.Failed(ex.Message);
}
}
4 months ago
/// <summary>
/// 任务台台账列表查询
/// </summary>
public async Task<DataResult<List<dynamic>>> GetPageAsync(PageRequest<QueryTaskManageDto> querySearch)
{
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
if (querySearch.OtherQueryCondition == null)
{
throw new ArgumentNullException(nameof(querySearch.OtherQueryCondition));
}
//序列化查询条件
List<IConditionalModel>? whereList = null;
if (!string.IsNullOrEmpty(querySearch.QueryCondition))
{
whereList = tenantDb.Utilities.JsonToConditionalModels(querySearch.QueryCondition);
if (whereList != null)
{
foreach (var item in whereList)
{
if (item is ConditionalModel model)
{
if (!model.FieldName.StartsWith("t."))
{
model.FieldName = "t." + model.FieldName;
}
}
}
}
}
// 格式化参数
TaskBaseTypeEnum? taskType = null;
if (Enum.TryParse(typeof(TaskBaseTypeEnum), querySearch.OtherQueryCondition.TaskType, out object? temp))
{
taskType = (TaskBaseTypeEnum)temp;
};
4 months ago
TaskStatLevelEnum? taskStatLevel = null;
//TaskStatLevelEnum? taskStatLevel = TaskStatLevelEnum.PUBLIC;
if (Enum.TryParse(typeof(TaskStatLevelEnum), querySearch.OtherQueryCondition.TaskCategory, out object? tempStat))
{
taskStatLevel = (TaskStatLevelEnum)tempStat;
4 months ago
}
else
{
//throw new ArgumentException("TaskCategory");
4 months ago
}
var userId = long.Parse(user.UserId);
DataResult<List<dynamic>> result = new();
try
{
switch (taskType)
{
case TaskBaseTypeEnum.BC:
{
var queryable = tenantDb.Queryable<TaskBaseInfo>()
.LeftJoin<TaskBaseAllocation>((t, a) => t.Id == a.TaskId)
.LeftJoin<TaskBCInfo>((t, a, bc) => t.Id == bc.TASK_ID);
4 months ago
SetCondition(queryable, whereList, taskType, taskStatLevel, querySearch.OtherQueryCondition, userId);
4 months ago
result = await queryable.Select<dynamic>((t, a, bc) => new
{
Id = t.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
})
.Distinct().ToQueryPageAsync(querySearch.PageCondition);
//var sql = queryable.ToSqlString();
return result;
}
case TaskBaseTypeEnum.SI_FEEDBACK:
4 months ago
{
var queryable = tenantDb.Queryable<TaskBaseInfo>().LeftJoin<TaskBaseAllocation>((t, a) => t.Id == a.TaskId)
.LeftJoin<TaskSiSubmitted>((t, a, bc) => t.Id == bc.TASK_ID);
4 months ago
SetCondition(queryable, whereList, taskType, taskStatLevel, querySearch.OtherQueryCondition, userId);
4 months ago
result = await queryable.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.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
})
.Distinct().ToQueryPageAsync(querySearch.PageCondition);
return result;
}
case TaskBaseTypeEnum.INVOICE_BILL_MAIL:
4 months ago
{
var queryable = tenantDb.Queryable<TaskBaseInfo>().LeftJoin<TaskBaseAllocation>((t, a) => t.Id == a.TaskId)
.LeftJoin<TaskPerBillBase>((t, a, bc) => t.Id == bc.TASK_PKID);
4 months ago
SetCondition(queryable, whereList, taskType, taskStatLevel, querySearch.OtherQueryCondition, userId);
4 months ago
result = await queryable.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.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
})
.Distinct().ToQueryPageAsync(querySearch.PageCondition);
return result;
}
case TaskBaseTypeEnum.TRUCK_DISPATCH:
4 months ago
{
var queryable = tenantDb.Queryable<TaskBaseInfo>().LeftJoin<TaskBaseAllocation>((t, a) => t.Id == a.TaskId)
.LeftJoin<TaskTruck>((t, a, bc) => t.Id == bc.TASK_ID);
4 months ago
SetCondition(queryable, whereList, taskType, taskStatLevel, querySearch.OtherQueryCondition, userId);
4 months ago
result = await queryable.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.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
})
.Distinct().ToQueryPageAsync(querySearch.PageCondition);
return result;
}
case TaskBaseTypeEnum.CUT_MODIFY:
4 months ago
{
var queryable = tenantDb.Queryable<TaskBaseInfo>().LeftJoin<TaskBaseAllocation>((t, a) => t.Id == a.TaskId)
.LeftJoin<TaskCutDateChangeInfo>((t, a, bc) => t.Id == bc.TASK_ID);
4 months ago
SetCondition(queryable, whereList, taskType, taskStatLevel, querySearch.OtherQueryCondition, userId);
4 months ago
result = await queryable.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.Id.SelectAll(),
bc.TASK_ID,
bc.CARRIER,
bc.VESSEL,
bc.VOYNO,
bc.NOTICE_DATE
})
.Distinct().ToQueryPageAsync(querySearch.PageCondition);
return result;
}
case TaskBaseTypeEnum.ROLLING_NOMINATION:
case TaskBaseTypeEnum.TRANSFER_NOMINATION:
4 months ago
{
var queryable = tenantDb.Queryable<TaskBaseInfo>().LeftJoin<TaskBaseAllocation>((t, a) => t.Id == a.TaskId)
.LeftJoin<TaskRollingNomination>((t, a, bc) => t.Id == bc.TASK_ID);
4 months ago
SetCondition(queryable, whereList, taskType, taskStatLevel, querySearch.OtherQueryCondition, userId);
4 months ago
result = await queryable.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.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
}).Distinct().ToQueryPageAsync(querySearch.PageCondition);
return result;
}
case TaskBaseTypeEnum.DRAFT:
4 months ago
{
var queryable = tenantDb.Queryable<TaskBaseInfo>().LeftJoin<TaskBaseAllocation>((t, a) => t.Id == a.TaskId)
.LeftJoin<TaskDraftInfo>((t, a, bc) => t.Id == bc.TASK_ID);
4 months ago
SetCondition(queryable, whereList, taskType, taskStatLevel, querySearch.OtherQueryCondition, userId);
4 months ago
result = await queryable.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.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,
}).Distinct().ToQueryPageAsync(querySearch.PageCondition);
return result;
}
case TaskBaseTypeEnum.POD_DISCHARGE_FULL:
case TaskBaseTypeEnum.POD_GATEOUT_FULL:
4 months ago
{
var queryable = tenantDb.Queryable<TaskBaseInfo>().LeftJoin<TaskBaseAllocation>((t, a) => t.Id == a.TaskId)
.LeftJoin<TaskPodDischargeGateoutFull>((t, a, bc) => t.Id == bc.TASK_ID);
4 months ago
SetCondition(queryable, whereList, taskType, taskStatLevel, querySearch.OtherQueryCondition, userId);
4 months ago
result = await queryable.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.Id.SelectAll(),
bc.TASK_ID,
bc.CARRIER,
bc.NOTICE_TYPE,
bc.NOTICE_TYPE_NAME,
//bc.MBL_NO,
bc.NOTICE_DATE
}).Distinct().ToQueryPageAsync(querySearch.PageCondition);
return result;
}
case TaskBaseTypeEnum.CAUTION_NOTICE:
4 months ago
{
var queryable = tenantDb.Queryable<TaskBaseInfo>().LeftJoin<TaskBaseAllocation>((t, a) => t.Id == a.TaskId)
.LeftJoin<TaskCautionNotice>((t, a, bc) => t.Id == bc.TASK_ID);
4 months ago
SetCondition(queryable, whereList, taskType, taskStatLevel, querySearch.OtherQueryCondition, userId);
4 months ago
result = await queryable.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.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,
}).Distinct().ToQueryPageAsync(querySearch.PageCondition);
return result;
}
case TaskBaseTypeEnum.ROUTE_CUT_CHANGE:
4 months ago
{
var queryable = tenantDb.Queryable<TaskBaseInfo>().LeftJoin<TaskBaseAllocation>((t, a) => t.Id == a.TaskId)
.LeftJoin<TaskRouteChangeAdvisory>((t, a, bc) => t.Id == bc.TASK_ID);
4 months ago
SetCondition(queryable, whereList, taskType, taskStatLevel, querySearch.OtherQueryCondition, userId);
4 months ago
result = await queryable.Select<dynamic>((t, a, bc) => new
{
PK_ID = t.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
}).Distinct().ToQueryPageAsync(querySearch.PageCondition);
return result;
}
default:
4 months ago
{
var queryable = tenantDb.Queryable<TaskBaseInfo>().LeftJoin<TaskBaseAllocation>((t, a) => t.Id == a.TaskId);
4 months ago
SetCondition(queryable, whereList, taskType, taskStatLevel, querySearch.OtherQueryCondition, userId);
4 months ago
result = await queryable.Select<dynamic>((t, a) => new
{
PK_ID = t.Id.SelectAll(),
//TASK_USER_STATUS = a.Status,
//TASK_USER_STATUS_NAME = a.StatusName,
//TASK_USER_STATUS_TIME = a.StatusTime
}).Distinct().ToQueryPageAsync(querySearch.PageCondition);
return result;
}
}
}
finally
{
if (result.Data?.Count > 0)
{
var taskIdList = result.Data.Select(x => (long)x.Id).ToList();
var allRecvUserList = await tenantDb.Queryable<TaskBaseAllocation>()
.Where(x => taskIdList.Contains(x.TaskId))
.Select(x => new RecvUserInfo()
{
TaskId = x.TaskId,
RecvUserId = x.UserId,
RecvUserName = x.UserName,
RecvUserStatus = x.Status,
RecvUserStatusName = x.StatusName,
RecvUserStatusTime = x.StatusTime
}).ToListAsync();
if (allRecvUserList.Count > 0)
{
foreach (var item in result.Data)
{
var recvUserList = allRecvUserList.Where(x => x.TaskId == item.Id).ToList();
var currentUserStatus = recvUserList.FirstOrDefault(x => x.RecvUserId == userId);
if (currentUserStatus != null)
{
var n = recvUserList.IndexOf(currentUserStatus);
if (n != 0)
{
recvUserList.RemoveAt(n);
recvUserList.Insert(0, currentUserStatus);
}
4 months ago
item.TASK_USER_STATUS = currentUserStatus.RecvUserStatus;
item.TASK_USER_STATUS_NAME = currentUserStatus.RecvUserStatusName;
item.TASK_USER_STATUS_TIME = currentUserStatus.RecvUserStatusTime;
}
item.RecvUserList = recvUserList;
}
}
}
}
}
/// <summary>
/// 获取登陆人相关的任务统计信息
/// </summary>
/// <returns>返回回执</returns>
public async Task<DataResult<TaskUserStatResultInfo>> GetCurrentTotalStat(GetCurrentTotalStatQueryDto querySearch)
{
TaskUserStatResultInfo resultInfo = new TaskUserStatResultInfo
{
LevelTop = new List<TaskUserStatItem>(),
LevelNext = new List<TaskUserStatItemNext>(),
LevelTree = new List<TaskUserStatItemTree>()
};
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
// 人员信息测试用
//var sql = tenantDb.Queryable<SeaExport>().Where(x => x.Id > 232).ToSqlString();
//var a = user.UserId;
//var aa = user.TenantId;
//var a343 = user.GetTenantId();
//var sfdfd = user.TenantName;
//var b = user.GetOrgId();
//var b232 = user.OrgId;
4 months ago
//if (LastMatchTaskTime < DateTime.Now.AddSeconds(-5)) // 效果距上一次全局任务匹配执行如果超过5秒才进行匹配
//{
//LastMatchTaskTime = DateTime.Now;
//}
4 months ago
await MatchTask();
//序列化查询条件
List<IConditionalModel>? whereList = null;
if (!string.IsNullOrEmpty(querySearch.QueryCondition))
{
whereList = tenantDb.Utilities.JsonToConditionalModels(querySearch.QueryCondition);
if (whereList != null)
{
foreach (var item in whereList)
{
if (item is ConditionalModel model)
{
if (!model.FieldName.StartsWith("t."))
{
model.FieldName = "t." + model.FieldName;
}
}
}
}
}
var userId = long.Parse(user.UserId);
//任务列表分组统计
4 months ago
var groupList = await tenantDb.Queryable<TaskBaseInfo>()
.ClearFilter(typeof(IOrgId))
4 months ago
.LeftJoin<TaskBaseAllocation>((t, a) => t.Id == a.TaskId)
.Where(whereList)
.Where((t, a) => t.STATUS != TaskStatusEnum.Cancel.ToString())
.Where((t, a) => t.IS_PUBLIC == 1 || (t.IS_PUBLIC == 0 && a.Status != null && (a.UserId == userId))) // 2024-8-14 只显示自己需要审批的任务自己创建的任务不显示所以去掉t.CreateBy == userId ||
.WhereIF(!string.IsNullOrEmpty(querySearch.BusinessNo), (t, a) => t.MBL_NO == querySearch.BusinessNo || t.CUSTOMER_NO == querySearch.BusinessNo)
.GroupBy((t, a) => new { t.TASK_TYPE, t.STATUS, a.Status, t.IS_PUBLIC })
.Select((t, a) => new
4 months ago
{
Total = SqlFunc.AggregateDistinctCount(t.Id),
4 months ago
TaskType = t.TASK_TYPE,
TStatus = t.STATUS,
AStatus = a.Status,
//IsExcept = t.IS_EXCEPT,
4 months ago
IsPublic = t.IS_PUBLIC
}).ToListAsync();
//var exceptList = groupList
// .Where(t => t.IsExcept == 1).ToList();
var personList = groupList
.Where(t => t.IsPublic == 0).ToList();
var publicList = groupList
.Where(t => t.IsPublic == 1).ToList();
#region 异常
//if (exceptList.Count > 0)
//{
// resultInfo.LevelTop.Add(new TaskUserStatItem
// {
// Key = TaskStatLevelEnum.EXCPTION.ToString(),
// Name = TaskStatLevelEnum.EXCPTION.EnumDescription(),
// 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.EnumDescription(),
// 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);
// TaskBaseTypeEnum currEnum = (TaskBaseTypeEnum)System.Enum.Parse(typeof(TaskBaseTypeEnum), t.Key.TaskType);
// resultInfo.LevelTree.Add(new TaskUserStatItemTree
// {
// TopKey = TaskStatLevelEnum.EXCPTION.ToString(),
// NextKey = t.Key.Status,
// Key = currEnum.ToString(),
// Name = currEnum.EnumDescription(),
// 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.EnumDescription(),
Total = personList.Sum(t => t.Total),
SortNo = (int)TaskStatLevelEnum.PERSON,
ActionKey = TaskStatLevelEnum.PERSON.ToString()
});
var nextList = new List<TaskUserStatItemNext>();
personList.GroupBy(t => t.AStatus)
.Select(t => new { Key = t.Key, Total = t.ToList().Sum(p => p.Total) })
.ToList().ForEach(t =>
{
if (Enum.TryParse(t.Key, out TaskStatusEnum currEnum))
{
nextList.Add(new TaskUserStatItemNext
{
TopKey = TaskStatLevelEnum.PERSON.ToString(),
Key = currEnum.ToString(),
Name = currEnum.EnumDescription(),
Total = t.Total,
SortNo = (int)currEnum,
ActionKey = $"{TaskStatLevelEnum.PERSON}#{currEnum}"
});
}
});
if (nextList.Count > 0)
resultInfo.LevelNext.AddRange(nextList.OrderBy(t => t.SortNo).ToList());
personList.GroupBy(t => new { t.AStatus, t.TaskType })
.Select(t => new { Key = t.Key, Total = t.ToList().Sum(p => p.Total) })
.ToList().ForEach(t =>
{
if (Enum.TryParse(t.Key.TaskType, out TaskBaseTypeEnum currEnum))
{
resultInfo.LevelTree.Add(new TaskUserStatItemTree
{
TopKey = TaskStatLevelEnum.PERSON.ToString(),
NextKey = t.Key.AStatus,
Key = currEnum.ToString(),
Name = currEnum.EnumDescription(),
Total = t.Total,
SortNo = (int)currEnum,
ActionKey = $"{TaskStatLevelEnum.PERSON}#{t.Key.AStatus}#{currEnum}"
});
}
});
}
#endregion
#region 公共
if (publicList.Count > 0)
{
resultInfo.LevelTop.Add(new TaskUserStatItem
{
Key = TaskStatLevelEnum.PUBLIC.ToString(),
Name = TaskStatLevelEnum.PUBLIC.EnumDescription(),
Total = publicList.Sum(t => t.Total),
SortNo = (int)TaskStatLevelEnum.PUBLIC,
ActionKey = TaskStatLevelEnum.PUBLIC.ToString()
});
var nextList = new List<TaskUserStatItemNext>();
publicList.GroupBy(t => t.TStatus)
.Select(t => new { Key = t.Key, Total = t.ToList().Sum(p => p.Total) })
.ToList().ForEach(t =>
{
if (Enum.TryParse(t.Key, out TaskStatusEnum currEnum))
{
nextList.Add(new TaskUserStatItemNext
{
TopKey = TaskStatLevelEnum.PUBLIC.ToString(),
Key = currEnum.ToString(),
Name = currEnum.EnumDescription(),
Total = t.Total,
SortNo = (int)currEnum,
ActionKey = $"{TaskStatLevelEnum.PUBLIC}#{currEnum}"
});
}
});
if (nextList.Count > 0)
resultInfo.LevelNext.AddRange(nextList.OrderBy(t => t.SortNo).ToList());
publicList.GroupBy(t => new { t.TStatus, t.TaskType })
.Select(t => new { Key = t.Key, Total = t.ToList().Sum(p => p.Total) })
.ToList().ForEach(t =>
{
if (Enum.TryParse(t.Key.TaskType, out TaskBaseTypeEnum currEnum))
{
resultInfo.LevelTree.Add(new TaskUserStatItemTree
{
TopKey = TaskStatLevelEnum.PUBLIC.ToString(),
NextKey = t.Key.TStatus,
Key = currEnum.ToString(),
Name = currEnum.EnumDescription(),
Total = t.Total,
SortNo = (int)currEnum,
ActionKey = $"{TaskStatLevelEnum.PUBLIC}#{t.Key.TStatus}#{currEnum}"
});
}
});
}
#endregion
if (resultInfo.LevelTree != null && resultInfo.LevelTree.Count > 0)
{
resultInfo.LevelTree = resultInfo.LevelTree.OrderBy(x => x.SortNo).ToList();
}
return DataResult<TaskUserStatResultInfo>.Success(resultInfo);
}
/// <summary>
/// 取消任务(可批量)
/// </summary>
/// <param name="ids">任务主键数组</param>
/// <returns>返回结果</returns>
public async Task<DataResult<TaskManageOrderResultDto>> CancelTask(long[] ids)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
var userId = long.Parse(user.UserId);
string batchNo = Guid.NewGuid().ToString();
var taskList = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.Where(x => ids.Contains(x.Id)).ToListAsync();
List<TaskManageOrderResultDto> taskRunList = new List<TaskManageOrderResultDto>();
logger.LogInformation("批次={no} ids={ids} 取消任务开始", batchNo, string.Join(",", ids));
var noList = ids.Select((a, idx) => new { no = idx + 1, id = a }).ToList();
4 months ago
//serviceProvider.GetRequiredService<ISqlSugarClient>();
foreach (var bk in taskList)
{
var sortNo = noList.FirstOrDefault(a => a.id == bk.Id).no;
taskRunList.Add(await InnerManualTask(batchNo, bk, TaskOperTypeEnum.CANCEL_TASK, sortNo));
}
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 += " -";
}
return DataResult<TaskManageOrderResultDto>.Success(result);
}
/// <summary>
/// 单票执行任务
/// </summary>
/// <param name="batchNo">批次号</param>
/// <param name="model">任务详情</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 tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
var userId = long.Parse(user.UserId);
if (taskOperTypeEnum == TaskOperTypeEnum.COMPLETE_TASK)
{
if (model.TASK_TYPE == TaskBaseTypeEnum.TRUCK_DISPATCH.ToString())
{
if (model.STATUS == TaskStatusEnum.Cancel.ToString())
{
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskCannotCompleteWhenStatusMismatch)), TaskStatusEnum.Cancel.EnumDescription()));
}
}
if (model.TASK_TYPE == TaskBaseTypeEnum.CANCELLATION.ToString())
{
//收到订舱已被取消邮件后生成的任务,如果点击完成,(订舱状态变为【退舱】,注意这里还需要确认)
}
model.COMPLETE_DATE = DateTime.Now;
model.COMPLETE_DEAL = TaskCompleteDealEnum.MANUAL.ToString();
model.COMPLETE_DEAL = TaskCompleteDealEnum.MANUAL.EnumDescription();
model.IS_COMPLETE = 1;
model.STATUS = TaskStatusEnum.Complete.ToString();
model.STATUS_NAME = TaskStatusEnum.Complete.EnumDescription();
await tenantDb.Updateable(model).UpdateColumns(it => new
{
it.COMPLETE_DATE,
it.COMPLETE_DEAL,
it.COMPLETE_DEAL_NAME,
it.IS_COMPLETE,
it.STATUS,
it.STATUS_NAME,
it.UpdateBy,
it.UpdateTime,
it.UpdateUserName
}).ExecuteCommandAsync();
}
else if (taskOperTypeEnum == TaskOperTypeEnum.CANCEL_TASK)
{
if (model.TASK_TYPE == TaskBaseTypeEnum.CHANGE_SHIP.ToString())
{
model.STATUS = TaskStatusEnum.Cancel.ToString();
model.STATUS_NAME = TaskStatusEnum.Cancel.EnumDescription();
await tenantDb.Updateable(model).UpdateColumns(it => new
{
it.COMPLETE_DATE,
it.COMPLETE_DEAL,
it.COMPLETE_DEAL_NAME,
it.IS_COMPLETE,
it.STATUS,
it.STATUS_NAME,
it.UpdateBy,
it.UpdateTime,
it.UpdateUserName
}).ExecuteCommandAsync();
}
else if (model.TASK_TYPE == TaskBaseTypeEnum.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.EnumDescription();
await tenantDb.Updateable(model).UpdateColumns(it => new
{
it.STATUS,
it.STATUS_NAME,
it.UpdateBy,
it.UpdateTime,
it.UpdateUserName
}).ExecuteCommandAsync();
}
}
result.succ = true;
result.msg = "执行成功";
}
catch (Exception ex)
{
result.succ = false;
result.msg = ex.Message;
}
return result;
}
/// <summary>
/// 完成任务(可批量)
/// </summary>
/// <param name="ids">任务主键数组</param>
/// <returns>返回结果</returns>
public async Task<DataResult<TaskManageOrderResultDto>> CompleteTask(long[] ids)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
var userId = long.Parse(user.UserId);
string batchNo = Guid.NewGuid().ToString();
var taskList = await tenantDb.Queryable<TaskBaseInfo>().ClearFilter(typeof(IOrgId))
.Where(x => ids.Contains(x.Id)).ToListAsync();
List<TaskManageOrderResultDto> taskRunList = new List<TaskManageOrderResultDto>();
logger.LogInformation("批次={no} ids={ids} 完成任务开始", batchNo, string.Join(",", ids));
var noList = ids.Select((a, idx) => new { no = idx + 1, id = a }).ToList();
foreach (var bk in taskList)
{
var sortNo = noList.FirstOrDefault(a => a.id == bk.Id).no;
taskRunList.Add(await InnerManualTask(batchNo, bk, TaskOperTypeEnum.COMPLETE_TASK, sortNo));
}
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 += " -";
}
return DataResult<TaskManageOrderResultDto>.Success(result);
}
4 months ago
/// <summary>
/// 设置条件的方法,用于<see cref="GetPageAsync(PageRequest{QueryTaskManageDto})"/>
4 months ago
/// </summary>
private void SetCondition<T>(ISugarQueryable<TaskBaseInfo, TaskBaseAllocation, T> queryable,
List<IConditionalModel>? whereList,
TaskBaseTypeEnum? taskType,
4 months ago
TaskStatLevelEnum? taskStatLevel,
QueryTaskManageDto queryTaskManageDto,
long userId)
4 months ago
{
queryable.ClearFilter(typeof(IOrgId))
.Where(whereList)
.Where((t, a) => t.STATUS != TaskStatusEnum.Cancel.ToString())
.WhereIF(taskType != null, (t, a) => t.TASK_TYPE == taskType.ToString())
.WhereIF(!string.IsNullOrEmpty(queryTaskManageDto.BusinessNo), (t, a) => t.MBL_NO == queryTaskManageDto.BusinessNo || t.CUSTOMER_NO == queryTaskManageDto.BusinessNo)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1 && t.STATUS == queryTaskManageDto.Status)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0
&& (a.UserId == userId) // 2024-8-14 只显示自己需要审批的任务自己创建的任务不显示所以去掉t.CreateBy == userId ||
&& a.Status == queryTaskManageDto.Status)
.OrderByDescending(t => t.Id);
4 months ago
}
/// <summary>
/// 设置条件的方法,用于<see cref="GetPageAsync(PageRequest{QueryTaskManageDto})"/>
4 months ago
/// </summary>
private void SetCondition(ISugarQueryable<TaskBaseInfo, TaskBaseAllocation> queryable,
List<IConditionalModel>? whereList,
TaskBaseTypeEnum? taskType,
4 months ago
TaskStatLevelEnum? taskStatLevel,
QueryTaskManageDto queryTaskManageDto,
long userId)
4 months ago
{
queryable.ClearFilter(typeof(IOrgId))
.Where(whereList)
.Where((t, a) => t.STATUS != TaskStatusEnum.Cancel.ToString())
4 months ago
.WhereIF(taskType != null, (t, a) => t.TASK_TYPE == taskType.ToString())
.WhereIF(!string.IsNullOrEmpty(queryTaskManageDto.BusinessNo), (t, a) => t.MBL_NO == queryTaskManageDto.BusinessNo || t.CUSTOMER_NO == queryTaskManageDto.BusinessNo)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PUBLIC, (t, a) => t.IS_PUBLIC == 1 && t.STATUS == queryTaskManageDto.Status)
.WhereIF(taskStatLevel == TaskStatLevelEnum.PERSON, (t, a) => t.IS_PUBLIC == 0
&& (a.UserId == userId) // 2024-8-14 只显示自己需要审批的任务自己创建的任务不显示所以去掉t.CreateBy == userId ||
&& a.Status == queryTaskManageDto.Status)
.OrderByDescending(t => t.Id);
4 months ago
}
4 months ago
#region 根据收货地港口英文名解析出起始港对象
/// <summary>
/// 根据收货地港口英文名解析出起始港对象
/// </summary>
/// <param name="portEnName">收货地港口英文名</param>
/// <param name="cachePortLoad">起始港缓存</param>
/// <param name="cacheMapPortLoadFunc">起始港缓存映射</param>
/// <returns>起始港对象</returns>
private async Task<DataResult<CodePortRes>> PlaceReceiptToPortload(string portEnName, List<CodePortRes> cachePortLoad, Func<Task<DataResult<List<MappingPortRes>>>> cacheMapPortLoadFunc)
{
CodePortRes portInfo = null;
if (string.IsNullOrEmpty(portEnName))
{
return DataResult<CodePortRes>.FailedData(portInfo);
}
// 匹配方式1精准匹配
portInfo = cachePortLoad.FirstOrDefault(x => x.PortName.Equals(portEnName, StringComparison.OrdinalIgnoreCase));
if (portInfo != null) return DataResult<CodePortRes>.Success(portInfo);
// 匹配方式2起始模糊匹配
portInfo = cachePortLoad.FirstOrDefault(x => x.PortName.StartsWith(portEnName, StringComparison.OrdinalIgnoreCase));
if (portInfo != null) return DataResult<CodePortRes>.Success(portInfo);
// 匹配方式3完整模糊匹配
portInfo = cachePortLoad.FirstOrDefault(x => x.PortName.Contains(portEnName, StringComparison.OrdinalIgnoreCase));
if (portInfo != null) return DataResult<CodePortRes>.Success(portInfo);
// 匹配方式4精准映射匹配
var mapCachePortLoad = await cacheMapPortLoadFunc();
var map = mapCachePortLoad.Data.FirstOrDefault(x => x.Module == MappingModuleConst.RECEIPT_TO_PORTLOAD
&& x.MapName.Equals(portEnName, StringComparison.OrdinalIgnoreCase));
if (map != null)
{
portInfo = cachePortLoad.FirstOrDefault(x => x.Id == map.LinkId);
if (portInfo != null) return DataResult<CodePortRes>.Success(portInfo);
}
return DataResult<CodePortRes>.FailedData(portInfo);
}
4 months ago
/// <summary>
/// 测试用
/// </summary>
public async Task<DataResult> TestTaskFlow(string taskType, long taskId, int testType)
{
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
4 months ago
switch (testType)
{
4 months ago
// 任务编排执行测试
case 1:
{
var taskTypeEnum = (TaskBaseTypeEnum)Enum.Parse(typeof(TaskBaseTypeEnum), taskType);
TaskManageOrderMessageInfo p1 = new TaskManageOrderMessageInfo()
{
Main = new TaskManageOrderMessageMainInfo()
{
BCInfo = new TaskManageOrderBCInfo()
{
Vessel = "TESTVESSEL"
}
}
};
TaskFlowDataContext dataContext = new(
((TaskFlowDataNameConst.TaskManageOrderMessageInfo), p1),
(("Name"), "QD-ZXF"),
(("Age"), 19),
(("Height"), 160)
);
TaskFlowRuner taskFlow = new TaskFlowRuner(tenantDb, serviceProvider);
await taskFlow.Run(taskTypeEnum, taskId, dataContext);
break;
}
// 分配测试
case 2:
{
4 months ago
var order = await tenantDb.Queryable<SeaExport>().Select<Core.Op.Dtos.SeaExportRes>().FirstAsync(x => x.Id == 1816649497120477184);
TaskFlowDataContext dataContext2 = new(
(TaskFlowDataNameConst.Business, order)
);
var taskAllocationService = serviceProvider.GetRequiredService<ITaskAllocationService>();
var result = await taskAllocationService.GetAllotUserBySeaExportId(new List<TaskBaseTypeEnum>() {
TaskBaseTypeEnum.INVOICE_BILL_MAIL,
TaskBaseTypeEnum.NOT_LOADED,
TaskBaseTypeEnum.NOT_SHIPMENG,
}, 1816649497120477184, dataContext2);
break;
}
4 months ago
// 工作流获取下一节点测试
case 3:
{
var order = await tenantDb.Queryable<SeaExport>().Select<Core.Op.Dtos.SeaExportRes>().FirstAsync(x => x.Id == 1816649497120477184);
TaskFlowDataContext dataContext = new(
(TaskFlowDataNameConst.Business, order)
//("hasCabin", "false")
4 months ago
);
TaskFlowRuner runer = new TaskFlowRuner(tenantDb, serviceProvider);
var result22 = await runer.GetWorkFlowNextConfigByTaskType(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, TaskBaseTypeEnum.WAIT_BOOKING); // 正常
break;
}
// 判断条件测试
case 4:
{
logger.LogInformation("fdfdfd");
var condition = await tenantDb.Queryable<TaskFlowCondition>().FirstAsync(x => x.Id == 4001);
if (condition != null)
{
var conditionContent = JsonConvert.DeserializeObject<ConditionContent>(condition.Content!);
TaskManageOrderMessageInfo p1 = new TaskManageOrderMessageInfo()
{
Main = new TaskManageOrderMessageMainInfo()
{
BCInfo = new TaskManageOrderBCInfo()
{
Vessel = "ZXF"
}
}
};
int? A3 = 19;
long? A4 = 19;
long A5 = 19;
bool? B3 = true;
TaskFlowDataContext dataContext = new(
(("A1"), 19),
(("A2"), null),
(("A3"), A3),
(("A4"), A4),
(("A5"), A5),
(("B1"), true),
(("B2"), "true"),
(("B3"), B3),
(("B4"), null),
(("C1"), DateTime.Now),
(("C2"), new DateTime(2022, 2, 2, 2, 2, 2)),
(("C3"), "2022-2-2 2:2:2"),
(("C4"), "2022-2-2"),
(("C5"), null),
(("D1"), "ZXF"),
(("D2"), ""),
(("D3"), null),
((TaskFlowDataNameConst.TaskManageOrderMessageInfo), p1)
);
var a = ConditionHelper.IsPass(conditionContent, dataContext);
}
4 months ago
break;
}
}
return DataResult.Successed("测试成功");
}
4 months ago
#endregion
}
}