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.

540 lines
20 KiB
C#

4 months ago
using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.ContainerManagement.Info.Dtos;
using DS.WMS.ContainerManagement.Info.Entity;
using DS.WMS.ContainerManagement.Info.Interface;
using DS.WMS.Core.Application.Dtos;
using DS.WMS.Core.Application.Entity;
using DS.WMS.Core;
using DS.WMS.Core.Info.Dtos;
using DS.WMS.Core.Info.Entity;
using DS.WMS.Core.Info.Interface;
using DS.WMS.Core.Invoice.Dtos;
using DS.WMS.Core.Op.View;
using DS.WMS.Core.Sys.Entity;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
using DS.WMS.Core.Fee.Entity;
using DS.WMS.Core.Op.Entity;
using AngleSharp.Dom;
using NPOI.Util;
4 months ago
using DS.WMS.Core.Sys.Method;
using DS.WMS.Core.Fee.Interface;
using DS.WMS.Core.Sys.Interface;
using DS.Module.Core.Enums;
using DS.WMS.Core.TaskPlat.Dtos;
4 months ago
namespace DS.WMS.ContainerManagement.Info.Method;
//<TEntity> : FeeServiceBase, ISettlementService<TEntity> where TEntity : SettlementBase, new ()
public class CM_RentOneWayService : CMServiceBase, ICM_RentOneWayService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
4 months ago
private readonly ICommonService commonService;
readonly IFeeRecordService _feeService;
readonly ICM_State_ChangeService _Changeservice;
private readonly IFeeCurrencyExchangeService feeCurrencyExchangeService;
4 months ago
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public CM_RentOneWayService(IServiceProvider serviceProvider) : base(serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
4 months ago
commonService = _serviceProvider.GetRequiredService<ICommonService>();
_feeService = _serviceProvider.GetRequiredService<IFeeRecordService>();
_Changeservice = _serviceProvider.GetRequiredService<ICM_State_ChangeService>();
feeCurrencyExchangeService = _serviceProvider.GetRequiredService<IFeeCurrencyExchangeService>();
4 months ago
}
/// <summary>
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<DataResult<List<CM_RentOneWayRes>>> GetListByPage(PageRequest request)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = tenantDb.Queryable<CM_RentOneWay>()
.Where(whereList)
.Select<CM_RentOneWayRes>().ToQueryPage(request.PageCondition);
return data;
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public async Task<DataResult> EditCM_RentOneWay(CM_RentOneWayReq req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var ch = new CtnTotalHelper2<List<CM_RentOneWay_DetailReq>>(req.BodyList);
3 months ago
req.CntrnoAll = ch.GetCntrTotalStr();
req.Ctntotal = ch.GetCtnTotalStr();
req.PickupCtntotal = ch.GetStr();
req.RemainCtntotal = ch.GetStr();
req.DropoffCtntotal = ch.GetStr();
req.DropoffRemainCtntotal = ch.GetStr();
4 months ago
if (req.Id == 0)
{
var data = req.Adapt<CM_RentOneWay>();
4 months ago
var sequence = commonService.GetSequenceNext<CM_RentOneWay>();
if (!sequence.Succeeded)
{
return await Task.FromResult(DataResult.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist));
}
data.Billno = sequence.Data;
data.RentDirectId = CMRentDirectEnum.;
data.RentTypeId= CMRentTypeEnum.;
4 months ago
//var entity = tenantDb.Insertable(data).ExecuteReturnEntity();
var entity = await tenantDb.Insertable(data).ExecuteReturnEntityAsync();
if (req.BodyList.Count > 0)
{
//var ctnList = await tenantDb.Queryable<CM_RentOneWay_Detail>().Where(x => x.pid == req.Id.ToString()).ToListAsync();
foreach (var item in req.BodyList)
{
item.Id = 0;
item.Pid = entity.Id;
var newdetail = item.Adapt<CM_RentOneWay_Detail>();
await tenantDb.Insertable(newdetail).ExecuteCommandAsync();
}
}
//return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
return await Task.FromResult(DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess));
}
else
{
var info = await tenantDb.Queryable<CM_RentOneWay>().Where(x => x.Id == req.Id).FirstAsync();
info = req.Adapt(info);
4 months ago
info.RentDirectId = CMRentDirectEnum.;
info.RentTypeId = CMRentTypeEnum.;
4 months ago
await tenantDb.Updateable(info).ExecuteCommandAsync();
if (req.BodyList.Count > 0)
{
var _BodyList = await tenantDb.Queryable<CM_RentOneWay_Detail>().Where(x => x.Pid == req.Id).ToListAsync();
foreach (var item in req.BodyList)
{
if (item.Id == 0)
{
//item.Id = 0;
item.Pid = info.Id;
var newdetail = item.Adapt<CM_RentOneWay_Detail>();
await tenantDb.Insertable(newdetail).ExecuteCommandAsync();
}
else
{
var updrec = _BodyList.First(x => x.Id == item.Id);
updrec = item.Adapt(updrec);
await tenantDb.Updateable(updrec).ExecuteCommandAsync();
}
}
}
return await Task.FromResult(DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess));
}
}
/// <summary>
/// 详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult<CM_RentOneWayRes> GetCM_RentOneWay(string id)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var data = tenantDb.Queryable<CM_RentOneWay>()
.Where(a => a.Id == long.Parse(id))
.Select<CM_RentOneWayRes>()
.First();
return DataResult<CM_RentOneWayRes>.Success(data, MultiLanguageConst.DataQuerySuccess);
}
#region 删除
/// <summary>
/// 删除
/// </summary>
/// <param name="ids">费用记录ID</param>
/// <returns></returns>
public async Task<DataResult> DeleteCM_RentOneWayAsync(params long[] ids)
{
foreach (var _id in ids) {
if (await IsLockedAsync(_id, BusinessType.CM_RentOneWay))
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.FeeLocked));
}
//如果包含费用 不允许删除
var feeCount = await TenantDb.Queryable<FeeRecord>().Where(x => ids.Contains(x.BusinessId)).CountAsync();
if (feeCount > 0) {
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.CM_FeeExist));
}
int result = await TenantDb.Deleteable<CM_RentOneWay>(x => ids.Contains(x.Id)).ExecuteCommandAsync();
if (result > 0) {
//删除所有明细
await TenantDb.Deleteable<CM_RentOneWay_Detail>(x => ids.Contains(x.Pid)).ExecuteCommandAsync();
}
//await WriteBackStatusAsync(model.BusinessId, model.BusinessType);
return result > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
#endregion
4 months ago
/// <summary>
/// 单程_确认
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<DataResult> CM_RentOneWay_Confirm(string id, params long[] ids)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var data = tenantDb.Queryable<CM_RentOneWay>()
.Where(a => a.Id == long.Parse(id))
//.Select<CM_RentInRes>()
.First();
//20240808 首先判断该箱号能否执行确认
//if (!string.IsNullOrWhiteSpace(data.BillState))
//{
// return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
//}
2 months ago
data.BillState = CM_BillStatusEnum..ToInt().ToString();
4 months ago
//data.IsBusinessLocking = true;
var entity = await tenantDb.Updateable(data).ExecuteCommandAsync();
var body = tenantDb.Queryable<CM_RentOneWay_Detail>().Where(a => a.Pid == data.Id).ToList();
//20240826 生成箱状态变动
//如果是提箱/还箱 分别产生变动
foreach (var detail in body)
{
if (detail.PickupPortid != null)
{
var changerec = new CM_State_ChangeReq();
changerec.Cntrno = detail.Cntrno;
changerec.CtnCode = detail.CtnCode;
changerec.Ctnall = detail.Ctnall;
changerec.UsedState = "USED";
changerec.CtnOwnerId = data.OldContainerOwnerId;
changerec.CtnOwner = data.OldContainerOwner;
//默认长租租入
//changerec.CtnSourceId = detail.sour
changerec.CtnBizStateId = CM_CtnBizStateEnum.;
4 months ago
changerec.ChangeSourceId = CMChangeSourceEnum.;
changerec.ChangeSourceDetailId = data.Id;
changerec.CtnFlowStateId = null;
changerec.CtnStateId = CMCtnStateEnum.BK;
changerec.CtnBreakStateId = CMCtnBreakStateEnum.AV;
changerec.IsHeavy = false;
changerec.Billno = detail.Mblno;
//changerec.IsOnlineId = CM_IsOnlineEnum.待上线;
if (detail.PickupPortid != null)
{
changerec.Portid = detail.PickupPortid;
changerec.PortCode = detail.PickupPortCode;
changerec.Port = detail.PickupPort;
}
changerec.ChangeTime = data.Bsdate;
changerec.CtnFlowStateId = null;
//如果没有填写提箱日期 则变动来源id设为租箱主单 变动日期设为业务日期
//如果填写了提箱日期 则变动来源id设为租箱主单 变动日期设为提箱日期
if (detail.PickupDate != null)
{
4 months ago
changerec.CtnStateId = CMCtnStateEnum.AV;
changerec.ChangeSourceDetailId = data.Id;//提箱变动 来源id是头表
2 months ago
//changerec.CtnFlowStateId = CMCtnFlowStateEnum.//.已提箱;
4 months ago
changerec.ChangeTime = detail.PickupDate;
changerec.IsOnlineId = CM_IsOnlineEnum.线;
}
4 months ago
if (changerec.ChangeTime == null) changerec.ChangeTime = DateTime.Now;
//await TenantDb.Insertable(changerec).ExecuteReturnEntityAsync();
//await _Changeservice.UpdateCM_CurrentStateAsync(changerec);
await _Changeservice.AddCM_State_ChangeAsync(changerec);
}
if (detail.DropoffDate != null)
{
var changerec = new CM_State_ChangeReq();
changerec.Cntrno = detail.Cntrno;
changerec.CtnCode = detail.CtnCode;
changerec.Ctnall = detail.Ctnall;
changerec.UsedState = "USED";
changerec.CtnOwnerId = data.OldContainerOwnerId;
changerec.CtnOwner = data.OldContainerOwner;
//默认长租租入
//changerec.CtnSourceId = detail.sour
changerec.CtnBizStateId = CM_CtnBizStateEnum.;
4 months ago
changerec.ChangeSourceId = CMChangeSourceEnum.;
changerec.ChangeSourceDetailId = data.Id;
changerec.CtnFlowStateId = null;
changerec.CtnStateId = CMCtnStateEnum.AV;
changerec.CtnBreakStateId = CMCtnBreakStateEnum.AV;
changerec.IsHeavy = false;
changerec.Billno = detail.Mblno;
//changerec.IsOnlineId = CM_IsOnlineEnum.待上线;
if (detail.DropoffPortid != null)
{
changerec.Portid = detail.DropoffPortid;
changerec.PortCode = detail.DropoffPortCode;
changerec.Port = detail.DropoffPort;
}
changerec.ChangeTime = data.Bsdate;
changerec.CtnFlowStateId = null;
//如果没有填写提箱日期 则变动来源id设为租箱主单 变动日期设为业务日期
//如果填写了提箱日期 则变动来源id设为租箱主单 变动日期设为提箱日期
if (detail.PickupDate != null)
{
4 months ago
changerec.CtnStateId = CMCtnStateEnum.AV;
changerec.ChangeSourceDetailId = detail.Id;//还箱变动 来源是明细表
2 months ago
//changerec.CtnFlowStateId = CMCtnFlowStateEnum//.已还箱;
4 months ago
changerec.ChangeTime = detail.DropoffDate;
changerec.IsOnlineId = CM_IsOnlineEnum.线;
}
4 months ago
if (changerec.ChangeTime == null) changerec.ChangeTime = DateTime.Now;
//await TenantDb.Insertable(changerec).ExecuteReturnEntityAsync();
//await _Changeservice.UpdateCM_CurrentStateAsync(changerec);
await _Changeservice.AddCM_State_ChangeAsync(changerec);
}
}
return await Task.FromResult(DataResult.Successed("添加成功!", id, MultiLanguageConst.DataCreateSuccess));
}
public async Task<DataResult> CM_RentOneWay_Confirm(params long[] ids)
{
var _r = DataResult.Successed("添加成功!", null, MultiLanguageConst.DataCreateSuccess);
foreach (var id in ids)
{
_r = await CM_RentOneWay_Confirm(id.ToString(), null);
}
return _r;
}
/// <summary>
/// 单程_取消
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<DataResult> CM_RentOneWay_Cancel(string id, params long[] ids)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var data = tenantDb.Queryable<CM_RentOneWay>()
.Where(a => a.Id == long.Parse(id))
//.Select<CM_RentInRes>()
.First();
2 months ago
if (data.BillState != CM_BillStatusEnum..ToInt().ToString())
4 months ago
{
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
data.BillState = "";
//data.IsBusinessLocking = false;
var entity = await tenantDb.Updateable(data).ExecuteCommandAsync();
return await Task.FromResult(DataResult.Successed("取消成功!", id, MultiLanguageConst.DataCreateSuccess));
}
public async Task<DataResult> CM_RentOneWay_Cancel(params long[] ids)
{
var _r = DataResult.Successed("取消成功!", null, MultiLanguageConst.DataCreateSuccess);
foreach (var id in ids)
{
_r = await CM_RentOneWay_Cancel(id.ToString(), null);
}
return _r;
}
/// <summary>
/// 单程业务_添加箱
/// </summary>
/// <param name="ids">租出明细ID</param>
/// <returns></returns>
public async Task<DataResult> CM_RentOneWay_AddCtn(long id, params long[] ids)
{
//foreach (var _id in ids)
//{
2 months ago
if (await IsLockedAsync(id, BusinessType.CM_RentIn))
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.FeeLocked));
//}
//
var head = TenantDb.Queryable<CM_RentOneWay>().Where(a => a.Id == id).First();
var CurrentDetailList = TenantDb.Queryable<CM_RentOneWay_Detail>()
.Where(a => a.Pid == id).ToList();
2 months ago
var OnAddDetail = TenantDb.Queryable<CM_RentOneWay_Detail>()
.Where(a => ids.Contains(a.Id)).ToList();
var addList = new List<CM_RentOneWay_Detail>();
2 months ago
if (OnAddDetail != null && OnAddDetail.Count > 0)
{
2 months ago
foreach (var addrec in OnAddDetail)
{
if (CurrentDetailList.Exists(x => x.Cntrno == addrec.Cntrno))
{
//箱号已存在 就不添加
}
else
{
var newrec = new CM_RentOneWay_Detail();
newrec = addrec.Adapt<CM_RentOneWay_Detail>();
newrec.Id = 0;
newrec.Pid = id;
newrec.RentDirectId = CMRentDirectEnum.;
newrec.DropoffDate = head.Bsdate;
newrec.RentDetailId = addrec.Id;//
//newrec.PickupPortid = null;
//newrec.PickupPort = null;
//newrec.PickupPortCode = null;
//newrec.PickupDate = null;
2 months ago
newrec.CtnReleaseNo_In = addrec.CtnReleaseNo;
newrec.CtnReleaseNo = "";
//if (string.IsNullOrWhiteSpace(head.CtnReleaseNo)) {
//}
addList.Add(newrec);
}
}
if (addList != null && addList.Count > 0)
{
await TenantDb.Insertable(addList).ExecuteCommandAsync();
var _body = await TenantDb.Queryable<CM_RentOneWay_Detail>().Where(a => a.Pid == id).ToListAsync();
var ch = new CtnTotalHelper2<List<CM_RentOneWay_Detail>>(_body);
3 months ago
head.CntrnoAll = ch.GetCntrTotalStr();
head.Ctntotal = ch.GetCtnTotalStr();
head.DropoffCtntotal = ch.GetStr();
head.DropoffRemainCtntotal = ch.GetStr();
await TenantDb.Updateable(head).ExecuteCommandAsync();
return DataResult.Successed("添加成功!", id, MultiLanguageConst.DataCreateSuccess);
}
else
{
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
}
else
{
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
}
/// <summary>
/// 单程 待租出 明细_视图
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<DataResult<List<VW_CM_RentOneWay_NeedRentRes>>> CM_RentOneWay_NeedRent_View(PageRequest request)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
//if (request.PageCondition.SortConditions == null || request.PageCondition.SortConditions.Count() == 0)
//{
// request.PageCondition.SortConditions = new SortCondition[]{new SortCondition
// {
// SortField = nameof(VW_CM_RentOut_NeedRentRes.StateTime),
// ListSortDirection = System.ComponentModel.ListSortDirection.Descending
// } };
//}
request.SetDefaultOrderField("PickUpDate");
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = tenantDb.Queryable<VW_CM_RentOneWay_NeedRent>()
.Where(whereList)
.Select<VW_CM_RentOneWay_NeedRentRes>()
.ToQueryPage(request.PageCondition);
return data;
}
4 months ago
}