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.
462 lines
17 KiB
C#
462 lines
17 KiB
C#
using AngleSharp.Dom;
|
|
using DS.Module.Core;
|
|
using DS.Module.Core.Extensions;
|
|
using DS.Module.SqlSugar;
|
|
using DS.Module.UserModule;
|
|
using DS.WMS.Core.Code.Entity;
|
|
using DS.WMS.Core.Fee.Entity;
|
|
using DS.WMS.Core.Op.Dtos;
|
|
using DS.WMS.Core.Op.Entity;
|
|
using DS.WMS.Core.Op.Interface;
|
|
using DS.WMS.Core.System.Interface;
|
|
using DS.WMS.Core.System.Method;
|
|
using Mapster;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Serialization;
|
|
using Org.BouncyCastle.Ocsp;
|
|
using SqlSugar;
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
|
|
namespace DS.WMS.Core.Op.Method;
|
|
|
|
public class SeaExportService : ISeaExportService
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly ISqlSugarClient db;
|
|
private readonly IUser user;
|
|
private readonly ISaasDbService saasService;
|
|
|
|
private readonly ICommonService commonService;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="serviceProvider"></param>
|
|
public SeaExportService(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
|
|
commonService = _serviceProvider.GetRequiredService<ICommonService>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 列表
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
public DataResult<List<SeaExportRes>> GetListByPage(PageRequest request)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
//序列化查询条件
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
var data = tenantDb.Queryable<SeaExport>()
|
|
.Where(whereList)
|
|
.Select<SeaExportRes>().ToQueryPage(request.PageCondition);
|
|
return data;
|
|
}
|
|
/// <summary>
|
|
/// 编辑
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
public DataResult EditSeaExport(SeaExportReq req)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
if (req.Id == 0)
|
|
{
|
|
if (req.BLType != "拼箱分票" && tenantDb.Queryable<SeaExport>().Where(x => x.MBLNO == req.MBLNO.Trim()).Any())
|
|
{
|
|
return DataResult.Failed("海运出口信息主提单号已存在!", MultiLanguageConst.SeaExportMBLNOExist);
|
|
}
|
|
if (tenantDb.Queryable<SeaExport>().Where(x => x.HBLNO == req.HBLNO.Trim()).Any())
|
|
{
|
|
return DataResult.Failed("海运出口信息分提单号已存在!", MultiLanguageConst.SeaExportHBLNOExist);
|
|
}
|
|
//TODO 会计期间不允许小于已结转期间
|
|
if (req.CloseDocDate.IsNotNull() && req.CloseDocDate < req.ETD)
|
|
{
|
|
return DataResult.Failed("截单日期不允许小于开船日期!", MultiLanguageConst.SeaExportCloseDocDateLimit);
|
|
}
|
|
if (req.ClosingDate.IsNotNull() && req.ClosingDate < req.ETD)
|
|
{
|
|
return DataResult.Failed("截港日期不允许小于开船日期!", MultiLanguageConst.SeaExportCloseDateLimit);
|
|
}
|
|
var sequence = commonService.GetSequenceNext<SeaExport>();
|
|
if (!sequence.Succeeded)
|
|
{
|
|
return DataResult.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist);
|
|
}
|
|
var data = req.Adapt<SeaExport>();
|
|
data.CustomerNo = sequence.Data;
|
|
|
|
var entity = tenantDb.Insertable(data).ExecuteReturnEntity();
|
|
|
|
if (req.CtnInfo.Count > 0)
|
|
{
|
|
|
|
foreach (var item in req.CtnInfo)
|
|
{
|
|
var ctn = item.Adapt<OpCtn>();
|
|
ctn.BSNO = entity.Id.ToString();
|
|
tenantDb.Insertable(ctn).ExecuteCommand();
|
|
}
|
|
}
|
|
|
|
return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
|
|
}
|
|
else
|
|
{
|
|
var info = tenantDb.Queryable<SeaExport>().Where(x => x.Id == req.Id).First();
|
|
|
|
|
|
if ((bool)info.IsBusinessLocking)
|
|
{
|
|
return DataResult.Failed("海运出口信息业务已锁定!", MultiLanguageConst.SeaExportBusinessLock);
|
|
}
|
|
info = req.Adapt(info);
|
|
//TODO 会计期间不允许小于已结转期间
|
|
if (info.CloseDocDate.IsNotNull() && info.CloseDocDate < info.ETD)
|
|
{
|
|
return DataResult.Failed("截单日期不允许小于开船日期!", MultiLanguageConst.SeaExportCloseDocDateLimit);
|
|
}
|
|
if (info.ClosingDate.IsNotNull() && info.ClosingDate < info.ETD)
|
|
{
|
|
return DataResult.Failed("截港日期不允许小于开船日期!", MultiLanguageConst.SeaExportCloseDateLimit);
|
|
}
|
|
tenantDb.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).EnableDiffLogEvent().ExecuteCommand();
|
|
|
|
|
|
if (req.CtnInfo.Count > 0)
|
|
{
|
|
var ctnList = tenantDb.Queryable<OpCtn>().Where(x => x.BSNO == req.Id.ToString()).ToList();
|
|
foreach (var item in req.CtnInfo)
|
|
{
|
|
|
|
var ctn = ctnList.First(x => x.Id == item.Id);
|
|
ctn = item.Adapt(ctn);
|
|
tenantDb.Updateable(ctn).ExecuteCommand();
|
|
}
|
|
}
|
|
|
|
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 详情
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public DataResult<SeaExportRes> GetSeaExportInfo(string id)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var data = tenantDb.Queryable<SeaExport>()
|
|
.Where(a => a.Id == long.Parse(id))
|
|
.Select<SeaExportRes>()
|
|
.First();
|
|
return DataResult<SeaExportRes>.Success(data, MultiLanguageConst.DataQuerySuccess);
|
|
}
|
|
/// <summary>
|
|
/// 批量更新
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
public DataResult SeaExportBatchEdit(SeaExportBatchEditReq req)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
if (req.Ids.Count == 0)
|
|
{
|
|
return DataResult.Failed("海运出口批量编辑未勾选!", MultiLanguageConst.SeaExportBatchEditNoSelect);
|
|
}
|
|
if (tenantDb.Queryable<SeaExport>().Where(x => !req.Ids.Contains(x.Id)).Any().IsNull())
|
|
{
|
|
return DataResult.Failed("不存在的海运出口信息!", MultiLanguageConst.SeaExportExist);
|
|
}
|
|
if (tenantDb.Queryable<SeaExport>().Where(x => req.Ids.Contains(x.Id) && x.IsBusinessLocking == true).Any())
|
|
{
|
|
return DataResult.Failed("海运出口信息业务已锁定!", MultiLanguageConst.SeaExportBusinessLock);
|
|
}
|
|
|
|
if (req.AccountDate.ToString().IsNotNull())
|
|
{
|
|
if (tenantDb.Queryable<SeaExport>().Where(x => req.Ids.Contains(x.Id) && x.IsFeeLocking == true).Any())
|
|
{
|
|
return DataResult.Failed("海运出口信息费用已锁定!", MultiLanguageConst.SeaExportFeeLock);
|
|
}
|
|
}
|
|
var orderList = tenantDb.Queryable<SeaExport>().Where(x => req.Ids.Contains(x.Id)).ToList();
|
|
|
|
var dic = req.GetPropertiesArray();
|
|
|
|
foreach (var item in orderList)
|
|
{
|
|
var info = item;
|
|
info = req.Adapt(info);
|
|
tenantDb.Updateable(info).UpdateColumns(dic).EnableDiffLogEvent().ExecuteCommand();
|
|
}
|
|
|
|
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 业务单据单票复制
|
|
/// </summary>
|
|
/// <param name="id">业务Id</param>
|
|
/// <returns></returns>
|
|
public DataResult SeaExportCopy(string id)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var info = tenantDb.Queryable<SeaExport>().Where(x => x.Id == long.Parse(id)).First();
|
|
if (info.IsNullOrEmpty())
|
|
{
|
|
return DataResult.Failed("海运出口信息不存在!", MultiLanguageConst.SeaExportNotExist);
|
|
}
|
|
//获取表单复制模板
|
|
var template = tenantDb.Queryable<CodeFormCopy>().Where(x => x.PermissionId == 1772509201441099776).First();
|
|
var sequence = commonService.GetSequenceNext<SeaExport>();
|
|
if (!sequence.Succeeded)
|
|
{
|
|
return DataResult.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist);
|
|
}
|
|
|
|
var data = new SeaExport();
|
|
if (template.IsNullOrEmpty())
|
|
{
|
|
data = info.Adapt(data);
|
|
data.Id = 0;
|
|
data.ParentId = 0;
|
|
data.IsBusinessLocking = false;
|
|
data.IsFeeLocking = false;
|
|
data.CustomerNo = sequence.Data;
|
|
var entity = tenantDb.Insertable(data).ExecuteReturnEntity();
|
|
return DataResult.Successed("复制成功!", entity.Id, MultiLanguageConst.DataCopySuccess);
|
|
}
|
|
else
|
|
{
|
|
|
|
data = info.Adapt(data);
|
|
data.Id = 0;
|
|
data.ParentId = 0;
|
|
data.IsBusinessLocking = false;
|
|
data.IsFeeLocking = false;
|
|
data.CustomerNo = sequence.Data;
|
|
|
|
var list0 = template.CopyFields.Split(",");
|
|
var list1 = new List<string>();
|
|
foreach (var item in list0)
|
|
{
|
|
list1.Add(item.ToUpperCamelCase());
|
|
}
|
|
list1.Add("IsBusinessLocking");
|
|
list1.Add("IsFeeLocking");
|
|
list1.Add("CustomerNo");
|
|
var insertColumns = list1.ToArray();
|
|
//insertColumns.AddRange(["Id", "ParentId", "IsBusinessLocking", "IsFeeLocking", "CustomerNo"]);
|
|
var entity = tenantDb.Insertable(data).InsertColumns(insertColumns).ExecuteReturnEntity();
|
|
|
|
return DataResult.Successed("复制成功!", entity.Id, MultiLanguageConst.DataCopySuccess);
|
|
}
|
|
|
|
|
|
}
|
|
#region 删除
|
|
|
|
|
|
/// <summary>
|
|
/// 业务单据删除
|
|
/// </summary>
|
|
/// <param name="id">业务Id</param>
|
|
/// <returns></returns>
|
|
public DataResult SeaExportDel(string id)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var info = tenantDb.Queryable<SeaExport>().Where(x => x.Id == long.Parse(id)).First();
|
|
if (info.IsNullOrEmpty())
|
|
{
|
|
return DataResult.Failed("海运出口信息不存在!", MultiLanguageConst.SeaExportNotExist);
|
|
}
|
|
|
|
if (tenantDb.Queryable<SeaExport>().Where(x => x.ParentId == long.Parse(id)).Any())
|
|
{
|
|
return DataResult.Failed("海运出口存在分票信息,不能删除!", MultiLanguageConst.SeaExportPartExist);
|
|
}
|
|
if (tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == long.Parse(id)).Any())
|
|
{
|
|
return DataResult.Failed("海运出口存在费用信息,不能删除!", MultiLanguageConst.SeaExportFeeExist);
|
|
}
|
|
|
|
if ((bool)info.IsBusinessLocking)
|
|
{
|
|
return DataResult.Failed("海运出口信息业务已锁定!", MultiLanguageConst.SeaExportBusinessLock);
|
|
}
|
|
|
|
if ((bool)info.IsFeeLocking)
|
|
{
|
|
return DataResult.Failed("海运出口信息费用已锁定!", MultiLanguageConst.SeaExportFeeLock);
|
|
}
|
|
|
|
info.Deleted = true;
|
|
info.DeleteTime = DateTime.Now;
|
|
info.DeleteBy = long.Parse(user.UserId);
|
|
tenantDb.Updateable(info).ExecuteCommand();
|
|
//tenantDb.Deleteable(info).IsLogic().ExecuteCommand("Deleted");
|
|
|
|
return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 业务单据删除
|
|
/// </summary>
|
|
/// <param name="Ids">业务Ids</param>
|
|
/// <returns></returns>
|
|
public DataResult SeaExportBatchDel(List<long> Ids)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
if (Ids.Count == 0)
|
|
{
|
|
return DataResult.Failed("海运出口批量操作未勾选!", MultiLanguageConst.SeaExportBatchOpNoSelect);
|
|
}
|
|
if (tenantDb.Queryable<SeaExport>().Where(x => Ids.Contains(x.Id)).Any().IsNull())
|
|
{
|
|
return DataResult.Failed("不存在的海运出口信息!", MultiLanguageConst.SeaExportExist);
|
|
}
|
|
if (tenantDb.Queryable<SeaExport>().Where(x => Ids.Contains(x.Id) && x.IsBusinessLocking == true).Any())
|
|
{
|
|
return DataResult.Failed("海运出口信息业务已锁定!", MultiLanguageConst.SeaExportBusinessLock);
|
|
}
|
|
|
|
if (tenantDb.Queryable<SeaExport>().Where(x => Ids.Contains(x.Id) && x.IsFeeLocking == true).Any())
|
|
{
|
|
return DataResult.Failed("海运出口信息费用已锁定!", MultiLanguageConst.SeaExportFeeLock);
|
|
}
|
|
|
|
if (tenantDb.Queryable<SeaExport>().Where(x => Ids.Contains(x.ParentId)).Any())
|
|
{
|
|
return DataResult.Failed("海运出口存在分票信息,不能删除!", MultiLanguageConst.SeaExportPartExist);
|
|
}
|
|
if (tenantDb.Queryable<FeeRecord>().Where(x => Ids.Contains(x.BusinessId)).Any())
|
|
{
|
|
return DataResult.Failed("海运出口存在费用信息,不能删除!", MultiLanguageConst.SeaExportFeeExist);
|
|
}
|
|
|
|
var list = tenantDb.Queryable<SeaExport>().Where(x => Ids.Contains(x.Id)).ToList();
|
|
|
|
//tenantDb.Deleteable(list).IsLogic().ExecuteCommand("Deleted");
|
|
//tenantDb.Deleteable<SeaExport>(list).IsLogic().ExecuteCommand("Deleted");
|
|
foreach (var item in list)
|
|
{
|
|
item.Deleted = true;
|
|
item.DeleteTime = DateTime.Now;
|
|
item.DeleteBy = long.Parse(user.UserId);
|
|
tenantDb.Updateable(item).ExecuteCommand();
|
|
}
|
|
|
|
return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess);
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 费用锁定 业务锁定
|
|
/// <summary>
|
|
/// 业务锁定
|
|
/// </summary>
|
|
/// <param name="id">业务Id</param>
|
|
/// <returns></returns>
|
|
public DataResult SeaExportBusinessLook(string id)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var info = tenantDb.Queryable<SeaExport>().Where(x => x.Id == long.Parse(id)).First();
|
|
if (info.IsNullOrEmpty())
|
|
{
|
|
return DataResult.Failed("海运出口信息不存在!", MultiLanguageConst.SeaExportNotExist);
|
|
}
|
|
if ((bool)info.IsBusinessLocking)
|
|
{
|
|
return DataResult.Failed("海运出口信息业务已锁定!", MultiLanguageConst.SeaExportBusinessLock);
|
|
}
|
|
|
|
info.IsBusinessLocking = true;
|
|
tenantDb.Updateable(info).ExecuteCommand();
|
|
|
|
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
}
|
|
/// <summary>
|
|
/// 费用锁定
|
|
/// </summary>
|
|
/// <param name="id">业务Id</param>
|
|
/// <returns></returns>
|
|
public DataResult SeaExportFeeLook(string id)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var info = tenantDb.Queryable<SeaExport>().Where(x => x.Id == long.Parse(id)).First();
|
|
if (info.IsNullOrEmpty())
|
|
{
|
|
return DataResult.Failed("海运出口信息不存在!", MultiLanguageConst.SeaExportNotExist);
|
|
}
|
|
if ((bool)info.IsFeeLocking)
|
|
{
|
|
return DataResult.Failed("海运出口信息费用已锁定!", MultiLanguageConst.SeaExportFeeLock);
|
|
}
|
|
|
|
info.IsFeeLocking = true;
|
|
tenantDb.Updateable(info).ExecuteCommand();
|
|
|
|
|
|
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 业务解锁
|
|
/// </summary>
|
|
/// <param name="id">业务Id</param>
|
|
/// <returns></returns>
|
|
public DataResult SeaExportBusinessUnLook(string id)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var info = tenantDb.Queryable<SeaExport>().Where(x => x.Id == long.Parse(id)).First();
|
|
if (info.IsNullOrEmpty())
|
|
{
|
|
return DataResult.Failed("海运出口信息不存在!", MultiLanguageConst.SeaExportNotExist);
|
|
}
|
|
if (!(bool)info.IsBusinessLocking)
|
|
{
|
|
return DataResult.Failed("海运出口信息业务锁定已解锁!", MultiLanguageConst.SeaExportBusinessUnLock);
|
|
}
|
|
|
|
info.IsBusinessLocking = false;
|
|
tenantDb.Updateable(info).ExecuteCommand();
|
|
|
|
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
}
|
|
/// <summary>
|
|
/// 费用解锁
|
|
/// </summary>
|
|
/// <param name="id">业务Id</param>
|
|
/// <returns></returns>
|
|
public DataResult SeaExportFeeUnLook(string id)
|
|
{
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var info = tenantDb.Queryable<SeaExport>().Where(x => x.Id == long.Parse(id)).First();
|
|
if (info.IsNullOrEmpty())
|
|
{
|
|
return DataResult.Failed("海运出口信息不存在!", MultiLanguageConst.SeaExportNotExist);
|
|
}
|
|
if (!(bool)info.IsFeeLocking)
|
|
{
|
|
return DataResult.Failed("海运出口信息费用锁定已解锁!", MultiLanguageConst.SeaExportFeeUnLock);
|
|
}
|
|
|
|
info.IsFeeLocking = false;
|
|
tenantDb.Updateable(info).ExecuteCommand();
|
|
|
|
|
|
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
} |