using DS.Module.Core;
using DS.Module.RedisModule;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core.Code.Interface;
using DS.WMS.Core.Code.Method;
using DS.WMS.Core.Map.Interface;
using DS.WMS.Core.Map.Method;
using DS.WMS.Core.Sys.Interface;
using DS.WMS.Core.Sys.Method;
using DS.WMS.Core.TaskPlat.Dtos;
using DS.WMS.Core.TaskPlat.Entity;
using DS.WMS.Core.TaskPlat.Interface;
using Microsoft.Extensions.DependencyInjection;
using NLog;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mapster;
using DS.Module.DjyServiceStatus;
using Microsoft.AspNetCore.Identity;
namespace DS.WMS.Core.TaskPlat.Method
{
///
/// 截止时间变更
///
public class TaskManageCutDateChangeService: ITaskManageCutDateChangeService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public TaskManageCutDateChangeService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService();
user = _serviceProvider.GetRequiredService();
saasService = _serviceProvider.GetRequiredService();
}
#region 通过任务主键获取截止时间变更详情
///
/// 通过任务主键获取截止时间变更详情
///
/// 截止时间变更任务主键
/// 返回回执
public async Task>> GetInfoByTaskId(long taskPKId)
{
List list = new List();
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var queryList = await tenantDb.Queryable()
.InnerJoin((a, b) => a.Id == b.TASK_ID)
.Where((a, b) => a.Id == taskPKId)
.Select((a, b) => new { Base = a, Cut = b })
.ToListAsync();
//任务主键{taskPkId}无法获取业务信息
if (queryList.Count == 0)
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskBaseInfoFromTaskIdNull)), taskPKId));
var parentIdList = queryList.Select(a => a.Cut.Id).ToList();
var detailList = await tenantDb.Queryable()
.Where(a => parentIdList.Contains(a.P_ID)).ToListAsync();
if (detailList.Count > 0)
{
list = detailList.OrderBy(p => p.MBL_NO).Select(p =>
{
TaskCutDateChangeShowDto model = p.Adapt();
model.NoticeDate = queryList.FirstOrDefault().Cut.NOTICE_DATE;
model.Carrier = queryList.FirstOrDefault().Cut.CARRIER;
return model;
}).ToList();
}
return DataResult>.Success(list);
}
#endregion
#region 检索对应的订舱订单并保存订舱ID
///
/// 检索对应的订舱订单并保存订舱ID
///
/// 截止时间变更任务主键
/// 返回回执
public async Task SearchAndMarkBookingOrder(long taskPKId)
{
try
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var queryList = await tenantDb.Queryable()
.InnerJoin((a, b) => a.Id == b.TASK_ID)
.Where((a, b) => a.Id == taskPKId)
.Select((a, b) => new { Base = a, Cut = b })
.ToListAsync();
//调取海运出口的检索匹配订单方法
//通过船名航次取是主单的订舱记录列表
//var bookingInfo = _bookingOrderRepository.AsQueryable().Filter(null, true).First(a => a.MBLNO == entityInfo.MBL_NO
// && a.IsDeleted == false && (a.ParentId == null || a.ParentId == 0) && a.TenantId == UserManager.TENANT_ID);
//if (bookingInfo != null)
//{
// entityInfo.BOOKING_ID = bookingInfo.Id;
// entityInfo.UpdatedTime = DateTime.Now;
// entityInfo.UpdatedUserId = UserManager.UserId;
// entityInfo.UpdatedUserName = UserManager.Name;
// await _taskCutDateChangeInfoRepository.AsUpdateable(entityInfo).UpdateColumns(x => new
// {
// x.BOOKING_ID,
// x.UpdatedTime,
// x.UpdatedUserId,
// x.UpdatedUserName
// }).ExecuteCommandAsync();
// var list = _taskCutDateChangeDetailInfoRepository.AsQueryable().Filter(null, true).Where(a => a.P_ID == entityInfo.PK_ID).ToList();
// if (list != null && list.Count > 0)
// {
// list.ForEach(async p =>
// {
// if (p.MBL_NO.Equals(entityInfo.MBL_NO, StringComparison.OrdinalIgnoreCase))
// {
// p.BOOKING_ID = bookingInfo.Id;
// p.UpdatedTime = DateTime.Now;
// p.UpdatedUserId = UserManager.UserId;
// p.UpdatedUserName = UserManager.Name;
// await _taskCutDateChangeDetailInfoRepository.AsUpdateable(p).UpdateColumns(x => new
// {
// x.BOOKING_ID,
// x.UpdatedTime,
// x.UpdatedUserId,
// x.UpdatedUserName
// }).ExecuteCommandAsync();
// }
// });
// }
// result.succ = true;
// result.msg = "检索对应成功";
//}
//else
//{
// result.succ = false;
// result.msg = $"检索对应失败,提单号:{entityInfo.MBL_NO} 没有对应的订舱记录";
//}
}
catch (Exception ex)
{
//result.succ = false;
//result.msg = $"检索失败,原因:{ex.Message}";
//_logger.LogInformation($"taskPKId={taskPKId} 检索截止时间变更订舱记录 处理异常,原因:{ex.Message}");
}
return null;
}
#endregion
#region 发送邮件通知给客户
///
/// 发送邮件通知给客户
///
/// 截止时间变更主键
/// 返回回执
public async Task SendEmailToCustomer(long taskPKId)
{
return null;
}
#endregion
}
}