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.

2839 lines
121 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;
using MathNet.Numerics.LinearAlgebra.Factorization;
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>
/// <param name="isExport">是否导出</param>
/// <returns>返回回执</returns>
public async Task<DataResult<List<BLIssueManageBaseDto>>> GetPageAsync(PageRequest querySearch,bool isExport = false)
{
/*
1、海运出口的订单数据跟提单管理表的数据关联有提单记录的以提单记录为准。
*/
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
List<IConditionalModel> 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<SeaExport>().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<SeaExportBillManage>((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<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.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<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;
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<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 querySearch,out BLIssueMangeQueryExtDto queryExt)
{
List<IConditionalModel> whereList = null;
queryExt = new BLIssueMangeQueryExtDto();
if (!string.IsNullOrWhiteSpace(querySearch.OtherQueryCondition))
{
queryExt = JsonConvert.DeserializeObject<BLIssueMangeQueryExtDto>(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 打印
/// <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.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<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((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<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();
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<SeaExport>(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<SeaExportBillManage>().ClearFilter(typeof(IOrgId))
.InnerJoin<SeaExport>((l, r) => l.BusinessId == r.Id)
.LeftJoin<BLIssueManageBase>((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<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();
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<SeaExportBillManage>(data.sub).UpdateColumns(x => new
{
x.BLIssueStatus,
x.BLIssueStatusName,
x.UpdateBy,
x.UpdateUserName,
x.UpdateTime,
}).ExecuteCommandAsync();
}
}
#endregion
}
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.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<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((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<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();
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<SeaExport>(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<SeaExportBillManage>().ClearFilter(typeof(IOrgId))
.InnerJoin<SeaExport>((l, r) => l.BusinessId == r.Id)
.LeftJoin<BLIssueManageBase>((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<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();
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<SeaExport>(data.order).UpdateColumns(x => new
{
x.BLIssueStatus,
x.BLIssueStatusName,
x.UpdateBy,
x.UpdateUserName,
x.UpdateTime,
}).ExecuteCommandAsync();
}
}
}
#endregion
}
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.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<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((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<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.CheckOut.ToString(),
ActionName = BLIssueActionEnum.CheckOut.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable<BLIssueManageLog>(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<SeaExport>(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<SeaExportBillManage>().ClearFilter(typeof(IOrgId))
.InnerJoin<SeaExport>((l, r) => l.BusinessId == r.Id)
.LeftJoin<BLIssueManageBase>((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<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.CheckOut.ToString(),
ActionName = BLIssueActionEnum.CheckOut.GetDescription(),
Note = model.Notes,
Result = "成功",
CreateBy = long.Parse(user.UserId),
CreateUserName = user.UserName,
CreateTime = nowDate,
};
await tenantDb.Insertable<BLIssueManageLog>(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<SeaExportBillManage>(data.sub).UpdateColumns(x => new
{
x.BLIssueStatus,
x.BLIssueStatusName,
x.UpdateBy,
x.UpdateUserName,
x.UpdateTime,
}).ExecuteCommandAsync();
}
}
#endregion
}
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.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<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((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<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();
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<SeaExport>(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<SeaExportBillManage>().ClearFilter(typeof(IOrgId))
.InnerJoin<SeaExport>((l, r) => l.BusinessId == r.Id)
.LeftJoin<BLIssueManageBase>((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<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();
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<SeaExportBillManage>(data.sub).UpdateColumns(x => new
{
x.BLIssueStatus,
x.BLIssueStatusName,
x.UpdateBy,
x.UpdateUserName,
x.UpdateTime,
}).ExecuteCommandAsync();
}
}
}
#endregion
}
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.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<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((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<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();
}
}
}
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<SeaExportBillManage>().ClearFilter(typeof(IOrgId))
.InnerJoin<SeaExport>((l, r) => l.BusinessId == r.Id)
.LeftJoin<BLIssueManageBase>((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<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();
}
}
#endregion
}
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.Count == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var checkIds = model.bookids.Select(a => a.bookid).ToArray();
var orderList = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((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<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.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<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((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<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();
}
}
}
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<SeaExportBillManage>().ClearFilter(typeof(IOrgId))
.InnerJoin<SeaExport>((l, r) => l.BusinessId == r.Id)
.LeftJoin<BLIssueManageBase>((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<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();
}
}
#endregion
}
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.Count == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var checkIds = model.bookids.Select(a => a.bookid).ToArray();
var orderList = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((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<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.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<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((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<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();
}
}
}
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<SeaExportBillManage>().ClearFilter(typeof(IOrgId))
.InnerJoin<SeaExport>((l, r) => l.BusinessId == r.Id)
.LeftJoin<BLIssueManageBase>((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<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();
}
}
#endregion
}
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.Count == 0)
return DataResult.Failed("请求参数错误,请选择提单记录");
var checkIds = model.bookids.Select(a => a.bookid).ToArray();
var orderList = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((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<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.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<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((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<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();
}
}
}
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<SeaExportBillManage>().ClearFilter(typeof(IOrgId))
.InnerJoin<SeaExport>((l, r) => l.BusinessId == r.Id)
.LeftJoin<BLIssueManageBase>((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<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();
}
}
#endregion
}
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.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<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((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<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();
}
}
}
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<SeaExportBillManage>().ClearFilter(typeof(IOrgId))
.InnerJoin<SeaExport>((l, r) => l.BusinessId == r.Id)
.LeftJoin<BLIssueManageBase>((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<BLIssueManageBase>(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<BLIssueManageLog>(log).ExecuteCommandAsync();
}
}
#endregion
}
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.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<SeaExport>().ClearFilter(typeof(IOrgId))
.LeftJoin<BLIssueManageBase>((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<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();
}
}
}
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<SeaExportBillManage>().ClearFilter(typeof(IOrgId))
.InnerJoin<SeaExport>((l, r) => l.BusinessId == r.Id)
.LeftJoin<BLIssueManageBase>((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<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();
}
}
#endregion
}
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="hOrder">分单详情</param>
/// <param name="isHouseBill">是否分单 true-分单 false-主单</param>
/// <param name="busiTypeEnum">业务类型</param>
/// <returns></returns>
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
{
/// <summary>
/// 订单主键
/// </summary>
public long Id { get; set; }
/// <summary>
/// 订单类型M-主票 H-分票)
/// </summary>
public string BillType { get; set; }
/// <summary>
/// 主单ID
/// </summary>
public long ParentId { get; set; }
/// <summary>
/// 主提单号
/// </summary>
public string MBLNO { get; set; }
/// <summary>
/// 分提单号
/// </summary>
public string HBLNO { get; set; }
/// <summary>
/// 委托单位Id
/// </summary>
public long CustomerId { get; set; }
/// <summary>
/// 委托单位
/// </summary>
public string CustomerName { get; set; }
/// <summary>
/// 揽货人Id
/// </summary>
public long SaleId { get; set; }
/// <summary>
/// 揽货人
/// </summary>
public string Sale { get; set; }
/// <summary>
/// 开船日期
/// </summary>
public DateTime? ETD { get; set; }
/// <summary>
/// 预抵日期
/// </summary>
public DateTime? ETA { get; set; }
/// <summary>
/// 签单方式
/// </summary>
public string IssueType { get; set; }
/// <summary>
/// 签单方式代码
/// </summary>
public string IssueTypeCode { get; set; }
/// <summary>
/// 签单地点Id
/// </summary>
public long IssuePlaceId { get; set; }
/// <summary>
/// 签单地点
/// </summary>
public string IssuePlace { get; set; }
/// <summary>
/// 签单地点代码
/// </summary>
public string IssuePlaceCode { get; set; }
/// <summary>
/// 装货港Id
/// </summary>
public long LoadPortId { get; set; }
/// <summary>
/// 装货港
/// </summary>
public string LoadPort { get; set; }
/// <summary>
/// 装货港代码
/// </summary>
public string LoadPortCode { get; set; }
/// <summary>
/// 卸货港Id
/// </summary>
public long DischargePortId { get; set; }
/// <summary>
/// 卸货港
/// </summary>
public string DischargePort { get; set; }
/// <summary>
/// 卸货港代码
/// </summary>
public string DischargePortCode { get; set; }
/// <summary>
/// 客服
/// </summary>
public long CustomerService { get; set; }
/// <summary>
/// 客服名称
/// </summary>
public string CustomerServiceName { get; set; }
/// <summary>
/// 船名
/// </summary>
public string Vessel { get; set; }
/// <summary>
/// 海关航次
/// </summary>
public string Voyno { get; set; }
/// <summary>
/// Desc:单证
/// </summary>
public long Doc { get; set; }
/// <summary>
/// Desc:单证人员
/// </summary>
public string DocName { get; set; }
/// <summary>
/// Desc:月结算时间
/// </summary>
public DateTime? StlDate { get; set; }
/// <summary>
/// 结算方式
/// </summary>
public string StlName { get; set; }
/// <summary>
/// 委托编号
/// </summary>
public string CustomerNo { get; set; }
/// <summary>
/// 操作员
/// </summary>
public long OperatorId { get; set; }
/// <summary>
/// 操作员名称
/// </summary>
public string OperatorName { get; set; }
}
}