using Amazon.Runtime.Internal.Util;
using DS.Module.Core;
using DS.Module.Core.Log;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core.Op.Dtos;
using DS.WMS.Core.Op.Entity;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using DS.WMS.Core.Op.Interface;
using SqlSugar.IOC;
using Newtonsoft.Json;
using NLog;
using DS.WMS.Core.Sys.Interface;
using Microsoft.AspNetCore.Http;
using LanguageExt.Common;
using DS.Module.Core.Helpers;
using NPOI.SS.Formula.Functions;
using System.Text.RegularExpressions;
using DS.WMS.Core.Sys.Method;
using DS.WMS.Core.Map.Dtos;
using Org.BouncyCastle.Ocsp;
using DS.WMS.Core.Code.Entity;
using DS.WMS.Core.Map.Entity;
using DS.WMS.Core.Code.Dtos;
using System.Net.Http.Headers;
using DS.Module.DjyServiceStatus;
using NPOI.SS.UserModel;
using DS.WMS.Core.Info.Interface;
using Microsoft.Extensions.FileSystemGlobbing;
using DS.WMS.Core.Info.Entity;
using DS.WMS.Core.Info.Dtos;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using AngleSharp.Dom.Events;
using Microsoft.AspNetCore.Authorization;
using DS.WMS.Core.Map.Interface;
using DS.WMS.Core.Code.Interface;
using DS.WMS.Core.Code.Method;
using DS.WMS.Core.Map.Method;
using DS.Module.Core.Extensions;
using DS.Module.Core.Constants;
using DS.Module.Core.Data;
using DS.WMS.Core.TaskPlat.Dtos;
using NPOI.XSSF.UserModel;
using AngleSharp.Dom;
using DS.WMS.Core.TaskPlat.Entity;
using Microsoft.VisualBasic.FileIO;
using Microsoft.Extensions.Logging;
using AnyDiff.Extensions;
using DS.WMS.Core.Sys.Entity;
using LanguageExt;
using Masuit.Tools.Models;
using System.ComponentModel;
using Masuit.Tools.Systems;
using System.Threading;
using NPOI.OpenXmlFormats.Wordprocessing;
using DS.WMS.Core.Invoice.Dtos;
using DS.Module.Core.Enums;
using DS.WMS.Core.Application.Dtos;
using iText.Layout.Element;
using AngleSharp.Html;
using DS.WMS.Core.Op.Dtos.Enum;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
using iText.StyledXmlParser.Jsoup.Safety;
using MathNet.Numerics.LinearAlgebra.Factorization;
namespace DS.WMS.Core.Op.Method
{
///
///
///
public class BLIssueManageService: IBLIssueManageService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
private readonly ISeaExportService _seaExportService;
private static readonly NLog.Logger Logger = LogManager.GetCurrentClassLogger();
public BLIssueManageService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService();
user = _serviceProvider.GetRequiredService();
saasService = _serviceProvider.GetRequiredService();
_seaExportService = _serviceProvider.GetRequiredService();
}
#region 提单管理台账查询
///
/// 提单管理台账查询
///
/// 查询条件
/// 是否导出
/// 返回回执
public async Task>> GetPageAsync(PageRequest querySearch,bool isExport = false)
{
/*
1、海运出口的订单数据跟提单管理表的数据关联,有提单记录的以提单记录为准。
*/
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
List whereList = null;
BLIssueMangeQueryExtDto otherQueryCondition = new BLIssueMangeQueryExtDto();
whereList = GetPageCondition(querySearch,out otherQueryCondition);
var eqlStatus = new string[] { "StatusModify", "ReleaseNotice", "BLModify", "CheckOut", "CheckIn", "BLSeize", "ChangeEndorse", "RejectReleaeNotice" };
var q1 = tenantDb.Queryable().ClearFilter(typeof(IOrgId)).Where(l => (l.IsRefund == null || l.IsRefund.Value == false)
&& (l.IsChangeETD == null || l.IsChangeETD.Value == false))
.Select(a => new BLIssueManageBooking
{
Id = a.Id,
BillType = "M",
ParentId = 0,
MBLNO = a.MBLNO,
HBLNO = a.HBLNO,
CustomerId = a.CustomerId,
CustomerName = a.CustomerName,
ETD = a.ETD,
ETA = a.ETA,
CustomerService = a.CustomerService,
CustomerServiceName = a.CustomerServiceName,
DischargePortId = a.DischargePortId,
DischargePortCode = a.DischargePortCode,
DischargePort = a.DischargePort,
LoadPortId = a.LoadPortId,
LoadPortCode = a.LoadPortCode,
LoadPort = a.LoadPort,
Doc = a.Doc,
DocName = a.DocName,
IssuePlace = a.IssuePlace,
IssuePlaceId = a.IssuePlaceId,
IssueType = a.IssueType,
IssueTypeCode = a.IssueTypeCode,
Sale = a.Sale,
SaleId = a.SaleId,
Vessel = a.Vessel,
Voyno = a.Voyno,
IssuePlaceCode = a.IssuePlaceCode,
StlDate = a.StlDate,
StlName = a.StlName,
CustomerNo = a.CustomerNo,
OperatorId = a.OperatorId,
OperatorName = a.OperatorName
});
var q2 = q1.InnerJoin((l, r) => l.Id == r.BusinessId)
.Select((l, r) => new BLIssueManageBooking
{
Id = r.Id,
BillType = "H",
ParentId = l.Id,
MBLNO = r.MBLNO,
HBLNO = r.HBLNO,
CustomerId = l.CustomerId,
CustomerName = l.CustomerName,
ETD = l.ETD,
ETA = l.ETA,
CustomerService = l.CustomerService,
CustomerServiceName = l.CustomerServiceName,
DischargePortId = r.DischargePortId,
DischargePortCode = "",
DischargePort = r.DischargePort,
LoadPortId = r.LoadPortId,
LoadPortCode = "",
LoadPort = r.LoadPort,
Doc = l.Doc,
DocName = l.DocName,
IssuePlace = r.IssuePlace,
IssuePlaceId = r.IssuePlaceId,
IssueType = r.IssueType,
IssueTypeCode = "",
Sale = l.Sale,
SaleId = l.SaleId,
Vessel = r.Vessel,
Voyno = r.Voyno,
IssuePlaceCode = "",
StlDate = l.StlDate,
StlName = l.StlName,
CustomerNo = l.CustomerNo,
OperatorId = l.OperatorId,
OperatorName = l.OperatorName
});
var queryBase = tenantDb.UnionAll(q1, q2);
var query = queryBase
.LeftJoin((l, r) => l.Id == r.BookingId)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& otherQueryCondition.QueryTabCode.Equals(BLQueryStatusEnum.CheckInQuery.ToString(), StringComparison.OrdinalIgnoreCase),(l,r)=> r.IsCheckIn == false)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& otherQueryCondition.QueryTabCode.Equals(BLQueryStatusEnum.CheckOutQuery.ToString(), StringComparison.OrdinalIgnoreCase), (l, r) => r.IsCheckIn == true)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& otherQueryCondition.QueryTabCode.Equals(BLQueryStatusEnum.HasCheckOutQuery.ToString(), StringComparison.OrdinalIgnoreCase), (l, r) => r.IsCheckOut == true)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& otherQueryCondition.QueryTabCode.Equals(BLQueryStatusEnum.BLModifyQuery.ToString(), StringComparison.OrdinalIgnoreCase), (l, r) => r.IsBLModify == true)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& otherQueryCondition.QueryTabCode.Equals(BLQueryStatusEnum.BLSeizeQuery.ToString(), StringComparison.OrdinalIgnoreCase), (l, r) => r.IsBLSeize == true)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.MHouseFlag)
&& otherQueryCondition.MHouseFlag.Equals("M", StringComparison.OrdinalIgnoreCase), (l, r) => l.BillType == "M")
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.MHouseFlag)
&& otherQueryCondition.MHouseFlag.Equals("H", StringComparison.OrdinalIgnoreCase), (l, r) => l.BillType == "H")
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& otherQueryCondition.QueryTabCode.Equals(BLQueryStatusEnum.BLQuery.ToString(), StringComparison.OrdinalIgnoreCase)
&& !string.IsNullOrWhiteSpace(otherQueryCondition.BlNo), (l, r) => l.MBLNO.Contains(otherQueryCondition.BlNo) || l.HBLNO.Contains(otherQueryCondition.BlNo)
|| l.CustomerNo.Contains(otherQueryCondition.BlNo))
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& otherQueryCondition.QueryTabCode.Equals(BLQueryStatusEnum.BLQuery.ToString(), StringComparison.OrdinalIgnoreCase)
&& !string.IsNullOrWhiteSpace(otherQueryCondition.IssueType), (l, r) => l.IssueType == otherQueryCondition.IssueType)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& !string.IsNullOrWhiteSpace(otherQueryCondition.Vessel), (l, r) => l.Vessel == otherQueryCondition.Vessel)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& !string.IsNullOrWhiteSpace(otherQueryCondition.Voyno), (l, r) => l.Voyno == otherQueryCondition.Voyno)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& otherQueryCondition.CustomerId.HasValue, (l, r) => l.CustomerId == otherQueryCondition.CustomerId.Value)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& otherQueryCondition.Doc.HasValue, (l, r) => l.Doc == otherQueryCondition.Doc.Value)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& otherQueryCondition.ETDStart.HasValue, (l, r) => l.ETD >= otherQueryCondition.ETDStart)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& otherQueryCondition.ETDEnd.HasValue, (l, r) => l.ETD < otherQueryCondition.ETDEnd)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& otherQueryCondition.CheckInDateStart.HasValue, (l, r) => r.CheckInDate >= otherQueryCondition.CheckInDateStart)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& otherQueryCondition.CheckInDateEnd.HasValue, (l, r) => r.CheckInDate < otherQueryCondition.CheckInDateEnd)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& otherQueryCondition.CheckOutDateStart.HasValue, (l, r) => r.CheckOutDate >= otherQueryCondition.CheckOutDateStart)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& otherQueryCondition.CheckOutDateEnd.HasValue, (l, r) => r.CheckOutDate < otherQueryCondition.CheckOutDateEnd)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& otherQueryCondition.Operator.HasValue, (l, r) => l.OperatorId == otherQueryCondition.Operator.Value)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& !string.IsNullOrWhiteSpace(otherQueryCondition.Status)
&& otherQueryCondition.Status.Equals(BLIssueStatusEnum.UnCheckIn.ToString(), StringComparison.OrdinalIgnoreCase),
(l, r) => r.Id == 0)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& !string.IsNullOrWhiteSpace(otherQueryCondition.Status)
&& otherQueryCondition.Status.Equals(BLIssueStatusEnum.CheckInUnCheckOut.ToString(), StringComparison.OrdinalIgnoreCase),
(l, r) => r.IsCheckIn == true && r.IsCheckOut == false)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& !string.IsNullOrWhiteSpace(otherQueryCondition.Status)
&& otherQueryCondition.Status.Equals(BLIssueStatusEnum.UnCheckOut.ToString(), StringComparison.OrdinalIgnoreCase),
(l, r) => r.IsCheckOut == false)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.QueryTabCode)
&& !string.IsNullOrWhiteSpace(otherQueryCondition.Status)
&& eqlStatus.Contains(otherQueryCondition.Status),
(l, r) => r.IsCheckIn == true && r.IsCheckOut == false)
.Select((l, r) => new { order = l, bl = r });
BLIssueMangeQueryExtDto otherQuery = null;
if (whereList != null)
{
query = query.Where(whereList);
}
if (isExport)
{
querySearch.PageCondition.PageSize = Int16.MaxValue;
}
var result = await query.ToQueryPageAsync(querySearch.PageCondition);
List resultList = new List();
if (result.Data.Count > 0)
{
int start = 1;
foreach(var data in result.Data)
{
if (data.bl != null && data.bl.Id > 0)
{
var currBl = data.bl.Adapt();
currBl.IssueType = data.order.IssueType;
currBl.IssueTypeCode = data.order.IssueTypeCode;
currBl.IssuePlaceId = data.order.IssuePlaceId;
currBl.IssuePlaceCode = data.order.IssuePlaceCode;
currBl.IssuePlace = data.order.IssuePlace;
currBl.LoadPortId = data.order.LoadPortId;
currBl.LoadPortCode = data.order.LoadPortCode;
currBl.LoadPort = data.order.LoadPort;
currBl.DischargePortId = data.order.DischargePortId;
currBl.DischargePortCode = data.order.DischargePortCode;
currBl.DischargePort = data.order.DischargePort;
currBl.CustomerService = data.order.CustomerService;
currBl.CustomerServiceName = data.order.CustomerServiceName;
currBl.Doc = data.order.Doc;
currBl.DocName = data.order.DocName;
currBl.MasterHBill = data.order.BillType;
currBl.MasterHBillName = data.order.BillType == "M" ? "主单" : "分单";
currBl.StlDate = data.order.StlDate;
currBl.StlName = data.order.StlName;
currBl.ETD = data.order.ETD;
currBl.ETA = data.order.ETA;
currBl.OperatorId = data.order.OperatorId;
currBl.OperatorName = data.order.OperatorName;
currBl.CustomerNo = data.order.CustomerNo;
resultList.Add(currBl);
continue;
}
var nModel = new BLIssueManageBaseDto
{
Id = start,
BookingId = data.order.Id,
BLNo = data.order.MBLNO,
CustomerId = data.order.CustomerId,
CustomerName = data.order.CustomerName,
SaleId = data.order.SaleId,
Sale = data.order.Sale,
IssueType = data.order.IssueType,
IssueTypeCode = data.order.IssueTypeCode,
IssuePlaceCode = data.order.IssuePlaceCode,
IssuePlace = data.order.IssuePlace,
LoadPortId = data.order.LoadPortId,
LoadPortCode = data.order.LoadPortCode,
LoadPort = data.order.LoadPort,
DischargePortId = data.order.DischargePortId,
DischargePortCode = data.order.DischargePortCode,
DischargePort = data.order.DischargePort,
CustomerService = data.order.CustomerService,
CustomerServiceName = data.order.CustomerServiceName,
BusiType = BLIssueBusiTypeEnum.SeaExport.ToString(),
BusiTypeName = BLIssueBusiTypeEnum.SeaExport.GetDescription(),
BLType = BLTypeEnum.BL.ToString(),
BLTypeName = BLTypeEnum.BL.GetDescription(),
StlDate = data.order.StlDate,
StlName = data.order.StlName,
Doc = data.order.Doc,
DocName = data.order.DocName,
MasterHBill = data.order.BillType,
MasterHBillName = data.order.BillType == "M" ? "主单" : "分单",
ETD = data.order.ETD,
ETA = data.order.ETA,
OperatorId = data.order.OperatorId,
OperatorName = data.order.OperatorName,
CustomerNo = data.order.CustomerNo,
};
if (data.order.ETD.HasValue && data.order.StlDate.HasValue)
{
TimeSpan ts = data.order.StlDate.Value.Subtract(data.order.ETD.Value);
var timeDiff = (decimal)ts.TotalMinutes;
nModel.AgreementDays = (Int16)Math.Ceiling(timeDiff / (24 * 60m));
}
resultList.Add(nModel);
start++;
}
}
return DataResult>.PageList(result.Count, resultList, MultiLanguageConst.DataQuerySuccess);
}
#endregion
#region 获取台账查询条件
///
/// 获取台账查询条件
///
/// 原始查询条件
/// 其他查询条件
///
private List GetPageCondition(PageRequest querySearch,out BLIssueMangeQueryExtDto queryExt)
{
List whereList = null;
queryExt = new BLIssueMangeQueryExtDto();
if (!string.IsNullOrWhiteSpace(querySearch.OtherQueryCondition))
{
queryExt = JsonConvert.DeserializeObject(querySearch.OtherQueryCondition);
}
if (!querySearch.QueryCondition.IsNullOrEmpty())
{
whereList = querySearch.GetConditionalModels(db);
#region 处理查询条件
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("blNo", StringComparison.OrdinalIgnoreCase)))
{
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("blNo", StringComparison.OrdinalIgnoreCase));
queryExt.BlNo = ((ConditionalModel)t).FieldValue;
whereList.Remove(t);
}
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("issueType", StringComparison.OrdinalIgnoreCase)))
{
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("issueType", StringComparison.OrdinalIgnoreCase));
queryExt.IssueType = ((ConditionalModel)t).FieldValue;
whereList.Remove(t);
}
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("status", StringComparison.OrdinalIgnoreCase)))
{
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("Status", StringComparison.OrdinalIgnoreCase));
queryExt.Status = ((ConditionalModel)t).FieldValue;
whereList.Remove(t);
}
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("vessel", StringComparison.OrdinalIgnoreCase)))
{
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("vessel", StringComparison.OrdinalIgnoreCase));
queryExt.Vessel = ((ConditionalModel)t).FieldValue;
whereList.Remove(t);
}
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("voyno", StringComparison.OrdinalIgnoreCase)))
{
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("voyno", StringComparison.OrdinalIgnoreCase));
queryExt.Voyno = ((ConditionalModel)t).FieldValue;
whereList.Remove(t);
}
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("customerId", StringComparison.OrdinalIgnoreCase)))
{
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("customerId", StringComparison.OrdinalIgnoreCase));
queryExt.CustomerId = long.Parse(((ConditionalModel)t).FieldValue);
whereList.Remove(t);
}
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("customerName", StringComparison.OrdinalIgnoreCase)
|| ((ConditionalModel)t).FieldName.Equals("vesselId", StringComparison.OrdinalIgnoreCase)))
{
var curList = whereList.Where(t => ((ConditionalModel)t).FieldName.Equals("customerName", StringComparison.OrdinalIgnoreCase)
|| ((ConditionalModel)t).FieldName.Equals("vesselId", StringComparison.OrdinalIgnoreCase)).ToList();
foreach (ConditionalModel b in curList)
{
whereList.Remove(b);
}
}
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("businessType", StringComparison.OrdinalIgnoreCase)))
{
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("businessType", StringComparison.OrdinalIgnoreCase));
queryExt.BusinessType = ((ConditionalModel)t).FieldValue;
whereList.Remove(t);
}
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("doc", StringComparison.OrdinalIgnoreCase)))
{
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("doc", StringComparison.OrdinalIgnoreCase));
queryExt.Doc = long.Parse(((ConditionalModel)t).FieldValue);
whereList.Remove(t);
}
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("operator", StringComparison.OrdinalIgnoreCase)))
{
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("operator", StringComparison.OrdinalIgnoreCase));
queryExt.Operator = long.Parse(((ConditionalModel)t).FieldValue);
whereList.Remove(t);
}
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("etd", StringComparison.OrdinalIgnoreCase)))
{
var curList = whereList.Where(t => ((ConditionalModel)t).FieldName.Equals("etd", StringComparison.OrdinalIgnoreCase)).ToList();
foreach (ConditionalModel b in curList)
{
if (b.ConditionalType == ConditionalType.GreaterThanOrEqual)
{
DateTime currDate = DateTime.MinValue;
if (DateTime.TryParse(b.FieldValue, out currDate))
{
queryExt.ETDStart = currDate;
}
}
else if (b.ConditionalType == ConditionalType.LessThanOrEqual)
{
DateTime currDate = DateTime.MinValue;
if (DateTime.TryParse(b.FieldValue, out currDate))
{
queryExt.ETDEnd = currDate.AddDays(1);
}
}
whereList.Remove(b);
}
}
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("checkInDate", StringComparison.OrdinalIgnoreCase)))
{
var curList = whereList.Where(t => ((ConditionalModel)t).FieldName.Equals("checkInDate", StringComparison.OrdinalIgnoreCase)).ToList();
foreach (ConditionalModel b in curList)
{
if (b.ConditionalType == ConditionalType.GreaterThanOrEqual)
{
DateTime currDate = DateTime.MinValue;
if (DateTime.TryParse(b.FieldValue, out currDate))
{
queryExt.CheckInDateStart = currDate;
}
}
else if (b.ConditionalType == ConditionalType.LessThanOrEqual)
{
DateTime currDate = DateTime.MinValue;
if (DateTime.TryParse(b.FieldValue, out currDate))
{
queryExt.CheckInDateEnd = currDate.AddDays(1);
}
}
whereList.Remove(b);
}
}
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("checkOutDate", StringComparison.OrdinalIgnoreCase)))
{
var curList = whereList.Where(t => ((ConditionalModel)t).FieldName.Equals("checkOutDate", StringComparison.OrdinalIgnoreCase)).ToList();
foreach (ConditionalModel b in curList)
{
if (b.ConditionalType == ConditionalType.GreaterThanOrEqual)
{
DateTime currDate = DateTime.MinValue;
if (DateTime.TryParse(b.FieldValue, out currDate))
{
queryExt.CheckOutDateStart = currDate;
}
}
else if (b.ConditionalType == ConditionalType.LessThanOrEqual)
{
DateTime currDate = DateTime.MinValue;
if (DateTime.TryParse(b.FieldValue, out currDate))
{
queryExt.CheckOutDateEnd = currDate.AddDays(1);
}
}
whereList.Remove(b);
}
}
#endregion
}
return whereList;
}
#endregion
#region 打印
///
/// 打印
///
/// 提单管理主键
/// 返回回执
public async Task> Print(long id)
{
return null;
}
#endregion
#region 提单签入
///
/// 提单签入
///
/// 提单签入请求
/// 返回回执
public async Task BLCheckIn(BLCheckInOutDto model)
{
/*
1、判断是否已签入,已签入的不能重复签入
*/
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Count == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
DateTime nowDate = DateTime.Now;
if (model.bookids.Any(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
#region 主单处理
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.LeftJoin((l, r) => l.Id == r.BookingId)
.Where((l, r) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order, null);
var saveRlt = await Save(dto);
if (saveRlt.Succeeded)
blModel = saveRlt.Data;
}
if (!blModel.IsCheckIn)
{
blModel.IsCheckIn = true;
blModel.CheckInBy = long.Parse(user.UserId);
blModel.CheckInUserName = user.UserName;
blModel.CheckInDate = nowDate;
blModel.CheckInNote = model.Notes;
blModel.Status = BLIssueStatusEnum.CheckIn.ToString();
blModel.StatusName = BLIssueStatusEnum.CheckIn.GetDescription();
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.IsCheckIn,
x.CheckInBy,
x.CheckInUserName,
x.CheckInDate,
x.CheckInNote,
x.Status,
x.StatusName
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.CheckIn.ToString(),
ActionName = BLIssueActionEnum.CheckIn.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
data.order.BLIssueStatus = (int)BLIssueStatusEnum.CheckIn;
data.order.BLIssueStatusName = BLIssueStatusEnum.CheckIn.GetDescription();
data.order.UpdateBy = long.Parse(user.UserId);
data.order.UpdateUserName = user.UserName;
data.order.UpdateTime = nowDate;
await tenantDb.Updateable(data.order).UpdateColumns(x => new
{
x.BLIssueStatus,
x.BLIssueStatusName,
x.UpdateBy,
x.UpdateUserName,
x.UpdateTime,
}).ExecuteCommandAsync();
}
}
#endregion
}
if (model.bookids.Any(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
#region 分单处理
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.InnerJoin((l, r) => l.BusinessId == r.Id)
.LeftJoin((l, r, t) => l.Id == t.BookingId)
.Where((l, r, t) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r, t) => new { order = r, sub = l,bl = t })
.ToList();
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order, data.sub);
var saveRlt = await Save(dto);
if (saveRlt.Succeeded)
blModel = saveRlt.Data;
}
if (!blModel.IsCheckIn)
{
blModel.IsCheckIn = true;
blModel.CheckInBy = long.Parse(user.UserId);
blModel.CheckInUserName = user.UserName;
blModel.CheckInDate = nowDate;
blModel.CheckInNote = model.Notes;
blModel.Status = BLIssueStatusEnum.CheckIn.ToString();
blModel.StatusName = BLIssueStatusEnum.CheckIn.GetDescription();
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.IsCheckIn,
x.CheckInBy,
x.CheckInUserName,
x.CheckInDate,
x.CheckInNote,
x.Status,
x.StatusName
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.CheckIn.ToString(),
ActionName = BLIssueActionEnum.CheckIn.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
data.sub.BLIssueStatus = (int)BLIssueStatusEnum.CheckIn;
data.sub.BLIssueStatusName = BLIssueStatusEnum.CheckIn.GetDescription();
data.sub.UpdateBy = long.Parse(user.UserId);
data.sub.UpdateUserName = user.UserName;
data.sub.UpdateTime = nowDate;
await tenantDb.Updateable(data.sub).UpdateColumns(x => new
{
x.BLIssueStatus,
x.BLIssueStatusName,
x.UpdateBy,
x.UpdateUserName,
x.UpdateTime,
}).ExecuteCommandAsync();
}
}
#endregion
}
return DataResult.Successed("成功");
}
#endregion
#region 保存提单管理信息
///
/// 保存提单管理信息
///
/// 提单管理详情
/// 是否提取详情
/// 返回ID
public async Task> Save(BLIssueManageBaseInputDto model,bool isLoadInfo = false)
{
BLIssueManageBase info = null;
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
try
{
if (model.Id == 0)
{
info = model.Adapt();
tenantDb.Insertable(info).ExecuteReturnEntity();
}
else
{
if (isLoadInfo)
info = tenantDb.Queryable().First(a => a.Id == model.Id);
}
}
catch(Exception ex)
{
Logger.Log(NLog.LogLevel.Info, $"提单管理保存失败,原因:{ex.Message} json={JsonConvert.SerializeObject(model)}");
}
return DataResult.Success(info);
}
#endregion
#region 取消提单签入
///
/// 取消提单签入
///
/// 取消提单签入请求
/// 返回回执
public async Task BLCheckInCancel(BLCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Count == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
DateTime nowDate = DateTime.Now;
if (model.bookids.Any(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
#region 主单处理
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.LeftJoin((l, r) => l.Id == r.BookingId)
.Where((l, r) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel != null && blModel.Id > 0)
{
if (blModel.IsCheckIn)
{
blModel.IsCheckIn = false;
blModel.CheckInBy = 0;
blModel.CheckInUserName = null;
blModel.CheckInDate = null;
blModel.CheckInNote = null;
blModel.Status = null;
blModel.StatusName = null;
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.IsCheckIn,
x.CheckInBy,
x.CheckInUserName,
x.CheckInDate,
x.CheckInNote,
x.Status,
x.StatusName
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.CheckInCancel.ToString(),
ActionName = BLIssueActionEnum.CheckInCancel.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
data.order.BLIssueStatus = 0;
data.order.BLIssueStatusName = null;
data.order.UpdateBy = long.Parse(user.UserId);
data.order.UpdateUserName = user.UserName;
data.order.UpdateTime = nowDate;
await tenantDb.Updateable(data.order).UpdateColumns(x => new
{
x.BLIssueStatus,
x.BLIssueStatusName,
x.UpdateBy,
x.UpdateUserName,
x.UpdateTime,
}).ExecuteCommandAsync();
}
}
}
#endregion
}
if (model.bookids.Any(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
#region 分单处理
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.InnerJoin((l, r) => l.BusinessId == r.Id)
.LeftJoin((l, r, t) => l.Id == t.BookingId)
.Where((l, r, t) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r, t) => new { order = r, sub = l, bl = t })
.ToList();
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel != null && blModel.Id > 0)
{
if (blModel.IsCheckIn)
{
blModel.IsCheckIn = false;
blModel.CheckInBy = 0;
blModel.CheckInUserName = null;
blModel.CheckInDate = null;
blModel.CheckInNote = null;
blModel.Status = null;
blModel.StatusName = null;
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.IsCheckIn,
x.CheckInBy,
x.CheckInUserName,
x.CheckInDate,
x.CheckInNote,
x.Status,
x.StatusName
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.CheckInCancel.ToString(),
ActionName = BLIssueActionEnum.CheckInCancel.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
data.sub.BLIssueStatus = 0;
data.sub.BLIssueStatusName = null;
data.sub.UpdateBy = long.Parse(user.UserId);
data.sub.UpdateUserName = user.UserName;
data.sub.UpdateTime = nowDate;
await tenantDb.Updateable(data.order).UpdateColumns(x => new
{
x.BLIssueStatus,
x.BLIssueStatusName,
x.UpdateBy,
x.UpdateUserName,
x.UpdateTime,
}).ExecuteCommandAsync();
}
}
}
#endregion
}
return DataResult.Successed("成功");
}
#endregion
#region 提单签出
///
/// 提单签出
///
/// 提单签入请求
/// 返回回执
public async Task BLCheckOut(BLCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Count == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
DateTime nowDate = DateTime.Now;
if (model.bookids.Any(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.LeftJoin((l, r) => l.Id == r.BookingId)
.Where((l, r) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
//if (orderList.Count != model.bookids.Length)
//{
// return DataResult.Failed("部分订单查询失败,请重新查询台账");
//}
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order, null);
var saveRlt = await Save(dto);
if (saveRlt.Succeeded)
blModel = saveRlt.Data;
}
if (!blModel.IsCheckOut)
{
blModel.IsCheckOut = true;
blModel.CheckOutBy = long.Parse(user.UserId);
blModel.CheckOutUserName = user.UserName;
blModel.CheckOutDate = nowDate;
blModel.CheckOutNote = model.Notes;
blModel.Status = BLIssueStatusEnum.CheckOut.ToString();
blModel.StatusName = BLIssueStatusEnum.CheckOut.GetDescription();
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.IsCheckOut,
x.CheckOutBy,
x.CheckOutUserName,
x.CheckOutDate,
x.CheckOutNote,
x.Status,
x.StatusName
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.CheckOut.ToString(),
ActionName = BLIssueActionEnum.CheckOut.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
data.order.BLIssueStatus = (int)BLIssueStatusEnum.CheckOut;
data.order.BLIssueStatusName = BLIssueStatusEnum.CheckOut.GetDescription();
data.order.UpdateBy = long.Parse(user.UserId);
data.order.UpdateUserName = user.UserName;
data.order.UpdateTime = nowDate;
await tenantDb.Updateable(data.order).UpdateColumns(x => new
{
x.BLIssueStatus,
x.BLIssueStatusName,
x.UpdateBy,
x.UpdateUserName,
x.UpdateTime,
}).ExecuteCommandAsync();
}
}
}
if (model.bookids.Any(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
#region 分单处理
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.InnerJoin((l, r) => l.BusinessId == r.Id)
.LeftJoin((l, r, t) => l.Id == t.BookingId)
.Where((l, r, t) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r, t) => new { order = r, sub = l, bl = t })
.ToList();
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order, data.sub);
var saveRlt = await Save(dto);
if (saveRlt.Succeeded)
blModel = saveRlt.Data;
}
if (!blModel.IsCheckOut)
{
blModel.IsCheckOut = true;
blModel.CheckOutBy = long.Parse(user.UserId);
blModel.CheckOutUserName = user.UserName;
blModel.CheckOutDate = nowDate;
blModel.CheckOutNote = model.Notes;
blModel.Status = BLIssueStatusEnum.CheckOut.ToString();
blModel.StatusName = BLIssueStatusEnum.CheckOut.GetDescription();
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.IsCheckOut,
x.CheckOutBy,
x.CheckOutUserName,
x.CheckOutDate,
x.CheckOutNote,
x.Status,
x.StatusName
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.CheckOut.ToString(),
ActionName = BLIssueActionEnum.CheckOut.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
data.sub.BLIssueStatus = (int)BLIssueStatusEnum.CheckOut;
data.sub.BLIssueStatusName = BLIssueStatusEnum.CheckOut.GetDescription();
data.sub.UpdateBy = long.Parse(user.UserId);
data.sub.UpdateUserName = user.UserName;
data.sub.UpdateTime = nowDate;
await tenantDb.Updateable(data.sub).UpdateColumns(x => new
{
x.BLIssueStatus,
x.BLIssueStatusName,
x.UpdateBy,
x.UpdateUserName,
x.UpdateTime,
}).ExecuteCommandAsync();
}
}
#endregion
}
return DataResult.Successed("");
}
#endregion
#region 取消提单签出
///
/// 取消提单签出
///
/// 取消提单签入请求
/// 返回回执
public async Task BLCheckOutCancel(BLCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Count == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
DateTime nowDate = DateTime.Now;
if (model.bookids.Any(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.LeftJoin((l, r) => l.Id == r.BookingId)
.Where((l, r) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
if (orderList.Count != model.bookids.Count)
{
return DataResult.Failed("部分订单查询失败,请重新查询台账");
}
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel != null && blModel.Id > 0)
{
if (blModel.IsCheckOut)
{
blModel.IsCheckOut = false;
blModel.CheckOutBy = 0;
blModel.CheckOutUserName = null;
blModel.CheckOutDate = null;
blModel.CheckOutNote = null;
blModel.Status = null;
blModel.StatusName = null;
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.IsCheckOut,
x.CheckOutBy,
x.CheckOutUserName,
x.CheckOutDate,
x.CheckOutNote,
x.Status,
x.StatusName
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.CheckOutCancel.ToString(),
ActionName = BLIssueActionEnum.CheckOutCancel.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
data.order.BLIssueStatus = 0;
data.order.BLIssueStatusName = null;
data.order.UpdateBy = long.Parse(user.UserId);
data.order.UpdateUserName = user.UserName;
data.order.UpdateTime = nowDate;
await tenantDb.Updateable(data.order).UpdateColumns(x => new
{
x.BLIssueStatus,
x.BLIssueStatusName,
x.UpdateBy,
x.UpdateUserName,
x.UpdateTime,
}).ExecuteCommandAsync();
}
}
}
}
if (model.bookids.Any(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
#region 分单处理
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.InnerJoin((l, r) => l.BusinessId == r.Id)
.LeftJoin((l, r, t) => l.Id == t.BookingId)
.Where((l, r, t) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r, t) => new { order = r, sub = l, bl = t })
.ToList();
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel != null && blModel.Id > 0)
{
if (blModel.IsCheckOut)
{
blModel.IsCheckOut = false;
blModel.CheckOutBy = 0;
blModel.CheckOutUserName = null;
blModel.CheckOutDate = null;
blModel.CheckOutNote = null;
blModel.Status = null;
blModel.StatusName = null;
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.IsCheckOut,
x.CheckOutBy,
x.CheckOutUserName,
x.CheckOutDate,
x.CheckOutNote,
x.Status,
x.StatusName
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.CheckOutCancel.ToString(),
ActionName = BLIssueActionEnum.CheckOutCancel.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
data.sub.BLIssueStatus = 0;
data.sub.BLIssueStatusName = null;
data.sub.UpdateBy = long.Parse(user.UserId);
data.sub.UpdateUserName = user.UserName;
data.sub.UpdateTime = nowDate;
await tenantDb.Updateable(data.sub).UpdateColumns(x => new
{
x.BLIssueStatus,
x.BLIssueStatusName,
x.UpdateBy,
x.UpdateUserName,
x.UpdateTime,
}).ExecuteCommandAsync();
}
}
}
#endregion
}
return DataResult.Successed("成功");
}
#endregion
#region 船证签入
///
/// 船证签入
///
/// 船证签入请求
/// 返回回执
public async Task ShipCertCheckIn(ShipCertCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Count == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
DateTime nowDate = DateTime.Now;
if (model.bookids.Any(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.LeftJoin((l, r) => l.Id == r.BookingId)
.Where((l, r) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
//if (orderList.Count != model.bookids.Length)
//{
// return DataResult.Failed("部分订单查询失败,请重新查询台账");
//}
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order, null);
var saveRlt = await Save(dto);
if (saveRlt.Succeeded)
blModel = saveRlt.Data;
}
if (!blModel.IsShipCertCheckIn)
{
blModel.IsShipCertCheckIn = true;
blModel.IsShipCertificate = true;
blModel.ShipCertCheckInBy = long.Parse(user.UserId);
blModel.ShipCertCheckInUserName = user.UserName;
blModel.ShipCertCheckInDate = nowDate;
blModel.ShipCertCheckInNote = model.Notes;
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.IsShipCertificate,
x.IsShipCertCheckIn,
x.ShipCertCheckInBy,
x.ShipCertCheckInUserName,
x.ShipCertCheckInDate,
x.ShipCertCheckInNote,
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.ShipCertCheckIn.ToString(),
ActionName = BLIssueActionEnum.ShipCertCheckIn.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
}
}
}
if (model.bookids.Any(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
#region 主单处理
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.InnerJoin((l, r) => l.BusinessId == r.Id)
.LeftJoin((l, r, t) => l.Id == t.BookingId)
.Where((l, r, t) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r, t) => new { order = r, sub = l, bl = t })
.ToList();
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order, data.sub);
var saveRlt = await Save(dto);
if (saveRlt.Succeeded)
blModel = saveRlt.Data;
}
if (!blModel.IsShipCertCheckIn)
{
blModel.IsShipCertCheckIn = true;
blModel.IsShipCertificate = true;
blModel.ShipCertCheckInBy = long.Parse(user.UserId);
blModel.ShipCertCheckInUserName = user.UserName;
blModel.ShipCertCheckInDate = nowDate;
blModel.ShipCertCheckInNote = model.Notes;
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.IsShipCertificate,
x.IsShipCertCheckIn,
x.ShipCertCheckInBy,
x.ShipCertCheckInUserName,
x.ShipCertCheckInDate,
x.ShipCertCheckInNote,
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.ShipCertCheckIn.ToString(),
ActionName = BLIssueActionEnum.ShipCertCheckIn.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
}
}
#endregion
}
return DataResult.Successed("成功");
}
#endregion
#region 取消船证签入
///
/// 取消船证签入
///
/// 取消船证签入请求
/// 返回回执
public async Task ShipCertCheckInCancel(ShipCertCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Count == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var checkIds = model.bookids.Select(a => a.bookid).ToArray();
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.LeftJoin((l, r) => l.Id == r.BookingId)
.Where((l, r) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
if (orderList.Count != model.bookids.Count)
{
return DataResult.Failed("部分订单查询失败,请重新查询台账");
}
DateTime nowDate = DateTime.Now;
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel != null && blModel.Id > 0)
{
if (blModel.IsShipCertCheckIn)
{
blModel.IsShipCertCheckIn = false;
blModel.ShipCertCheckInBy = 0;
blModel.ShipCertCheckInUserName = null;
blModel.ShipCertCheckInDate = null;
blModel.ShipCertCheckInNote = null;
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.IsShipCertCheckIn,
x.ShipCertCheckInBy,
x.ShipCertCheckInUserName,
x.ShipCertCheckInDate,
x.ShipCertCheckInNote,
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.ShipCertCheckInCancel.ToString(),
ActionName = BLIssueActionEnum.ShipCertCheckInCancel.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
}
}
}
return DataResult.Successed("成功");
}
#endregion
#region 船证签出
///
/// 船证签出
///
/// 船证签出请求
/// 返回回执
public async Task ShipCertCheckOut(ShipCertCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Count == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
DateTime nowDate = DateTime.Now;
if (model.bookids.Any(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.LeftJoin((l, r) => l.Id == r.BookingId)
.Where((l, r) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
//if (orderList.Count != model.bookids.Length)
//{
// return DataResult.Failed("部分订单查询失败,请重新查询台账");
//}
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order, null);
var saveRlt = await Save(dto);
if (saveRlt.Succeeded)
blModel = saveRlt.Data;
}
if (!blModel.IsShipCertCheckOut)
{
blModel.IsShipCertCheckOut = true;
blModel.IsShipCertificate = true;
blModel.ShipCertCheckOutBy = long.Parse(user.UserId);
blModel.ShipCertCheckOutUserName = user.UserName;
blModel.ShipCertCheckOutDate = nowDate;
blModel.ShipCertCheckOutNote = model.Notes;
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.IsShipCertificate,
x.IsShipCertCheckOut,
x.ShipCertCheckOutBy,
x.ShipCertCheckOutUserName,
x.ShipCertCheckOutDate,
x.ShipCertCheckOutNote,
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.ShipCertCheckOut.ToString(),
ActionName = BLIssueActionEnum.ShipCertCheckOut.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
}
}
}
if (model.bookids.Any(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
#region 主单处理
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.InnerJoin((l, r) => l.BusinessId == r.Id)
.LeftJoin((l, r, t) => l.Id == t.BookingId)
.Where((l, r, t) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r, t) => new { order = r, sub = l, bl = t })
.ToList();
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order, data.sub);
var saveRlt = await Save(dto);
if (saveRlt.Succeeded)
blModel = saveRlt.Data;
}
if (!blModel.IsShipCertCheckOut)
{
blModel.IsShipCertCheckOut = true;
blModel.IsShipCertificate = true;
blModel.ShipCertCheckOutBy = long.Parse(user.UserId);
blModel.ShipCertCheckOutUserName = user.UserName;
blModel.ShipCertCheckOutDate = nowDate;
blModel.ShipCertCheckOutNote = model.Notes;
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.IsShipCertificate,
x.IsShipCertCheckOut,
x.ShipCertCheckOutBy,
x.ShipCertCheckOutUserName,
x.ShipCertCheckOutDate,
x.ShipCertCheckOutNote,
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.ShipCertCheckOut.ToString(),
ActionName = BLIssueActionEnum.ShipCertCheckOut.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
}
}
#endregion
}
return DataResult.Successed("成功");
}
#endregion
#region 取消船证签出
///
/// 取消船证签出
///
/// 取消船证签出请求
/// 返回回执
public async Task ShipCertCheckOutCancel(ShipCertCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Count == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var checkIds = model.bookids.Select(a => a.bookid).ToArray();
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.LeftJoin((l, r) => l.Id == r.BookingId)
.Where((l, r) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
if (orderList.Count != model.bookids.Count)
{
return DataResult.Failed("部分订单查询失败,请重新查询台账");
}
DateTime nowDate = DateTime.Now;
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel != null && blModel.Id > 0)
{
if (blModel.IsShipCertCheckOut)
{
blModel.IsShipCertCheckOut = false;
blModel.ShipCertCheckOutBy = 0;
blModel.ShipCertCheckOutUserName = null;
blModel.ShipCertCheckOutDate = null;
blModel.ShipCertCheckOutNote = null;
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.IsShipCertCheckOut,
x.ShipCertCheckOutBy,
x.ShipCertCheckOutUserName,
x.ShipCertCheckOutDate,
x.ShipCertCheckOutNote,
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.ShipCertCheckOutCancel.ToString(),
ActionName = BLIssueActionEnum.ShipCertCheckOutCancel.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
}
}
}
return DataResult.Successed("成功");
}
#endregion
#region 提单换签(背书)
///
/// 提单换签(背书)
///
/// 提单换签(背书)请求
/// 返回回执
public async Task BLCheckChangeEndorse(BLCheckInOutDto model)
{
/*
只能提单签入才能换单背书
*/
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Count == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
DateTime nowDate = DateTime.Now;
if (model.bookids.Any(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.LeftJoin((l, r) => l.Id == r.BookingId)
.Where((l, r) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
//if (orderList.Count != model.bookids.Length)
//{
// return DataResult.Failed("部分订单查询失败,请重新查询台账");
//}
if (orderList.Any(p => !p.bl.IsCheckIn))
{
string s = string.Join(",", orderList.Where(p => !p.bl.IsCheckIn)
.Select(b => b.bl.BLNo).ToArray());
return DataResult.Failed($"提单号:{s} 不能操作,只有已提单已签入才能进行 提单换签(背书)");
}
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order, null);
var saveRlt = await Save(dto);
if (saveRlt.Succeeded)
blModel = saveRlt.Data;
}
if (blModel.IsCheckIn)
{
blModel.Status = BLIssueStatusEnum.ChangeEndorse.ToString();
blModel.StatusName = BLIssueStatusEnum.ChangeEndorse.GetDescription();
blModel.IsChangeEndorse = true;
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.Status,
x.StatusName,
x.IsChangeEndorse,
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.ChangeEndorse.ToString(),
ActionName = BLIssueActionEnum.ChangeEndorse.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
}
}
}
if (model.bookids.Any(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
#region 主单处理
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.InnerJoin((l, r) => l.BusinessId == r.Id)
.LeftJoin((l, r, t) => l.Id == t.BookingId)
.Where((l, r, t) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r, t) => new { order = r, sub = l, bl = t })
.ToList();
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order, data.sub);
var saveRlt = await Save(dto);
if (saveRlt.Succeeded)
blModel = saveRlt.Data;
}
if (blModel.IsCheckIn || !blModel.IsChangeEndorse)
{
blModel.Status = BLIssueStatusEnum.ChangeEndorse.ToString();
blModel.StatusName = BLIssueStatusEnum.ChangeEndorse.GetDescription();
blModel.IsChangeEndorse = true;
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.Status,
x.StatusName,
x.IsChangeEndorse,
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.ChangeEndorse.ToString(),
ActionName = BLIssueActionEnum.ChangeEndorse.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
}
}
#endregion
}
return DataResult.Successed("成功");
}
#endregion
#region 取消提单换签(背书)
///
/// 取消提单换签(背书)
///
/// 取消提单换签(背书)请求
/// 返回回执
public async Task BLCheckChangeEndorseCancel(BLCheckInOutDto model)
{
/*
只能提单签入才能换单背书
*/
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Count == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var checkIds = model.bookids.Select(a => a.bookid).ToArray();
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.LeftJoin((l, r) => l.Id == r.BookingId)
.Where((l, r) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
if (orderList.Count != model.bookids.Count)
{
return DataResult.Failed("部分订单查询失败,请重新查询台账");
}
if (orderList.Any(p => !p.bl.IsCheckIn))
{
string s = string.Join(",", orderList.Where(p => !p.bl.IsCheckIn)
.Select(b => b.bl.BLNo).ToArray());
return DataResult.Failed($"提单号:{s} 不能操作,只有已提单已签入才能进行 提单换签(背书)");
}
DateTime nowDate = DateTime.Now;
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = new BLIssueManageBaseInputDto
{
BookingId = data.order.Id,
BLNo = data.order.MBLNO,
CustomerId = data.order.CustomerId,
CustomerName = data.order.CustomerName,
SaleId = data.order.SaleId,
Sale = data.order.Sale,
IssueType = data.order.IssueType,
IssueTypeCode = data.order.IssueTypeCode,
IssuePlaceCode = data.order.IssuePlaceCode,
IssuePlace = data.order.IssuePlace,
LoadPortId = data.order.LoadPortId,
LoadPortCode = data.order.LoadPortCode,
LoadPort = data.order.LoadPort,
DischargePortId = data.order.DischargePortId,
DischargePortCode = data.order.DischargePortCode,
DischargePort = data.order.DischargePort,
CustomerService = data.order.CustomerService,
CustomerServiceName = data.order.CustomerServiceName,
BLType = BLTypeEnum.BL.ToString(),
BLTypeName = BLTypeEnum.BL.GetDescription(),
BusiType = BLIssueBusiTypeEnum.SeaExport.ToString(),
BusiTypeName = BLIssueBusiTypeEnum.SeaExport.GetDescription(),
StlDate = data.order.StlDate,
};
var saveRlt = await Save(dto);
if (saveRlt.Succeeded)
blModel = saveRlt.Data;
}
if (blModel.IsChangeEndorse)
{
blModel.Status = null;
blModel.StatusName = null;
blModel.IsChangeEndorse = false;
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.Status,
x.StatusName,
x.IsChangeEndorse,
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.ChangeEndorseCancel.ToString(),
ActionName = BLIssueActionEnum.ChangeEndorseCancel.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
}
}
return DataResult.Successed("成功");
}
#endregion
#region 驳回放单通知
///
/// 驳回放单通知
///
/// 驳回放单通知请求
/// 返回回执
public async Task BLRejectReleaseNotice(BLCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Count == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
DateTime nowDate = DateTime.Now;
if (model.bookids.Any(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.LeftJoin((l, r) => l.Id == r.BookingId)
.Where((l, r) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
//if (orderList.Count != model.bookids.Length)
//{
// return DataResult.Failed("部分订单查询失败,请重新查询台账");
//}
if (orderList.Any(p => !p.bl.IsCheckIn))
{
string s = string.Join(",", orderList.Where(p => !p.bl.IsCheckIn)
.Select(b => b.bl.BLNo).ToArray());
return DataResult.Failed($"提单号:{s} 不能操作,只有已提单已签入才能进行 驳回放单通知");
}
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order, null);
var saveRlt = await Save(dto);
if (saveRlt.Succeeded)
blModel = saveRlt.Data;
}
if (blModel.IsCheckIn)
{
blModel.Status = BLIssueStatusEnum.RejectReleaeNotice.ToString();
blModel.StatusName = BLIssueStatusEnum.RejectReleaeNotice.GetDescription();
blModel.IsChangeEndorse = true;
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.Status,
x.StatusName,
x.IsChangeEndorse,
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.RejectReleaeNotice.ToString(),
ActionName = BLIssueActionEnum.RejectReleaeNotice.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
}
}
}
if (model.bookids.Any(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
#region 主单处理
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.InnerJoin((l, r) => l.BusinessId == r.Id)
.LeftJoin((l, r, t) => l.Id == t.BookingId)
.Where((l, r, t) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r, t) => new { order = r, sub = l, bl = t })
.ToList();
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order, data.sub);
var saveRlt = await Save(dto);
if (saveRlt.Succeeded)
blModel = saveRlt.Data;
}
if (blModel.IsCheckIn)
{
blModel.Status = BLIssueStatusEnum.RejectReleaeNotice.ToString();
blModel.StatusName = BLIssueStatusEnum.RejectReleaeNotice.GetDescription();
//blModel.Isrej = true;
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.Status,
x.StatusName,
x.IsChangeEndorse,
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.RejectReleaeNotice.ToString(),
ActionName = BLIssueActionEnum.RejectReleaeNotice.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
}
}
#endregion
}
return DataResult.Successed("成功");
}
#endregion
#region 更改提单(其他)
///
/// 更改提单(其他)
///
/// 更改提单请求
/// 返回回执
public async Task BLModify(BLCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Count == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
DateTime nowDate = DateTime.Now;
if (model.bookids.Any(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.LeftJoin((l, r) => l.Id == r.BookingId)
.Where((l, r) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
if (orderList.Count != model.bookids.Count)
{
return DataResult.Failed("部分订单查询失败,请重新查询台账");
}
if (orderList.Any(p => !p.bl.IsCheckIn))
{
string s = string.Join(",", orderList.Where(p => !p.bl.IsCheckIn)
.Select(b => b.bl.BLNo).ToArray());
return DataResult.Failed($"提单号:{s} 不能操作,只有已提单已签入才能进行 更改提单(其他)");
}
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order, null);
var saveRlt = await Save(dto);
if (saveRlt.Succeeded)
blModel = saveRlt.Data;
}
if (blModel.IsCheckIn)
{
blModel.Status = BLIssueStatusEnum.BLModify.ToString();
blModel.StatusName = BLIssueStatusEnum.BLModify.GetDescription();
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.Status,
x.StatusName,
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.RejectReleaeNotice.ToString(),
ActionName = BLIssueActionEnum.RejectReleaeNotice.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
}
}
}
if (model.bookids.Any(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
#region 主单处理
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.InnerJoin((l, r) => l.BusinessId == r.Id)
.LeftJoin((l, r, t) => l.Id == t.BookingId)
.Where((l, r, t) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r, t) => new { order = r, sub = l, bl = t })
.ToList();
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order, data.sub);
var saveRlt = await Save(dto);
if (saveRlt.Succeeded)
blModel = saveRlt.Data;
}
if (blModel.IsCheckIn)
{
blModel.Status = BLIssueStatusEnum.BLModify.ToString();
blModel.StatusName = BLIssueStatusEnum.BLModify.GetDescription();
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.Status,
x.StatusName,
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.BLModify.ToString(),
ActionName = BLIssueActionEnum.BLModify.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
}
}
#endregion
}
return DataResult.Successed("成功");
}
#endregion
#region 状态更改
///
/// 状态更改
///
/// 状态更改请求
/// 返回回执
public async Task BLModifyStatus(BLCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Count == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
DateTime nowDate = DateTime.Now;
if (model.bookids.Any(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("M", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.LeftJoin((l, r) => l.Id == r.BookingId)
.Where((l, r) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
//if (orderList.Count != model.bookids.Length)
//{
// return DataResult.Failed("部分订单查询失败,请重新查询台账");
//}
if (orderList.Any(p => !p.bl.IsCheckIn))
{
string s = string.Join(",", orderList.Where(p => !p.bl.IsCheckIn)
.Select(b => b.bl.BLNo).ToArray());
return DataResult.Failed($"提单号:{s} 不能操作,只有已提单已签入才能进行 状态更改");
}
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order, null);
var saveRlt = await Save(dto);
if (saveRlt.Succeeded)
blModel = saveRlt.Data;
}
if (blModel.IsCheckIn)
{
blModel.Status = BLIssueStatusEnum.StatusModify.ToString();
blModel.StatusName = BLIssueStatusEnum.StatusModify.GetDescription();
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.Status,
x.StatusName,
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.StatusModify.ToString(),
ActionName = BLIssueActionEnum.StatusModify.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
}
}
}
if (model.bookids.Any(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)))
{
var checkIds = model.bookids.Where(a => a.MHBillType.Equals("H", StringComparison.OrdinalIgnoreCase)).Select(a => a.bookid).ToArray();
#region 主单处理
var orderList = tenantDb.Queryable().ClearFilter(typeof(IOrgId))
.InnerJoin((l, r) => l.BusinessId == r.Id)
.LeftJoin((l, r, t) => l.Id == t.BookingId)
.Where((l, r, t) => checkIds.Contains(l.Id) && l.Deleted == false)
.Select((l, r, t) => new { order = r, sub = l, bl = t })
.ToList();
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order, data.sub);
var saveRlt = await Save(dto);
if (saveRlt.Succeeded)
blModel = saveRlt.Data;
}
if (blModel.IsCheckIn)
{
blModel.Status = BLIssueStatusEnum.StatusModify.ToString();
blModel.StatusName = BLIssueStatusEnum.StatusModify.GetDescription();
await tenantDb.Updateable(blModel)
.UpdateColumns(x => new
{
x.Status,
x.StatusName,
}).ExecuteCommandAsync();
var log = new BLIssueManageLog
{
Pid = blModel.Id,
ActionCode = BLIssueActionEnum.StatusModify.ToString(),
ActionName = BLIssueActionEnum.StatusModify.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable(log).ExecuteCommandAsync();
}
}
#endregion
}
return DataResult.Successed("成功");
}
#endregion
#region 查询单票的提单管理日志
///
/// 查询单票的提单管理日志
///
/// 提单管理主键
/// 返回日志列表
public async Task>> GetLogs(long id)
{
List list = new List();
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
//这里如果遇到id小于5位时,表示ID不是虚拟的,不能进行库查询
if (id.ToString().Length > 5)
{
var logList = tenantDb.Queryable().Where(a => a.Pid == id).ToList();
if (logList.Count > 0)
{
list = logList.OrderByDescending(a => a.CreateTime).Adapt>();
}
}
return DataResult>.Success(list);
}
#endregion
#region 获取相关信息
///
/// 获取相关信息
///
/// 提单管理主键
/// 返回相关信息
public async Task> GetRelateInfo(long id)
{
BLIssueCustomerDto model = new BLIssueCustomerDto();
return DataResult.Success(model);
}
#endregion
#region 获取欠费详情列表
///
/// 获取欠费详情列表
///
/// 提单管理主键
/// 返回列表
public async Task>> GetOverdueFeeList(long id)
{
List list = new List();
return DataResult>.Success(list);
}
#endregion
#region 获取初始化提单管理详情
///
/// 获取初始化提单管理详情
///
/// 临时ID
/// 订单详情
/// 业务类型
///
private BLIssueManageBaseDto GetInitInfo(long tempId,SeaExport order, BLIssueBusiTypeEnum busiTypeEnum = BLIssueBusiTypeEnum.SeaExport)
{
return new BLIssueManageBaseDto
{
Id = tempId,
BookingId = order.Id,
BLNo = order.MBLNO,
CustomerId = order.CustomerId,
CustomerName = order.CustomerName,
SaleId = order.SaleId,
Sale = order.Sale,
IssueType = order.IssueType,
IssueTypeCode = order.IssueTypeCode,
IssuePlaceCode = order.IssuePlaceCode,
IssuePlace = order.IssuePlace,
LoadPortId = order.LoadPortId,
LoadPortCode = order.LoadPortCode,
LoadPort = order.LoadPort,
DischargePortId = order.DischargePortId,
DischargePortCode = order.DischargePortCode,
DischargePort = order.DischargePort,
CustomerService = order.CustomerService,
CustomerServiceName = order.CustomerServiceName,
BusiType = busiTypeEnum.ToString(),
BusiTypeName = busiTypeEnum.GetDescription(),
BLType = BLTypeEnum.BL.ToString(),
BLTypeName = BLTypeEnum.BL.GetDescription(),
Doc = order.Doc,
DocName = order.DocName,
};
}
#endregion
#region 获取待保存提单管理详情
///
/// 获取待保存提单管理详情
///
/// 订单详情
/// 分单详情
/// 是否分单 true-分单 false-主单
/// 业务类型
///
private BLIssueManageBaseInputDto GetReadSaveInfo(SeaExport order, SeaExportBillManage hOrder, bool isHouseBill = false, BLIssueBusiTypeEnum busiTypeEnum = BLIssueBusiTypeEnum.SeaExport)
{
var model = new BLIssueManageBaseInputDto
{
BLNo = order.MBLNO,
CustomerId = order.CustomerId,
CustomerName = order.CustomerName,
SaleId = order.SaleId,
Sale = order.Sale,
CustomerService = order.CustomerService,
CustomerServiceName = order.CustomerServiceName,
BusiType = busiTypeEnum.ToString(),
BusiTypeName = busiTypeEnum.GetDescription(),
BLType = BLTypeEnum.BL.ToString(),
BLTypeName = BLTypeEnum.BL.GetDescription(),
ETD = order.ETD,
ETA = order.ETA,
StlDate = order.StlDate,
StlName = order.StlName,
HBLNo = hOrder != null ? order.HBLNO : "",
MHBillType = isHouseBill ? "H" : "M"
};
if (hOrder != null && hOrder.Id > 0)
{
model.BookingId = hOrder.Id;
model.IssueType = hOrder.IssueType;
//model.IssueTypeCode = hOrder.IssueTypeCode;
//model.IssuePlaceCode = hOrder.IssuePlaceCode;
model.IssuePlace = hOrder.IssuePlace;
model.LoadPortId = hOrder.LoadPortId;
//model.LoadPortCode = hOrder.LoadPortCode;
model.LoadPort = hOrder.LoadPort;
model.DischargePortId = hOrder.DischargePortId;
//model.DischargePortCode = hOrder.DischargePortCode;
model.DischargePort = hOrder.DischargePort;
}
else
{
model.BookingId = order.Id;
model.IssueType = order.IssueType;
model.IssueTypeCode = order.IssueTypeCode;
model.IssuePlaceCode = order.IssuePlaceCode;
model.IssuePlace = order.IssuePlace;
model.LoadPortId = order.LoadPortId;
model.LoadPortCode = order.LoadPortCode;
model.LoadPort = order.LoadPort;
model.DischargePortId = order.DischargePortId;
model.DischargePortCode = order.DischargePortCode;
model.DischargePort = order.DischargePort;
model.CustomerService = order.CustomerService;
}
if (order.ETD.HasValue && order.StlDate.HasValue)
{
TimeSpan ts = order.StlDate.Value.Subtract(order.ETD.Value);
var timeDiff = (decimal)ts.TotalMinutes;
model.AgreementDays = (Int16)Math.Ceiling(timeDiff / (24 * 60m));
}
model.UpdateBy = long.Parse(user.UserId);
model.UpdateUserName = user.UserName;
model.UpdateTime = DateTime.Now;
return model;
}
#endregion
}
public class BLIssueManageBooking
{
///
/// 订单主键
///
public long Id { get; set; }
///
/// 订单类型(M-主票 H-分票)
///
public string BillType { get; set; }
///
/// 主单ID
///
public long ParentId { get; set; }
///
/// 主提单号
///
public string MBLNO { get; set; }
///
/// 分提单号
///
public string HBLNO { get; set; }
///
/// 委托单位Id
///
public long CustomerId { get; set; }
///
/// 委托单位
///
public string CustomerName { get; set; }
///
/// 揽货人Id
///
public long SaleId { get; set; }
///
/// 揽货人
///
public string Sale { get; set; }
///
/// 开船日期
///
public DateTime? ETD { get; set; }
///
/// 预抵日期
///
public DateTime? ETA { get; set; }
///
/// 签单方式
///
public string IssueType { get; set; }
///
/// 签单方式代码
///
public string IssueTypeCode { get; set; }
///
/// 签单地点Id
///
public long IssuePlaceId { get; set; }
///
/// 签单地点
///
public string IssuePlace { get; set; }
///
/// 签单地点代码
///
public string IssuePlaceCode { get; set; }
///
/// 装货港Id
///
public long LoadPortId { get; set; }
///
/// 装货港
///
public string LoadPort { get; set; }
///
/// 装货港代码
///
public string LoadPortCode { get; set; }
///
/// 卸货港Id
///
public long DischargePortId { get; set; }
///
/// 卸货港
///
public string DischargePort { get; set; }
///
/// 卸货港代码
///
public string DischargePortCode { get; set; }
///
/// 客服
///
public long CustomerService { get; set; }
///
/// 客服名称
///
public string CustomerServiceName { get; set; }
///
/// 船名
///
public string Vessel { get; set; }
///
/// 海关航次
///
public string Voyno { get; set; }
///
/// Desc:单证
///
public long Doc { get; set; }
///
/// Desc:单证人员
///
public string DocName { get; set; }
///
/// Desc:月结算时间
///
public DateTime? StlDate { get; set; }
///
/// 结算方式
///
public string StlName { get; set; }
///
/// 委托编号
///
public string CustomerNo { get; set; }
///
/// 操作员
///
public long OperatorId { get; set; }
///
/// 操作员名称
///
public string OperatorName { get; set; }
}
}