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.

1523 lines
69 KiB
C#

using DS.Module.Core;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core.Op.Dtos;
using DS.WMS.Core.Op.Interface;
using DS.WMS.Core.Sys.Interface;
using DS.WMS.Core.TaskPlat.Dtos;
using DS.WMS.Core.TaskPlat.Entity;
using DS.WMS.Core.TaskPlat.Interface;
using LanguageExt.Common;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using NLog;
using NPOI.SS.Formula.Functions;
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 DS.WMS.Core.Op.Entity;
using Microsoft.AspNetCore.Mvc;
using NPOI.HPSF;
using DS.WMS.Core.Invoice.Dtos;
using DS.WMS.Core.Op.Method;
using DS.WMS.Core.Code.Interface;
using DS.WMS.Core.Map.Interface;
using LanguageExt;
using Microsoft.Extensions.FileSystemGlobbing.Internal.PathSegments;
using Newtonsoft.Json;
using System.Net.Http.Headers;
using DS.Module.Core.Data;
namespace DS.WMS.Core.TaskPlat.Method
{
public class TaskManageSISubmittedService: ITaskManageSISubmittedService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
private readonly ISeaExportService _seaExportService;
private readonly IConfigService _configService;
private readonly IUserService _userService;
private readonly IDjyServiceStatusService _djyServiceStatusService;
private readonly ITaskManageBaseService _taskManageBaseService;
private readonly ISysFileService _sysFileService;
private readonly IOpFileService _opFileService;
private readonly ISeaExportCommonService _seaExportCommonService;
private readonly ICodeIssueTypeService _codeIssueTypeService;
private readonly IMappingIssueTypeService _mappingIssueTypeService;
//租户SI回执是否自动更新订舱
const string CONST_SI_SUBMITTED_DEFAULT_PARAM = "SI_SUBMITTED_AUTO_UPDATE_ORDER";
private static readonly NLog.Logger Logger = LogManager.GetCurrentClassLogger();
public TaskManageSISubmittedService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
_seaExportService = _serviceProvider.GetRequiredService<ISeaExportService>();
_configService = _serviceProvider.GetRequiredService<IConfigService>();
_userService = _serviceProvider.GetRequiredService<IUserService>();
_djyServiceStatusService = _serviceProvider.GetRequiredService<IDjyServiceStatusService>();
_taskManageBaseService = _serviceProvider.GetRequiredService<ITaskManageBaseService>();
_opFileService = _serviceProvider.GetRequiredService<IOpFileService>();
_sysFileService = _serviceProvider.GetRequiredService<ISysFileService>();
_seaExportCommonService = _serviceProvider.GetRequiredService<ISeaExportCommonService>();
_codeIssueTypeService = _serviceProvider.GetRequiredService<ICodeIssueTypeService>();
_mappingIssueTypeService = _serviceProvider.GetRequiredService<IMappingIssueTypeService>();
}
#region 通过任务主键获取截单回执详情
/// <summary>
/// 通过任务主键获取截单回执详情
/// </summary>
/// <param name="taskPKId">截单回执任务主键</param>
/// <returns>返回回执</returns>
public async Task<DataResult<TaskSISubmittedShowDto>> GetInfoByTaskId(long taskPKId)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
//任务不考虑OrgId,这里去掉
tenantDb.QueryFilter.Clear<IOrgId>();
var queryList = await tenantDb.Queryable<TaskBaseInfo>()
.InnerJoin<TaskSiSubmitted>((a, b) => a.Id == b.TASK_ID)
.Where((a, b) => a.Id == taskPKId)
.Select((a, b) => new { Base = a, SI = b })
.ToListAsync();
//任务主键{taskPkId}无法获取业务信息
if (queryList.Count == 0)
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskBaseInfoFromTaskIdNull)), taskPKId));
var siSubmitted = queryList.FirstOrDefault().SI;
var taskBase = queryList.FirstOrDefault().Base;
var dto = siSubmitted.Adapt<TaskSISubmittedShowDto>();
if (dto != null)
{
dto.IsComplete = taskBase.IS_COMPLETE == 1 ? true : false;
dto.CompleteTime = taskBase.COMPLETE_DATE;
}
return DataResult<TaskSISubmittedShowDto>.Success(dto);
}
#endregion
#region 检索对应的订舱订单并保存订舱ID
/// <summary>
/// 检索对应的订舱订单并保存订舱ID
/// </summary>
/// <param name="taskPKId">截单回执任务主键</param>
/// <returns>返回回执</returns>
public async Task<DataResult<SeaExportOrderExtension>> SearchAndMarkBookingOrder(long taskPKId)
{
SeaExportOrderExtension orderInfo = null;
try
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
//任务不考虑OrgId,这里去掉
tenantDb.QueryFilter.Clear<IOrgId>();
var queryList = await tenantDb.Queryable<TaskBaseInfo>()
.InnerJoin<TaskCutDateChangeInfo>((a, b) => a.Id == b.TASK_ID)
.Where((a, b) => a.Id == taskPKId)
.Select((a, b) => new { Base = a, SI = b })
.ToListAsync();
//任务主键{taskPkId}无法获取业务信息
if (queryList.Count == 0)
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskBaseInfoFromTaskIdNull)), taskPKId));
string mblNo = queryList.FirstOrDefault().Base.MBL_NO;
var orderRlt = await _seaExportService.SearchOrderInfo(mblNo);
if (!orderRlt.Succeeded)
{
// 提单号 {0} 检索海运出口订单失败
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskBaseSearchOrderFailMBLNo)), mblNo));
}
orderInfo = orderRlt.Data;
foreach (var item in queryList.Select(a => a.SI).ToList())
{
item.BOOKING_ID = orderInfo.currOrder.Id;
item.UpdateTime = DateTime.Now;
item.UpdateBy = long.Parse(user.UserId);
item.UpdateUserName = user.UserName;
tenantDb.Updateable<TaskCutDateChangeInfo>(item).UpdateColumns(x => new
{
x.BOOKING_ID,
x.UpdateTime,
x.UpdateBy,
x.UpdateUserName
}).ExecuteCommand();
var list = tenantDb.Queryable<TaskCutDateChangeDetailInfo>().Where(a => a.P_ID == item.Id).ToList();
if (list != null && list.Count > 0)
{
list.ForEach(async p =>
{
if (p.MBL_NO.Equals(item.MBL_NO, StringComparison.OrdinalIgnoreCase))
{
p.BOOKING_ID = orderInfo.currOrder.Id;
p.UpdateTime = DateTime.Now;
p.UpdateBy = long.Parse(user.UserId);
p.UpdateUserName = user.UserName;
await tenantDb.Updateable<TaskCutDateChangeDetailInfo>(p).UpdateColumns(x => new
{
x.BOOKING_ID,
x.UpdateTime,
x.UpdateBy,
x.UpdateUserName
}).ExecuteCommandAsync();
}
});
}
}
}
catch (Exception ex)
{
Logger.Log(NLog.LogLevel.Info, $"taskPKId={taskPKId} 检索截单回执的订舱记录 处理异常,原因:{ex.Message}");
return DataResult<SeaExportOrderExtension>.FailedData(orderInfo, $"检索失败,原因:{ex.Message}", MultiLanguageConst.Operation_Failed);
}
return DataResult<SeaExportOrderExtension>.Success(orderInfo);
}
#endregion
#region 处理SI截单回执
/// <summary>
/// 处理SI截单回执
/// </summary>
/// <param name="taskPkId">截单回执任务主键</param>
/// <returns>返回回执</returns>
public async Task<DataResult> ProcessSISubmitted(long taskPkId)
{
bool result = false;
string msg = string.Empty;
TaskSiSubmitted siSubmitted = null;
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
//任务不考虑OrgId,这里去掉
tenantDb.QueryFilter.Clear<IOrgId>();
try
{
/*
1SI_SUBMITTED_AUTO_UPDATE_ORDER=ENABLE
2
3
4
*/
var queryList = await tenantDb.Queryable<TaskBaseInfo>()
.InnerJoin<TaskSiSubmitted>((a, b) => a.Id == b.TASK_ID)
.Where((a, b) => a.Id == taskPkId)
.Select((a, b) => new { Base = a, SI = b })
.ToListAsync();
var taskBaseInfo = queryList.FirstOrDefault().Base;
if (queryList.Count == 0)
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskBaseInfoFromTaskIdNull)), taskPkId));
siSubmitted = queryList.FirstOrDefault().SI;
//当前截单回执已有匹配的订舱订单
if (siSubmitted.BOOKING_ID.HasValue)
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskSISubmittedHasOrder)));
var paramConfig = _configService.GetConfig(CONST_SI_SUBMITTED_DEFAULT_PARAM, long.Parse(user.TenantId), false).GetAwaiter().GetResult()?.Data?.Value;
var siCtnList = tenantDb.Queryable<TaskSiSubmittedCtn>().Where(a => a.P_PKID == siSubmitted.Id).ToList();
var orderRlt = await _seaExportService.SearchOrderInfo(siSubmitted.MBL_NO);
if (!orderRlt.Succeeded)
{
// 提单号 {0} 检索海运出口订单失败
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskBaseSearchOrderFailMBLNo)), siSubmitted.MBL_NO));
}
var orderInfo = orderRlt.Data.currOrder;
var codeIssueTypeList = _codeIssueTypeService.GetAllList().GetAwaiter().GetResult()?.Data;
var mappingIssueTypeList = _mappingIssueTypeService.GetAllList().GetAwaiter().GetResult()?.Data;
if (!string.IsNullOrWhiteSpace(paramConfig) && paramConfig.Equals("ENABLE", StringComparison.OrdinalIgnoreCase))
{
siSubmitted.IS_SET_AUTO_UPD_BOOKING = true;
Logger.Log(NLog.LogLevel.Info, $"taskPkId={taskPkId} 提单号{siSubmitted.MBL_NO} 配置了自动更新订舱详情");
if (orderInfo != null)
{
Logger.Log(NLog.LogLevel.Info, $"taskPkId={taskPkId} 提单号{siSubmitted.MBL_NO} 获取了订舱详情完成 bookingid={orderInfo.Id}");
siSubmitted.BOOKING_ID = orderInfo.Id;
var ctnList = orderRlt.Data.currOrderCtnList.Adapt<List<OpCtnReq>>();
Logger.Log(NLog.LogLevel.Info, $"taskPkId={taskPkId} 提单号{siSubmitted.MBL_NO} 获取订舱集装箱列表完成 ctnnum={ctnList.Count}");
SIFeedBackCompareDto siSrcDto = orderInfo.Adapt<SIFeedBackCompareDto>();
if (ctnList.Count > 0)
{
siSrcDto.ContaList = ctnList.Select(t => new SIFeedBackCompareContaDto
{
ContaNo = t.CntrNo,
SealNo = t.SealNo,
ContaType = t.CtnCode,
ContaTypeName = t.CtnAll,
PKGS = t.PKGS.HasValue ? t.PKGS.Value : 0,
CBM = t.CBM,
KGS = t.KGS,
WeighType = t.WeightType == "累加" ? "ADD" : "ALL",
WeighKGS = t.WeightKGS
}).ToList();
}
SIFeedBackCompareDto siTargetDto = siSubmitted.Adapt<SIFeedBackCompareDto>();
if (siCtnList.Count > 0)
{
siTargetDto.ContaList = siCtnList.Select(t => new SIFeedBackCompareContaDto
{
ContaNo = t.CNTRNO,
SealNo = t.SEALNO,
ContaType = t.CTNCODE,
ContaTypeName = t.CTNALL,
PKGS = t.PKGS.HasValue ? t.PKGS.Value : 0,
CBM = t.CBM,
KGS = t.KGS,
WeighType = t.WEIGHTYPE,
WeighKGS = t.WEIGHKGS
}).ToList();
}
Logger.Log(NLog.LogLevel.Info, $"taskPkId={taskPkId} 提单号{siSubmitted.MBL_NO} 开始比对");
//更新前先比对一遍差异
var compareRlt = await PushCompareSIInfo(siSrcDto, siTargetDto, orderInfo.Id, taskPkId);
if (string.IsNullOrWhiteSpace(compareRlt.Item1))
{
siSubmitted.DIFF_NUM = compareRlt.Item2;
}
Logger.Log(NLog.LogLevel.Info, $"taskPkId={taskPkId} 提单号{siSubmitted.MBL_NO} 获取比对完成 结果={JsonConvert.SerializeObject(compareRlt)}");
SeaExportOpenEditReq bkModel = null;
Dictionary<string, Tuple<bool, string>> changeDict = new Dictionary<string, Tuple<bool, string>>();
if (orderInfo != null)
{
bkModel = new SeaExportOpenEditReq
{
Id = orderInfo.Id,
//MBLNO = orderInfo.MBLNO,
//ctnInputs = new List<BookingCtnDto>(),
//ChangedFields = new List<string>()
};
if (!string.IsNullOrEmpty(siSubmitted.ISSUETYPE))
{
string issueType = string.Empty;
if (siSubmitted.ISSUETYPE.Equals("seaway", StringComparison.OrdinalIgnoreCase))
{
//bkModel.ISSUETYPE = "seaway";
issueType = "Seaway Bill";
}
else if (siSubmitted.ISSUETYPE.Equals("telex", StringComparison.OrdinalIgnoreCase))
{
//bkModel.ISSUETYPE = "telex";
issueType = "Telex";
}
else if (siSubmitted.ISSUETYPE.Equals("original", StringComparison.OrdinalIgnoreCase))
{
//bkModel.ISSUETYPE = "original";
issueType = "Original";
}
var currMap = mappingIssueTypeList.FirstOrDefault(a => a.MapName.Equals(issueType));
if (currMap != null)
{
var codeIssue = codeIssueTypeList.FirstOrDefault(b => b.Id == currMap.LinkId);
if (codeIssue != null)
{
bkModel.IssueType = codeIssue.EnName;
}
}
if (string.IsNullOrWhiteSpace(bkModel.IssueType))
{
bkModel.IssueType = issueType;
}
changeDict.Add(nameof(bkModel.IssueType), new Tuple<bool, string>(true, issueType));
//bkModel.ChangedFields.Add(nameof(SaveBookingOrderInput.ISSUETYPE));
//bkModel.ChangedFields.Add(nameof(SaveBookingOrderInput.ISSUETYPE));
}
if (!string.IsNullOrEmpty(siSubmitted.SHIPPER))
{
bkModel.Shipper = siSubmitted.SHIPPER;
changeDict.Add(nameof(bkModel.Shipper), new Tuple<bool, string>(true, siSubmitted.SHIPPER));
//bkModel.ChangedFields.Add(nameof(SaveBookingOrderInput.SHIPPER));
}
if (!string.IsNullOrEmpty(siSubmitted.CONSIGNEE))
{
bkModel.Consignee = siSubmitted.CONSIGNEE;
changeDict.Add(nameof(bkModel.Consignee), new Tuple<bool, string>(true, siSubmitted.CONSIGNEE));
//bkModel.ChangedFields.Add(nameof(SaveBookingOrderInput.CONSIGNEE));
}
if (!string.IsNullOrEmpty(siSubmitted.NOTIFYPARTY))
{
bkModel.NotifyParty = siSubmitted.NOTIFYPARTY;
changeDict.Add(nameof(bkModel.NotifyParty), new Tuple<bool, string>(true, siSubmitted.NOTIFYPARTY));
//bkModel.ChangedFields.Add(nameof(SaveBookingOrderInput.NOTIFYPARTY));
}
if (!string.IsNullOrEmpty(siSubmitted.NOTIFYPARTY2))
{
bkModel.SecondNotifyParty = siSubmitted.NOTIFYPARTY2;
changeDict.Add(nameof(bkModel.SecondNotifyParty), new Tuple<bool, string>(true, siSubmitted.NOTIFYPARTY2));
//bkModel.ChangedFields.Add(nameof(SaveBookingOrderInput.NOTIFYPARTY2));
}
if (!string.IsNullOrEmpty(siSubmitted.KINDPKGS))
{
bkModel.KindPkgs = siSubmitted.KINDPKGS;
changeDict.Add(nameof(bkModel.KindPkgs), new Tuple<bool, string>(true, siSubmitted.KINDPKGS));
//bkModel.ChangedFields.Add(nameof(SaveBookingOrderInput.KINDPKGS));
}
if (!string.IsNullOrEmpty(siSubmitted.DESCRIPTION))
{
bkModel.Description = siSubmitted.DESCRIPTION;
changeDict.Add(nameof(bkModel.Description), new Tuple<bool, string>(true, siSubmitted.DESCRIPTION));
//bkModel.ChangedFields.Add(nameof(SaveBookingOrderInput.DESCRIPTION));
}
if (!string.IsNullOrEmpty(siSubmitted.HSCODE))
{
bkModel.HSCode = siSubmitted.HSCODE;
changeDict.Add(nameof(bkModel.HSCode), new Tuple<bool, string>(true, siSubmitted.HSCODE));
//bkModel.ChangedFields.Add(nameof(SaveBookingOrderInput.HSCODE));
}
if (!string.IsNullOrEmpty(siSubmitted.MARKS))
{
bkModel.Marks = siSubmitted.MARKS;
changeDict.Add(nameof(bkModel.Marks), new Tuple<bool, string>(true, siSubmitted.MARKS));
//bkModel.ChangedFields.Add(nameof(SaveBookingOrderInput.MARKS));
}
}
if (ctnList.Count > 0)
{
List<OpCtnReq> oddCtnList = new List<OpCtnReq>();
foreach (var ctn in ctnList)
{
if (!string.IsNullOrWhiteSpace(ctn.CtnCode) && string.IsNullOrWhiteSpace(ctn.CntrNo) && ctn.CtnNum > 1)
{
for (int i = 0; i < ctn.CtnNum - 1; i++)
{
oddCtnList.Add(new OpCtnReq
{
BSNO = orderInfo.Id.ToString(),
CtnCode = ctn.CtnCode,
CtnAll = ctn.CtnAll,
});
}
ctn.CtnNum = 1;
}
}
if (oddCtnList.Count > 0)
{
ctnList.AddRange(oddCtnList);
}
}
if (siCtnList.Count > 0)
{
bkModel.KGS = siCtnList.Sum(x => x.KGS.HasValue ? x.KGS.Value : 0);
changeDict.Add(nameof(bkModel.KGS), new Tuple<bool, string>(true, siSubmitted.KGS.HasValue? siSubmitted.KGS.Value.ToString():""));
//bkModel.ChangedFields.Add(nameof(SaveBookingOrderInput.KGS));
bkModel.PKGS = siCtnList.Sum(x => x.PKGS.HasValue ? x.PKGS.Value : 0);
changeDict.Add(nameof(bkModel.PKGS), new Tuple<bool, string>(true, siSubmitted.PKGS.HasValue ? siSubmitted.PKGS.Value.ToString() : ""));
//bkModel.ChangedFields.Add(nameof(SaveBookingOrderInput.PKGS));
bkModel.CBM = siCtnList.Sum(x => x.CBM.HasValue ? x.CBM.Value : 0);
changeDict.Add(nameof(bkModel.CBM), new Tuple<bool, string>(true, siSubmitted.CBM.HasValue ? siSubmitted.CBM.Value.ToString() : ""));
//bkModel.ChangedFields.Add(nameof(SaveBookingOrderInput.CBM));
siCtnList.ForEach(x =>
{
var ctn = ctnList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(x.CNTRNO) && !string.IsNullOrWhiteSpace(a.CntrNo)
&& a.CntrNo.Equals(x.CNTRNO, StringComparison.OrdinalIgnoreCase));
if (ctn != null)
{
ctn.CtnCode = x.CTNCODE;
ctn.CtnAll = x.CTNALL;
ctn.CtnNum = 1;
ctn.SealNo = x.SEALNO;
ctn.PKGS = x.PKGS;
ctn.KGS = x.KGS;
ctn.WeightType = x.WEIGHTYPE;
ctn.WeightKGS = x.WEIGHKGS;
ctn.CBM = x.CBM;
ctn.Remark += "SI Add";
//ctn.TenantId = UserManager.TENANT_ID;
//ctn.CreatedTime = DateTime.Now;
//ctn.CreatedUserId = UserManager.UserId;
//ctn.CreatedUserName = UserManager.Name;
ctn.KindPkgs = x.KINDPKGS;
if (string.IsNullOrWhiteSpace(x.KINDPKGS) && !string.IsNullOrWhiteSpace(siSubmitted.KINDPKGS))
ctn.KindPkgs = siSubmitted.KINDPKGS;
if (x.WEIGHKGS.HasValue && x.KGS.HasValue)
ctn.TareWeight = x.WEIGHKGS.Value - x.KGS.Value;
}
else
{
ctn = ctnList.FirstOrDefault(a => a.CtnCode == x.CTNCODE && string.IsNullOrWhiteSpace(a.CntrNo));
if (ctn != null)
{
ctn.CntrNo = x.CNTRNO;
ctn.CtnCode = x.CTNCODE;
ctn.CtnAll = x.CTNALL;
ctn.CtnNum = 1;
ctn.SealNo = x.SEALNO;
ctn.PKGS = x.PKGS;
ctn.KGS = x.KGS;
ctn.WeightType = x.WEIGHTYPE;
ctn.WeightKGS = x.WEIGHKGS;
ctn.CBM = x.CBM;
ctn.Remark += "SI Add";
//ctn.TenantId = UserManager.TENANT_ID;
//ctn.CreatedTime = DateTime.Now;
//ctn.CreatedUserId = UserManager.UserId;
//ctn.CreatedUserName = UserManager.Name;
ctn.KindPkgs = x.KINDPKGS;
if (string.IsNullOrWhiteSpace(x.KINDPKGS) && !string.IsNullOrWhiteSpace(siSubmitted.KINDPKGS))
ctn.KindPkgs = siSubmitted.KINDPKGS;
if (x.WEIGHKGS.HasValue && x.KGS.HasValue)
ctn.TareWeight = x.WEIGHKGS.Value - x.KGS.Value;
}
else
{
ctn = ctnList.FirstOrDefault(a => a.CtnAll == x.CTNALL && string.IsNullOrWhiteSpace(a.CntrNo));
if (ctn != null)
{
ctn.CntrNo = x.CNTRNO;
ctn.CtnCode = x.CTNCODE;
ctn.CtnAll = x.CTNALL;
ctn.CtnNum = 1;
ctn.SealNo = x.SEALNO;
ctn.PKGS = x.PKGS;
ctn.KGS = x.KGS;
ctn.WeightType = x.WEIGHTYPE;
ctn.WeightKGS = x.WEIGHKGS;
ctn.CBM = x.CBM;
ctn.Remark += "SI Add";
//ctn.TenantId = UserManager.TENANT_ID;
//ctn.CreatedTime = DateTime.Now;
//ctn.CreatedUserId = UserManager.UserId;
//ctn.CreatedUserName = UserManager.Name;
ctn.KindPkgs = x.KINDPKGS;
if (string.IsNullOrWhiteSpace(x.KINDPKGS) && !string.IsNullOrWhiteSpace(siSubmitted.KINDPKGS))
ctn.KindPkgs = siSubmitted.KINDPKGS;
if (x.WEIGHKGS.HasValue && x.KGS.HasValue)
ctn.TareWeight = x.WEIGHKGS.Value - x.KGS.Value;
}
else
{
ctnList.Add(new OpCtnReq
{
BSNO = orderInfo.Id.ToString(),
//IsDeleted = false,
//cre = DateTime.Now,
//UpdatedTime = DateTime.Now,
//CreatedUserId = UserManager.UserId,
//CreatedUserName = UserManager.Name,
//TenantId = UserManager.TENANT_ID,
CntrNo = x.CNTRNO,
CtnCode = x.CTNCODE,
CtnAll = x.CTNALL,
CtnNum = 1,
SealNo = x.SEALNO,
PKGS = x.PKGS,
KGS = x.KGS,
WeightType = x.WEIGHTYPE,
WeightKGS = x.WEIGHKGS,
CBM = x.CBM,
Remark = "SI Add",
TareWeight = x.WEIGHKGS.HasValue && x.KGS.HasValue ? x.WEIGHKGS.Value - x.KGS.Value : 0,
KindPkgs = (string.IsNullOrWhiteSpace(x.KINDPKGS) && !string.IsNullOrWhiteSpace(siSubmitted.KINDPKGS)) ? siSubmitted.KINDPKGS : x.KINDPKGS,
});
}
}
}
});
if (ctnList.Any(t => string.IsNullOrWhiteSpace(t.Remark) || t.Remark.IndexOf("SI Add") < 0))
{
ctnList = ctnList.Where(t => !string.IsNullOrWhiteSpace(t.Remark) && t.Remark.IndexOf("SI Add") >= 0).ToList();
}
}
if (ctnList.Count > 0)
{
bkModel.CtnList = ctnList.Select(t => new OpCtnReq
{
BSNO = t.BSNO,
CntrNo = t.CntrNo,
CtnAll = t.CtnAll,
CtnCode = t.CtnCode,
CtnNum = t.CtnNum,
CBM = t.CBM.HasValue ? t.CBM.Value : 0,
KindPkgs = t.KindPkgs,
PKGS = t.PKGS.HasValue ? t.PKGS.Value : 0,
SealNo = t.SealNo,
KGS = t.KGS.HasValue ? t.KGS.Value : 0,
TareWeight = t.TareWeight.HasValue ? t.TareWeight.Value : 0,
WeightKGS = t.WeightKGS.HasValue ? t.WeightKGS.Value : 0,
WeightType = t.WeightType,
Id = t.Id,
}).ToList();
}
Logger.Log(NLog.LogLevel.Info, $"taskPkId={taskPkId} 提单号{siSubmitted.MBL_NO} 准备更新订舱数据完更");
//更新订舱数据
var bkRlt = await _seaExportCommonService.SeaExportOpenEdit(bkModel);
if (bkRlt.Succeeded)
{
Logger.Log(NLog.LogLevel.Info, $"taskPkId={taskPkId} 提单号{siSubmitted.MBL_NO} 更新订舱数据成功");
//推送截单货物状态
var pushModel = new EmbedServiceProjectStatusDto
{
businessId = bkModel.Id.ToString(),
SourceType = 1,
StatusCodes = new List<EmbedServiceProjectStatusDetailDto> {
new EmbedServiceProjectStatusDetailDto{
StatusCode = "JD"
}
}
};
if (siSubmitted.NOTICE_DATE.HasValue)
{
pushModel.StatusCodes[0].SetActDate = siSubmitted.NOTICE_DATE.Value;
}
var saveStatusRlt = await _djyServiceStatusService.SaveServiceStatus(pushModel);
Logger.Log(NLog.LogLevel.Info, $"taskPkId={taskPkId} 提单号{siSubmitted.MBL_NO} 推送截单状态完成 结果={JsonConvert.SerializeObject(saveStatusRlt)}");
siSubmitted.PROCESS_STATUS = "SUCC";
siSubmitted.PROCESS_DATE = DateTime.Now;
siSubmitted.IS_UPDATE_BOOKING = true;
siSubmitted.UPDATE_BOOKING_DATE = DateTime.Now;
//直接完成SI的回执任务
if (taskBaseInfo.IS_PUBLIC == 1)
{
await _taskManageBaseService.SetTaskOwner(new long[] { taskBaseInfo.Id }, new List<RecvUserInfo> {
new RecvUserInfo{
RecvUserId = orderInfo.OperatorId,
RecvUserName = orderInfo.OperatorName,
}
});
//更新任务的状态
taskBaseInfo.IS_COMPLETE = 1;
taskBaseInfo.COMPLETE_DEAL = "AUTO";
taskBaseInfo.COMPLETE_DEAL_NAME = "自动";
taskBaseInfo.COMPLETE_DATE = DateTime.Now;
taskBaseInfo.UpdateTime = DateTime.Now;
taskBaseInfo.UpdateBy = orderInfo.OperatorId;
taskBaseInfo.UpdateUserName = orderInfo.OperatorName;
await tenantDb.Updateable<TaskBaseInfo>(taskBaseInfo).UpdateColumns(it => new {
it.IS_COMPLETE,
it.COMPLETE_DEAL,
it.COMPLETE_DEAL_NAME,
it.COMPLETE_DATE,
it.UpdateTime,
it.UpdateBy,
it.UpdateUserName
}).ExecuteCommandAsync();
}
else
{
taskBaseInfo.IS_COMPLETE = 1;
taskBaseInfo.COMPLETE_DEAL = "AUTO";
taskBaseInfo.COMPLETE_DEAL_NAME = "自动";
taskBaseInfo.COMPLETE_DATE = DateTime.Now;
taskBaseInfo.UpdateTime = DateTime.Now;
taskBaseInfo.UpdateBy = taskBaseInfo.CreateBy;
taskBaseInfo.UpdateUserName = taskBaseInfo.CreateUserName;
//更新任务台,将当前任务变更为个人任务
await tenantDb.Updateable<TaskBaseInfo>(taskBaseInfo).UpdateColumns(it => new {
it.IS_COMPLETE,
it.COMPLETE_DEAL,
it.COMPLETE_DEAL_NAME,
it.COMPLETE_DATE,
it.UpdateTime,
it.UpdateBy,
it.UpdateUserName
}).ExecuteCommandAsync();
}
/*
1
2
*/
var fileList = tenantDb.Queryable<TaskFileInfo>().Where(a => a.TASK_PKID == taskPkId).ToList();
//_opFileService.GetOpFileDownLoad();
////处理附件
//var opt = App.GetOptions<BookingAttachOptions>();
//var dirAbs = opt.basePath;
//if (string.IsNullOrEmpty(dirAbs))
//{
// dirAbs = App.WebHostEnvironment.WebRootPath;
//}
string batchNo = SnowFlakeSingle.Instance.NextId().ToString();
//var fileList = _taskFileRepository.AsQueryable().Filter(null, true)
fileList.ForEach(file =>
{
if (file.FILE_CATEGORY == TaskFileCategoryEnum.SI_SUBMITTED.ToString())
{
var currFile = _opFileService.GetOpFileDownLoad(file.Id.ToString()).Data;
var fileFullPath = currFile.FilePath;
if (File.Exists(fileFullPath))
{
//如果确认文件读取成功
var bookFilePath = _sysFileService.MoveFile(bkModel.Id.ToString(), fileFullPath, batchNo
, false, null, true).GetAwaiter().GetResult();
//将格式单附件写入订舱的附件
SaveEDIFile(bkModel.Id, fileFullPath, currFile.FileName, 0, 0).GetAwaiter();
}
}
});
Logger.Log(NLog.LogLevel.Info, $"taskPkId={taskPkId} 提单号{siSubmitted.MBL_NO} 上传订舱数据附件完成");
result = true;
msg = "处理成功";
Logger.Log(NLog.LogLevel.Info, $"taskPkId={taskPkId} 提单号{siSubmitted.MBL_NO} 更新完成");
}
else
{
siSubmitted.PROCESS_STATUS = "FAILURE";
siSubmitted.PROCESS_DATE = DateTime.Now;
siSubmitted.PROCESS_RESULT = "更新订舱信息失败";
siSubmitted.UPDATE_BOOKING_DATE = DateTime.Now;
result = false;
msg = "处理失败";
Logger.Log(NLog.LogLevel.Info, $"taskPkId={taskPkId} 提单号{siSubmitted.MBL_NO} 处理失败");
}
}
else
{
result = false;
msg = $"提单号{siSubmitted.MBL_NO} 检索订舱数据失败";
Logger.Log(NLog.LogLevel.Info, $"taskPkId={taskPkId} 提单号{siSubmitted.MBL_NO} 检索订舱数据失败");
}
}
else
{
result = false;
msg = "当前租户没开通自动SI回执是否自动更新订舱";
siSubmitted.IS_SET_AUTO_UPD_BOOKING = false;
//将文件同步到订舱的附件
if (orderInfo != null)
{
//推送截单货物状态
var pushModel = new EmbedServiceProjectStatusDto
{
businessId = orderInfo.Id.ToString(),
SourceType = 1,
StatusCodes = new List<EmbedServiceProjectStatusDetailDto> {
new EmbedServiceProjectStatusDetailDto{
StatusCode = "JD"
}
}
};
if (siSubmitted.NOTICE_DATE.HasValue)
{
pushModel.StatusCodes[0].SetActDate = siSubmitted.NOTICE_DATE.Value;
}
var saveStatusRlt = await _djyServiceStatusService.SaveServiceStatus(pushModel);
Logger.Log(NLog.LogLevel.Info, $"taskPkId={taskPkId} 提单号{siSubmitted.MBL_NO} 推送截单状态完成 结果={JsonConvert.SerializeObject(saveStatusRlt)}");
siSubmitted.PROCESS_STATUS = "SUCC";
siSubmitted.PROCESS_DATE = DateTime.Now;
siSubmitted.IS_UPDATE_BOOKING = true;
siSubmitted.UPDATE_BOOKING_DATE = DateTime.Now;
//直接完成SI的回执任务
if (taskBaseInfo.IS_PUBLIC == 1)
{
await _taskManageBaseService.SetTaskOwner(new long[] { taskBaseInfo.Id }, new List<RecvUserInfo> {
new RecvUserInfo{
RecvUserId = orderInfo.OperatorId,
RecvUserName = orderInfo.OperatorName,
}
});
//更新任务的状态
taskBaseInfo.IS_COMPLETE = 1;
taskBaseInfo.COMPLETE_DEAL = "AUTO";
taskBaseInfo.COMPLETE_DEAL_NAME = "自动";
taskBaseInfo.COMPLETE_DATE = DateTime.Now;
taskBaseInfo.UpdateTime = DateTime.Now;
taskBaseInfo.UpdateBy = orderInfo.OperatorId;
taskBaseInfo.UpdateUserName = orderInfo.OperatorName;
await tenantDb.Updateable<TaskBaseInfo>(taskBaseInfo).UpdateColumns(it => new {
it.IS_COMPLETE,
it.COMPLETE_DEAL,
it.COMPLETE_DEAL_NAME,
it.COMPLETE_DATE,
it.UpdateTime,
it.UpdateBy,
it.UpdateUserName
}).ExecuteCommandAsync();
}
else
{
taskBaseInfo.IS_COMPLETE = 1;
taskBaseInfo.COMPLETE_DEAL = "AUTO";
taskBaseInfo.COMPLETE_DEAL_NAME = "自动";
taskBaseInfo.COMPLETE_DATE = DateTime.Now;
taskBaseInfo.UpdateTime = DateTime.Now;
taskBaseInfo.UpdateBy = taskBaseInfo.CreateBy;
taskBaseInfo.UpdateUserName = taskBaseInfo.CreateUserName;
//更新任务台,将当前任务变更为个人任务
await tenantDb.Updateable<TaskBaseInfo>(taskBaseInfo).UpdateColumns(it => new {
it.IS_COMPLETE,
it.COMPLETE_DEAL,
it.COMPLETE_DEAL_NAME,
it.COMPLETE_DATE,
it.UpdateTime,
it.UpdateBy,
it.UpdateUserName
}).ExecuteCommandAsync();
}
var fileList = tenantDb.Queryable<TaskFileInfo>().Where(a => a.TASK_PKID == taskPkId).ToList();
//_opFileService.GetOpFileDownLoad();
////处理附件
//var opt = App.GetOptions<BookingAttachOptions>();
//var dirAbs = opt.basePath;
//if (string.IsNullOrEmpty(dirAbs))
//{
// dirAbs = App.WebHostEnvironment.WebRootPath;
//}
string batchNo = SnowFlakeSingle.Instance.NextId().ToString();
//var fileList = _taskFileRepository.AsQueryable().Filter(null, true)
fileList.ForEach(file =>
{
if (file.FILE_CATEGORY == TaskFileCategoryEnum.SI_SUBMITTED.ToString())
{
var currFile = _opFileService.GetOpFileDownLoad(file.Id.ToString()).Data;
var fileFullPath = currFile.FilePath;
if (File.Exists(fileFullPath))
{
//如果确认文件读取成功
var bookFilePath = _sysFileService.MoveFile(orderInfo.Id.ToString(), fileFullPath, batchNo
, false, null, true).GetAwaiter().GetResult();
//将格式单附件写入订舱的附件
SaveEDIFile(orderInfo.Id, fileFullPath, currFile.FileName, 0, 0).GetAwaiter();
}
}
});
Logger.Log(NLog.LogLevel.Info, $"taskPkId={taskPkId} 提单号{siSubmitted.MBL_NO} 上传订舱数据附件完成");
result = true;
msg = "处理成功";
Logger.Log(NLog.LogLevel.Info, $"taskPkId={taskPkId} 提单号{siSubmitted.MBL_NO} 更新完成");
}
else
{
result = false;
msg = $"提单号{siSubmitted.MBL_NO} 检索订舱数据失败";
Logger.Log(NLog.LogLevel.Info, $"taskPkId={taskPkId} 提单号{siSubmitted.MBL_NO} 检索订舱数据失败");
}
}
}
catch (Exception ex)
{
result = false;
msg = ex.Message;
}
if (!result)
{
if (siSubmitted != null)
{
siSubmitted.PROCESS_STATUS = "FAILURE";
siSubmitted.PROCESS_DATE = DateTime.Now;
if (msg.Length > 500)
{
siSubmitted.PROCESS_RESULT = msg.Substring(0, 500);
}
else
{
siSubmitted.PROCESS_RESULT = msg;
}
await tenantDb.Updateable<TaskSiSubmitted>(siSubmitted).UpdateColumns(x => new
{
x.PROCESS_DATE,
x.PROCESS_STATUS,
x.PROCESS_RESULT,
x.DIFF_NUM,
x.IS_SET_AUTO_UPD_BOOKING,
}).ExecuteCommandAsync();
//new EmailNoticeHelper().SendEmailNotice($"MBLNO={siSubmitted.MBL_NO} SI回执回写失败", $"MBLNO={siSubmitted.MBL_NO} SI回执回写失败原因{result.msg}", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList());
}
return DataResult.Failed(msg);
}
else
{
await tenantDb.Updateable<TaskSiSubmitted>(siSubmitted).UpdateColumns(x => new
{
x.PROCESS_DATE,
x.PROCESS_STATUS,
x.PROCESS_RESULT,
x.IS_UPDATE_BOOKING,
x.UPDATE_BOOKING_DATE,
x.DIFF_NUM,
x.BOOKING_ID,
x.IS_SET_AUTO_UPD_BOOKING
}).ExecuteCommandAsync();
return DataResult.Successed(msg);
}
}
#endregion
#region 推送BC变更比对
/// <summary>
/// 推送BC变更比对sysUser
/// </summary>
/// <param name="siSrcDto">订舱详情</param>
/// <param name="siTargetDto">SI截单详情</param>
/// <param name="bookingId">订舱主键</param>
/// <param name="taskPKId">任务ID</param>
/// <returns></returns>
[NonAction]
public async Task<Tuple<string, int>> PushCompareSIInfo(SIFeedBackCompareDto siSrcDto, SIFeedBackCompareDto siTargetDto, long bookingId, long taskPKId)
{
string result = string.Empty;
int diffNum = 0;
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
string batchNo = SnowFlakeSingle.Instance.NextId().ToString();
DateTime bDate = DateTime.Now;
var compareResult = await ExcuteCompare(siSrcDto, siTargetDto);
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
if (compareResult != null)
{
Logger.Log(NLog.LogLevel.Info, "批次={no} 请求完成,耗时:{timeDiff}ms. 结果{msg}", batchNo, timeDiff, compareResult.succ ? "成功" : "失败");
if (!compareResult.succ)
{
result = $"比对失败,原因:{compareResult.msg}";
}
}
if (compareResult != null)
{
DateTime nowDate = DateTime.Now;
var hisInfo = tenantDb.Queryable<BusinessCompareDiffRecord>().First(a =>
a.BUSI_ID == bookingId.ToString() && a.TASK_ID == taskPKId);
if (hisInfo == null)
{
BusinessCompareDiffRecord entity = new BusinessCompareDiffRecord
{
BUSI_ID = bookingId.ToString(),
TASK_ID = taskPKId,
BUSI_TYPE = "SI_SUBMITTED",
COMPARE_DIFF_NUM = compareResult.extra.IsExistsDiff ? compareResult.extra.ShowDetailList.Count : 0,
CreateTime = nowDate,
UpdateTime = nowDate,
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
UpdateBy = long.Parse(user.UserId),
UpdateUserName = user.UserName,
COMPARE_TYPE = "SI_MODIFY",
COMPARE_RLT = JsonConvert.SerializeObject(compareResult.extra.ShowDetailList),
};
await tenantDb.Insertable<BusinessCompareDiffRecord>(entity).ExecuteCommandAsync();
}
else
{
hisInfo.COMPARE_DIFF_NUM = compareResult.extra.IsExistsDiff ? compareResult.extra.ShowDetailList.Count : 0;
hisInfo.UpdateTime = nowDate;
hisInfo.UpdateBy = long.Parse(user.UserId);
hisInfo.UpdateUserName = user.UserName;
hisInfo.COMPARE_RLT = JsonConvert.SerializeObject(compareResult.extra.ShowDetailList);
await tenantDb.Updateable<BusinessCompareDiffRecord>(hisInfo).UpdateColumns(it =>
new
{
it.COMPARE_DIFF_NUM,
it.COMPARE_RLT,
it.UpdateTime,
it.UpdateBy,
it.UpdateUserName
}).ExecuteCommandAsync();
}
if (compareResult.extra.ShowDetailList == null || compareResult.extra.ShowDetailList.Count == 0)
{
result = $"比对失败,没有比对出差异";
//new EmailNoticeHelper().SendEmailNotice($"MBLNO={siSrcDto.MblNo} SI 回执比对差异失败比对结果为0", $"MBLNO={siSrcDto.MblNo} SI 回执比对差异失败比对结果为0", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList());
}
else
{
diffNum = compareResult.extra.ShowDetailList.Count;
}
}
else
{
result = $"比对失败,未获取到比对结果";
//new EmailNoticeHelper().SendEmailNotice($"MBLNO={siSrcDto.MblNo} SI 回执比对差异失败,未获取到比对结果", $"MBLNO={siSrcDto.MblNo} SI 回执比对差异失败,未获取到比对结果", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList());
}
return new Tuple<string, int>(result, diffNum);
}
#endregion
#region 请求BC比对
/// <summary>
/// 请求SI比对
/// </summary>
/// <param name="siSrcDto">订舱详情</param>
/// <param name="siTargetDto">SI截单详情</param>
/// <returns>返回回执</returns>
[NonAction]
public async Task<TaskManageExcuteResultDto> ExcuteCompare(SIFeedBackCompareDto siSrcDto, SIFeedBackCompareDto siTargetDto)
{
TaskManageExcuteResultDto model = null;
/*
1URL
2JSON
3POST
4
*/
var url = "";//App.Configuration["SICompareUrl"];
using (var httpClient = new HttpClient())
{
try
{
using (var reduceAttach = new MultipartFormDataContent())
{
var dataContent = new ByteArrayContent(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(siSrcDto)));
dataContent.Headers.ContentDisposition = new ContentDispositionHeaderValue($"form-data")
{
Name = "srcJson"
};
reduceAttach.Add(dataContent);
var dataContent2 = new ByteArrayContent(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(siTargetDto)));
dataContent2.Headers.ContentDisposition = new ContentDispositionHeaderValue($"form-data")
{
Name = "destJson"
};
reduceAttach.Add(dataContent2);
//请求
var response = httpClient.PostAsync(url, reduceAttach).Result;
var result = response.Content.ReadAsStringAsync().Result;
model = JsonConvert.DeserializeObject<TaskManageExcuteResultDto>(result);
}
}
catch (Exception ex)
{
Logger.Log(NLog.LogLevel.Info, "推送SI比对异常原因{error}", ex.Message);
//throw Oops.Oh($"推送SI比对异常原因{ex.Message}");
}
}
return model;
}
#endregion
#region 获取订舱详情
/// <summary>
/// 获取订舱详情
/// </summary>
/// <param name="taskPKId">任务主键</param>
/// <returns>返回结果</returns>
public async Task<DataResult<TaskBookingOrderDto>> GetBookingOrderInfo(long taskPKId)
{
TaskBookingOrderDto model = null;
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var taskInfo = tenantDb.Queryable<TaskBaseInfo>().First(t => t.Id == taskPKId);
if (taskInfo == null)
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskBaseInfoFromTaskIdNull)), taskPKId));
var orderInfo = _seaExportService.SearchOrderInfo(taskInfo.MBL_NO).GetAwaiter().GetResult().Data;
if (orderInfo != null)
{
//订舱
model = orderInfo.Adapt<TaskBookingOrderDto>();
var contaList = orderInfo.currOrderCtnList;
//获取集装箱的主键
var ctnArg = contaList.Select(t => t.Id).ToArray();
//查询集装箱所有的货物信息
var cargoList = new List<OpCtnDetail>();
//Logger.Log(NLog.LogLevel.Info, "批次={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>();
}
return DataResult<TaskBookingOrderDto>.Success(model);
}
#endregion
#region 获取SI反馈信息
/// <summary>
/// 获取SI反馈信息
/// </summary>
/// <param name="taskPKId">任务主键</param>
/// <returns>返回结果</returns>
public async Task<DataResult<TaskSIFeedBackResultDto>> GetSIFeedBackInfo(long taskPKId)
{
TaskSIFeedBackResultDto model = new TaskSIFeedBackResultDto();
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var siFeedBackList = tenantDb.Queryable<TaskSiSubmitted>()
.InnerJoin<TaskSiSubmittedCtn>((si, ctn) => si.Id == ctn.P_PKID)
.Where((si, ctn) => si.TASK_ID == taskPKId)
.Select((si, ctn) => new { si = si, ctn = ctn }).ToList();
if (siFeedBackList.Count == 0)
throw new Exception($"SI反馈信息不存在");
var mblNo = siFeedBackList.FirstOrDefault().si.MBL_NO;
var orderInfoData = _seaExportService.SearchOrderInfo(mblNo).GetAwaiter().GetResult().Data;
var orderInfo = orderInfoData.currOrder;
model.TaskId = taskPKId;
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(orderInfoData.currOrderCtnList,
siFeedBackList.Select(t => t.ctn).ToList());
model.SICompareOrderContaKeyList = contaDiff;
return DataResult<TaskSIFeedBackResultDto>.Success(model);
}
#endregion
#region 比较主信息
/// <summary>
/// 比较主信息
/// </summary>
/// <param name="bookingOrder">订舱详情</param>
/// <param name="taskSIFeedBackInfo">SI反馈详情</param>
/// <returns>返回差异</returns>
private async Task<List<string>> InnerCompareMainInfoDiff(SeaExportRes bookingOrder, TaskSiSubmitted 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(SeaExportRes).GetProperties();
var feedProps = typeof(TaskSiSubmitted).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 = string.Empty;
string st2 = string.Empty;
if (bkVal == null)
{
st1 = "";
}
else
{
st1 = (bkVal as string).AdjustString();
}
if (siVal == null)
{
st2 = "";
}
else
{
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<OpCtnRes> bookContaList, List<TaskSiSubmittedCtn> siContaList)
{
List<string> resultList = new List<string>();
var bookProps = typeof(OpCtnRes).GetProperties();
var feedProps = typeof(TaskSiSubmittedCtn).GetProperties();
resultList = siContaList.GroupJoin(bookContaList, l => l.CNTRNO, 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.SEALNO.Equals(bkCtn.SealNo)
|| !l.CTNALL.Equals(bkCtn.CtnAll)
|| !l.CBM.Equals(bkCtn.CBM))
{
return l.CNTRNO;
}
return String.Empty;
}
return l.CNTRNO;
}).Where(t => !string.IsNullOrWhiteSpace(t)).ToList();
return resultList;
}
#endregion
#region 异步写入附件表
/// <summary>
/// 异步写入附件表
/// </summary>
/// <param name="boookId">订舱ID</param>
/// <param name="FilePath">文件路径</param>
/// <param name="fileName">文件名</param>
/// <param name="tenantId">租户ID</param>
/// <param name="fileTypeCode">附件类型代码</param>
/// <param name="fileTypeName">附件类型名称</param>
/// <param name="moudle">附件模块代码</param>
/// <returns></returns>
[NonAction]
private async Task<DataResult<string>> SaveEDIFile(long boookId, string FilePath, string fileName, long tenantId, int fileSize,
string fileTypeCode = "sifeed", string fileTypeName = "SI submitted", string moudle = "TaskSISubmitted")
{
/*
*/
//EDI文件
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var bookFile = new OpFile
{
FileName = fileName,
FilePath = FilePath,
TypeCode = fileTypeCode,
TypeName = fileTypeName,
LinkId = boookId,
FileSize = fileSize,
FileType = Path.GetExtension(fileName),
Extension = Path.GetExtension(fileName),
OrgId = user.OrgId
};
await tenantDb.Insertable<OpFile>(bookFile).ExecuteCommandAsync();
return DataResult<string>.Success(string.Empty);
}
#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 new Exception(string.Format("字段{0}={1}转换日期失败,请检查日期格式", MemberName, str));
return currDate;
}
}
#endregion
}