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.

1878 lines
83 KiB
C#

This file contains ambiguous Unicode characters!

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

using 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;
namespace DS.WMS.Core.Op.Method
{
/// <summary>
///
/// </summary>
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<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
_seaExportService = _serviceProvider.GetRequiredService<ISeaExportService>();
}
#region 提单管理台账查询
/// <summary>
/// 提单管理台账查询
/// </summary>
/// <param name="querySearch">查询条件</param>
/// <returns>返回回执</returns>
public async Task<DataResult<List<BLIssueManageBaseDto>>> GetPageAsync(PageRequest<BLIssueMangeQueryExtDto> querySearch)
{
/*
1、海运出口的订单数据跟提单管理表的数据关联有提单记录的以提单记录为准。
*/
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
List<IConditionalModel> whereList = null;
BLIssueMangeQueryExtDto otherQueryCondition = querySearch.OtherQueryCondition;
whereList = GetPageCondition(querySearch,out otherQueryCondition);
var eqlStatus = new string[] { "StatusModify", "ReleaseNotice", "BLModify", "CheckOut", "CheckIn", "BLSeize", "ChangeEndorse", "RejectReleaeNotice" };
var query = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((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.QueryTabCode.Equals("M", StringComparison.OrdinalIgnoreCase), (l, r) => l.ParentId == 0)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.MHouseFlag)
&& otherQueryCondition.QueryTabCode.Equals("H", StringComparison.OrdinalIgnoreCase), (l, r) => l.ParentId > 0)
.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))
.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.Doc.HasValue, (l, r) => l.Doc == otherQueryCondition.Doc.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);
}
var result = await query.ToQueryPageAsync(querySearch.PageCondition);
List<BLIssueManageBaseDto> resultList = new List<BLIssueManageBaseDto>();
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<BLIssueManageBaseDto>();
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;
resultList.Add(currBl);
continue;
}
resultList.Add(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,
Doc = data.order.Doc,
DocName = data.order.DocName,
});
start++;
}
}
return DataResult<List<BLIssueManageBaseDto>>.PageList(result.Count, resultList, MultiLanguageConst.DataQuerySuccess);
}
#endregion
#region 获取导出数据列表
/// <summary>
/// 获取导出数据列表
/// </summary>
/// <param name="querySearch">查询条件</param>
/// <returns>返回回执</returns>
public async Task<DataResult<List<BLIssueManageBaseDto>>> GetExportList(PageRequest<BLIssueMangeQueryExtDto> querySearch)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
List<IConditionalModel> whereList = null;
BLIssueMangeQueryExtDto otherQueryCondition = querySearch.OtherQueryCondition;
whereList = GetPageCondition(querySearch, out otherQueryCondition);
var eqlStatus = new string[] { "StatusModify", "ReleaseNotice", "BLModify", "CheckOut", "CheckIn", "BLSeize", "ChangeEndorse", "RejectReleaeNotice" };
var query = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((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.QueryTabCode.Equals("M", StringComparison.OrdinalIgnoreCase), (l, r) => l.ParentId == 0)
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.MHouseFlag)
&& otherQueryCondition.QueryTabCode.Equals("H", StringComparison.OrdinalIgnoreCase), (l, r) => l.ParentId > 0)
.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))
.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.Doc.HasValue, (l, r) => l.Doc == otherQueryCondition.Doc.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);
}
querySearch.PageCondition.PageSize = Int16.MaxValue;
var result = await query.ToQueryPageAsync(querySearch.PageCondition);
List<BLIssueManageBaseDto> resultList = new List<BLIssueManageBaseDto>();
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<BLIssueManageBaseDto>();
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;
resultList.Add(currBl);
continue;
}
resultList.Add(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,
Doc = data.order.Doc,
DocName = data.order.DocName,
});
start++;
}
}
return DataResult<List<BLIssueManageBaseDto>>.PageList(result.Count, resultList, MultiLanguageConst.DataQuerySuccess);
}
#endregion
#region 获取台账查询条件
/// <summary>
/// 获取台账查询条件
/// </summary>
/// <param name="querySearch">原始查询条件</param>
/// <param name="queryExt">其他查询条件</param>
/// <returns></returns>
private List<IConditionalModel> GetPageCondition(PageRequest<BLIssueMangeQueryExtDto> querySearch,out BLIssueMangeQueryExtDto queryExt)
{
List<IConditionalModel> whereList = null;
queryExt = 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("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))
{
querySearch.OtherQueryCondition.ETDStart = currDate;
}
}
else if (b.ConditionalType == ConditionalType.LessThanOrEqual)
{
DateTime currDate = DateTime.MinValue;
if (DateTime.TryParse(b.FieldValue, out currDate))
{
querySearch.OtherQueryCondition.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))
{
querySearch.OtherQueryCondition.CheckInDateStart = currDate;
}
}
else if (b.ConditionalType == ConditionalType.LessThanOrEqual)
{
DateTime currDate = DateTime.MinValue;
if (DateTime.TryParse(b.FieldValue, out currDate))
{
querySearch.OtherQueryCondition.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))
{
querySearch.OtherQueryCondition.CheckOutDateStart = currDate;
}
}
else if (b.ConditionalType == ConditionalType.LessThanOrEqual)
{
DateTime currDate = DateTime.MinValue;
if (DateTime.TryParse(b.FieldValue, out currDate))
{
querySearch.OtherQueryCondition.CheckOutDateEnd = currDate.AddDays(1);
}
}
whereList.Remove(b);
}
}
#endregion
}
return whereList;
}
#endregion
#region 打印
/// <summary>
/// 打印
/// </summary>
/// <param name="id">提单管理主键</param>
/// <returns>返回回执</returns>
public async Task<DataResult<string>> Print(long id)
{
return null;
}
#endregion
#region 提单签入
/// <summary>
/// 提单签入
/// </summary>
/// <param name="model">提单签入请求</param>
/// <returns>返回回执</returns>
public async Task<DataResult> BLCheckIn(BLCheckInOutDto model)
{
/*
1、判断是否已签入已签入的不能重复签入
*/
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Length == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var orderList = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((l, r) => l.Id == r.BookingId)
.Where((l,r) => model.bookids.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
if (orderList.Count != model.bookids.Length)
{
return DataResult.Failed("部分订单查询失败,请重新查询台账");
}
DateTime nowDate = DateTime.Now;
foreach(var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order);
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<BLIssueManageBase>(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<BLIssueManageLog>(log).ExecuteCommandAsync();
}
}
return DataResult.Successed("成功");
}
#endregion
#region 保存提单管理信息
/// <summary>
/// 保存提单管理信息
/// </summary>
/// <param name="model">提单管理详情</param>
/// <param name="isLoadInfo">是否提取详情</param>
/// <returns>返回ID</returns>
public async Task<DataResult<BLIssueManageBase>> Save(BLIssueManageBaseInputDto model,bool isLoadInfo = false)
{
BLIssueManageBase info = null;
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
try
{
if (model.Id == 0)
{
info = model.Adapt<BLIssueManageBase>();
tenantDb.Insertable<BLIssueManageBase>(info).ExecuteReturnEntity();
}
else
{
if (isLoadInfo)
info = tenantDb.Queryable<BLIssueManageBase>().First(a => a.Id == model.Id);
}
}
catch(Exception ex)
{
Logger.Log(NLog.LogLevel.Info, $"提单管理保存失败,原因:{ex.Message} json={JsonConvert.SerializeObject(model)}");
}
return DataResult<BLIssueManageBase>.Success(info);
}
#endregion
#region 取消提单签入
/// <summary>
/// 取消提单签入
/// </summary>
/// <param name="model">取消提单签入请求</param>
/// <returns>返回回执</returns>
public async Task<DataResult> BLCheckInCancel(BLCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Length == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var orderList = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((l, r) => l.Id == r.BookingId)
.Where((l, r) => model.bookids.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
if (orderList.Count != model.bookids.Length)
{
return DataResult.Failed("部分订单查询失败,请重新查询台账");
}
DateTime nowDate = DateTime.Now;
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<BLIssueManageBase>(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<BLIssueManageLog>(log).ExecuteCommandAsync();
}
}
}
return DataResult.Successed("成功");
}
#endregion
#region 提单签出
/// <summary>
/// 提单签出
/// </summary>
/// <param name="model">提单签入请求</param>
/// <returns>返回回执</returns>
public async Task<DataResult> BLCheckOut(BLCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Length == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var orderList = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((l, r) => l.Id == r.BookingId)
.Where((l, r) => model.bookids.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
if (orderList.Count != model.bookids.Length)
{
return DataResult.Failed("部分订单查询失败,请重新查询台账");
}
DateTime nowDate = DateTime.Now;
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order);
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<BLIssueManageBase>(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.CheckIn.ToString(),
ActionName = BLIssueActionEnum.CheckIn.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable<BLIssueManageLog>(log).ExecuteCommandAsync();
}
}
return DataResult.Successed("");
}
#endregion
#region 取消提单签出
/// <summary>
/// 取消提单签出
/// </summary>
/// <param name="model">取消提单签入请求</param>
/// <returns>返回回执</returns>
public async Task<DataResult> BLCheckOutCancel(BLCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Length == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var orderList = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((l, r) => l.Id == r.BookingId)
.Where((l, r) => model.bookids.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
if (orderList.Count != model.bookids.Length)
{
return DataResult.Failed("部分订单查询失败,请重新查询台账");
}
DateTime nowDate = DateTime.Now;
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<BLIssueManageBase>(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<BLIssueManageLog>(log).ExecuteCommandAsync();
}
}
}
return DataResult.Successed("成功");
}
#endregion
#region 船证签入
/// <summary>
/// 船证签入
/// </summary>
/// <param name="model">船证签入请求</param>
/// <returns>返回回执</returns>
public async Task<DataResult> ShipCertCheckIn(ShipCertCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Length == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var orderList = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((l, r) => l.Id == r.BookingId)
.Where((l, r) => model.bookids.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
if (orderList.Count != model.bookids.Length)
{
return DataResult.Failed("部分订单查询失败,请重新查询台账");
}
DateTime nowDate = DateTime.Now;
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order);
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<BLIssueManageBase>(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<BLIssueManageLog>(log).ExecuteCommandAsync();
}
}
return DataResult.Successed("成功");
}
#endregion
#region 取消船证签入
/// <summary>
/// 取消船证签入
/// </summary>
/// <param name="model">取消船证签入请求</param>
/// <returns>返回回执</returns>
public async Task<DataResult> ShipCertCheckInCancel(ShipCertCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Length == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var orderList = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((l, r) => l.Id == r.BookingId)
.Where((l, r) => model.bookids.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
if (orderList.Count != model.bookids.Length)
{
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<BLIssueManageBase>(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<BLIssueManageLog>(log).ExecuteCommandAsync();
}
}
}
return DataResult.Successed("成功");
}
#endregion
#region 船证签出
/// <summary>
/// 船证签出
/// </summary>
/// <param name="model">船证签出请求</param>
/// <returns>返回回执</returns>
public async Task<DataResult> ShipCertCheckOut(ShipCertCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Length == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var orderList = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((l, r) => l.Id == r.BookingId)
.Where((l, r) => model.bookids.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
if (orderList.Count != model.bookids.Length)
{
return DataResult.Failed("部分订单查询失败,请重新查询台账");
}
DateTime nowDate = DateTime.Now;
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order);
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<BLIssueManageBase>(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<BLIssueManageLog>(log).ExecuteCommandAsync();
}
}
return DataResult.Successed("成功");
}
#endregion
#region 取消船证签出
/// <summary>
/// 取消船证签出
/// </summary>
/// <param name="model">取消船证签出请求</param>
/// <returns>返回回执</returns>
public async Task<DataResult> ShipCertCheckOutCancel(ShipCertCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Length == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var orderList = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((l, r) => l.Id == r.BookingId)
.Where((l, r) => model.bookids.Contains(l.Id) && l.Deleted == false)
.Select((l, r) => new { order = l, bl = r })
.ToList();
if (orderList.Count != model.bookids.Length)
{
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<BLIssueManageBase>(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<BLIssueManageLog>(log).ExecuteCommandAsync();
}
}
}
return DataResult.Successed("成功");
}
#endregion
#region 提单换签(背书)
/// <summary>
/// 提单换签(背书)
/// </summary>
/// <param name="model">提单换签(背书)请求</param>
/// <returns>返回回执</returns>
public async Task<DataResult> BLCheckChangeEndorse(BLCheckInOutDto model)
{
/*
只能提单签入才能换单背书
*/
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Length == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var orderList = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((l, r) => l.Id == r.BookingId)
.Where((l, r) => model.bookids.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} 不能操作,只有已提单已签入才能进行 提单换签(背书)");
}
DateTime nowDate = DateTime.Now;
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order);
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<BLIssueManageBase>(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<BLIssueManageLog>(log).ExecuteCommandAsync();
}
}
return DataResult.Successed("成功");
}
#endregion
#region 取消提单换签(背书)
/// <summary>
/// 取消提单换签(背书)
/// </summary>
/// <param name="model">取消提单换签(背书)请求</param>
/// <returns>返回回执</returns>
public async Task<DataResult> BLCheckChangeEndorseCancel(BLCheckInOutDto model)
{
/*
只能提单签入才能换单背书
*/
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Length == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var orderList = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((l, r) => l.Id == r.BookingId)
.Where((l, r) => model.bookids.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} 不能操作,只有已提单已签入才能进行 提单换签(背书)");
}
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<BLIssueManageBase>(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<BLIssueManageLog>(log).ExecuteCommandAsync();
}
}
return DataResult.Successed("成功");
}
#endregion
#region 驳回放单通知
/// <summary>
/// 驳回放单通知
/// </summary>
/// <param name="model">驳回放单通知请求</param>
/// <returns>返回回执</returns>
public async Task<DataResult> BLRejectReleaseNotice(BLCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Length == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var orderList = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((l, r) => l.Id == r.BookingId)
.Where((l, r) => model.bookids.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} 不能操作,只有已提单已签入才能进行 驳回放单通知");
}
DateTime nowDate = DateTime.Now;
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order);
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<BLIssueManageBase>(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<BLIssueManageLog>(log).ExecuteCommandAsync();
}
}
return DataResult.Successed("成功");
}
#endregion
#region 更改提单(其他)
/// <summary>
/// 更改提单(其他)
/// </summary>
/// <param name="model">更改提单请求</param>
/// <returns>返回回执</returns>
public async Task<DataResult> BLModify(BLCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Length == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var orderList = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((l, r) => l.Id == r.BookingId)
.Where((l, r) => model.bookids.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} 不能操作,只有已提单已签入才能进行 更改提单(其他)");
}
DateTime nowDate = DateTime.Now;
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order);
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<BLIssueManageBase>(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<BLIssueManageLog>(log).ExecuteCommandAsync();
}
}
return DataResult.Successed("成功");
}
#endregion
#region 状态更改
/// <summary>
/// 状态更改
/// </summary>
/// <param name="model">状态更改请求</param>
/// <returns>返回回执</returns>
public async Task<DataResult> BLModifyStatus(BLCheckInOutDto model)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (model.bookids.Length == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var orderList = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((l, r) => l.Id == r.BookingId)
.Where((l, r) => model.bookids.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} 不能操作,只有已提单已签入才能进行 状态更改");
}
DateTime nowDate = DateTime.Now;
foreach (var data in orderList)
{
var blModel = data.bl;
if (blModel == null || blModel.Id == 0)
{
var dto = GetReadSaveInfo(data.order);
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<BLIssueManageBase>(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<BLIssueManageLog>(log).ExecuteCommandAsync();
}
}
return DataResult.Successed("成功");
}
#endregion
#region 查询单票的提单管理日志
/// <summary>
/// 查询单票的提单管理日志
/// </summary>
/// <param name="id">提单管理主键</param>
/// <returns>返回日志列表</returns>
public async Task<DataResult<List<BusinessTaskLogDto>>> GetLogs(long id)
{
List<BusinessTaskLogDto> list = new List<BusinessTaskLogDto>();
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
//这里如果遇到id小于5位时表示ID不是虚拟的不能进行库查询
if (id.ToString().Length > 5)
{
var logList = tenantDb.Queryable<BLIssueManageLog>().Where(a => a.Pid == id).ToList();
if (logList.Count > 0)
{
list = logList.OrderByDescending(a => a.CreateTime).Adapt<List<BusinessTaskLogDto>>();
}
}
return DataResult<List<BusinessTaskLogDto>>.Success(list);
}
#endregion
#region 获取相关信息
/// <summary>
/// 获取相关信息
/// </summary>
/// <param name="id">提单管理主键</param>
/// <returns>返回相关信息</returns>
public async Task<DataResult<BLIssueCustomerDto>> GetRelateInfo(long id)
{
BLIssueCustomerDto model = new BLIssueCustomerDto();
return DataResult<BLIssueCustomerDto>.Success(model);
}
#endregion
#region 获取欠费详情列表
/// <summary>
/// 获取欠费详情列表
/// </summary>
/// <param name="id">提单管理主键</param>
/// <returns>返回列表</returns>
public async Task<DataResult<List<BLOverdueFeeDto>>> GetOverdueFeeList(long id)
{
List<BLOverdueFeeDto> list = new List<BLOverdueFeeDto>();
return DataResult<List<BLOverdueFeeDto>>.Success(list);
}
#endregion
#region 获取初始化提单管理详情
/// <summary>
/// 获取初始化提单管理详情
/// </summary>
/// <param name="tempId">临时ID</param>
/// <param name="order">订单详情</param>
/// <param name="busiTypeEnum">业务类型</param>
/// <returns></returns>
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 获取待保存提单管理详情
/// <summary>
/// 获取待保存提单管理详情
/// </summary>
/// <param name="order">订单详情</param>
/// <param name="busiTypeEnum">业务类型</param>
/// <returns></returns>
private BLIssueManageBaseInputDto GetReadSaveInfo(SeaExport order, BLIssueBusiTypeEnum busiTypeEnum = BLIssueBusiTypeEnum.SeaExport)
{
return new BLIssueManageBaseInputDto
{
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(),
};
}
#endregion
}
}