@ -8,7 +8,9 @@ using DS.WMS.Core.Flow.Dtos;
using DS.WMS.Core.Flow.Entity ;
using DS.WMS.Core.Flow.Interface ;
using DS.WMS.Core.Info.Entity ;
using DS.WMS.Core.Op.Dtos.TaskInteraction ;
using DS.WMS.Core.Op.Entity ;
using DS.WMS.Core.Op.Interface.TaskInteraction ;
using DS.WMS.Core.Sys.Entity ;
using Mapster ;
using Masuit.Tools.Systems ;
@ -23,6 +25,7 @@ namespace DS.WMS.Core.Fee.Method
public class FeeRecordService : FeeServiceBase , IFeeRecordService
{
readonly IClientFlowInstanceService flowService ;
readonly ITaskService taskService ;
/// <summary>
/// 初始化
@ -31,6 +34,7 @@ namespace DS.WMS.Core.Fee.Method
public FeeRecordService ( IServiceProvider serviceProvider ) : base ( serviceProvider )
{
flowService = serviceProvider . GetRequiredService < IClientFlowInstanceService > ( ) ;
taskService = serviceProvider . GetRequiredService < ITaskService > ( ) ;
}
/// <summary>
@ -136,11 +140,11 @@ namespace DS.WMS.Core.Fee.Method
ArgumentNullException . ThrowIfNull ( items , nameof ( items ) ) ;
if ( items . GroupBy ( x = > new { x . BusinessId , x . BusinessType } ) . Count ( ) > 1 )
return DataResult . Failed ( MultiLanguageConst . FeeBusinessIdOnlyOne ) ;
return DataResult . Failed WithDesc( nameof ( MultiLanguageConst . FeeBusinessIdOnlyOne ) ) ;
var first = items . Select ( x = > new { x . BusinessType , x . BusinessId } ) . FirstOrDefault ( ) ;
if ( await IsFeeLockedAsync ( first . BusinessId , first . BusinessType ) )
return DataResult . Failed ( MultiLanguageConst . FeeLocked ) ;
return DataResult . Failed WithDesc( nameof ( MultiLanguageConst . FeeLocked ) ) ;
var order = await TenantDb . Queryable < SeaExport > ( ) . Where ( x = > x . Id = = first . BusinessId ) . Select ( x = > new
{
@ -150,7 +154,7 @@ namespace DS.WMS.Core.Fee.Method
x . CBM //尺码
} ) . FirstAsync ( ) ;
if ( order = = null )
return DataResult . Failed ( MultiLanguageConst . EmptyData ) ;
return DataResult . Failed WithDesc( nameof ( MultiLanguageConst . EmptyData ) ) ;
//获取订单箱型箱量
string bsNo = first . BusinessId . ToString ( ) ;
@ -406,7 +410,6 @@ namespace DS.WMS.Core.Fee.Method
Id = x . Id ,
FeeName = x . FeeName ,
FeeStatus = x . FeeStatus ,
FlowId = x . FlowId ,
BusinessId = x . BusinessId ,
BusinessType = x . BusinessType
} ) . ToListAsync ( ) ;
@ -419,13 +422,13 @@ namespace DS.WMS.Core.Fee.Method
if ( await IsFeeLockedAsync ( bid , bType ) )
return DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . FeeLocked ) ) ;
if ( fees . Any ( x = > x . FlowId . HasValue ) )
if ( await flowService . IsRunning ( auditType , null , idArray ) )
return DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . FeeRecordIsAuditing ) ) ;
if ( fees . Any ( x = > x . FeeStatus = = FeeStatus . PartialSettlement | | x . FeeStatus = = FeeStatus . SettlementCompleted ) )
return DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . FeeRecordIsSettled ) ) ;
DataResult result = DataResult . FailedWithDesc( nameof ( MultiLanguageConst . Operation_Failed ) ) ;
DataResult result = DataResult . Success ;
await TenantDb . Ado . BeginTranAsync ( ) ;
try
{
@ -439,18 +442,14 @@ namespace DS.WMS.Core.Fee.Method
}
if ( ! result . Succeeded )
{
await TenantDb . Ado . RollbackTranAsync ( ) ;
return result ;
}
await TenantDb . Updateable ( fees ) . UpdateColumns ( x = > new
{
x . Id ,
x . FeeStatus ,
x . SubmitBy ,
x . SubmitDate ,
x . FlowId
x . SubmitDate
} ) . ExecuteCommandAsync ( ) ;
await TenantDb . Ado . CommitTranAsync ( ) ;
return DataResult . Success ;
@ -478,14 +477,40 @@ namespace DS.WMS.Core.Fee.Method
if ( sb . Length > 0 )
return DataResult . Failed ( sb . ToString ( ) , MultiLanguageConst . Operation_Failed ) ;
DataResult result ;
DateTime dtNow = DateTime . Now ;
if ( await taskService . HasAuthorizedAsync ( ) )
{
var requests = fees . Select ( x = > new TaskCreationRequest
{
BusinessId = x . Id ,
TaskTypeName = TaskBaseTypeEnum . FEE_AUDIT . ToString ( ) ,
TaskTitle = $"【{TaskBaseTypeEnum.FEE_AUDIT.GetDescription()}】{x.FeeName}"
} ) ;
foreach ( var request in requests )
{
result = await taskService . CreateTaskAsync ( request , false ) ;
if ( ! result . Succeeded )
return result ;
var fee = fees . Find ( x = > x . Id = = request . BusinessId ) ;
//变更状态为提交审核
fee . FeeStatus = FeeStatus . AuditSubmitted ;
fee . SubmitBy = long . Parse ( User . UserId ) ;
fee . SubmitDate = dtNow ;
}
return DataResult . Success ;
}
var template = await FindTemplateAsync ( TaskBaseTypeEnum . FEE_AUDIT ) ;
if ( template = = null )
return DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . TemplateNotFound ) ) ;
DateTime dtNow = DateTime . Now ;
foreach ( var item in fees )
{
var result = flowService . CreateFlowInstance ( new CreateFlowInstanceReq
result = flowService . CreateFlowInstance ( new CreateFlowInstanceReq
{
BusinessId = item . Id ,
BusinessType = item . BusinessType ,
@ -500,7 +525,6 @@ namespace DS.WMS.Core.Fee.Method
item . FeeStatus = FeeStatus . AuditSubmitted ;
item . SubmitBy = long . Parse ( User . UserId ) ;
item . SubmitDate = dtNow ;
item . FlowId = instance . Id ;
}
}
@ -522,14 +546,41 @@ namespace DS.WMS.Core.Fee.Method
if ( sb . Length > 0 )
return DataResult . Failed ( sb . ToString ( ) , MultiLanguageConst . Operation_Failed ) ;
DataResult result ;
DateTime dtNow = DateTime . Now ;
if ( await taskService . HasAuthorizedAsync ( ) )
{
var requests = fees . Select ( x = > new TaskCreationRequest
{
BusinessId = x . Id ,
TaskTypeName = TaskBaseTypeEnum . FEE_AUDIT . ToString ( ) ,
TaskTitle = $"【{TaskBaseTypeEnum.FEE_AUDIT.GetDescription()}】{x.FeeName}"
} ) ;
foreach ( var request in requests )
{
result = await taskService . CreateTaskAsync ( request , false ) ;
if ( ! result . Succeeded )
return result ;
var fee = fees . Find ( x = > x . Id = = request . BusinessId ) ;
//变更状态为申请删除
fee . FeeStatus = FeeStatus . ApplyDeletion ;
fee . SubmitBy = long . Parse ( User . UserId ) ;
fee . SubmitDate = dtNow ;
fee . Reason = reason ;
}
return DataResult . Success ;
}
var template = await FindTemplateAsync ( TaskBaseTypeEnum . FEE_DELETE_AUDIT ) ;
if ( template = = null )
return DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . TemplateNotFound ) ) ;
DateTime dtNow = DateTime . Now ;
foreach ( var item in fees )
{
var result = flowService . CreateFlowInstance ( new CreateFlowInstanceReq
result = flowService . CreateFlowInstance ( new CreateFlowInstanceReq
{
BusinessId = item . Id ,
BusinessType = item . BusinessType ,
@ -544,7 +595,6 @@ namespace DS.WMS.Core.Fee.Method
item . FeeStatus = FeeStatus . ApplyDeletion ;
item . SubmitBy = long . Parse ( User . UserId ) ;
item . SubmitDate = dtNow ;
item . FlowId = instance . Id ;
item . Reason = reason ;
}
}
@ -581,39 +631,61 @@ namespace DS.WMS.Core.Fee.Method
if ( sb . Length > 0 )
return DataResult . Failed ( sb . ToString ( ) , MultiLanguageConst . Operation_Failed ) ;
var template = await FindTemplateAsync ( TaskBaseTypeEnum . FEE_MODIFY_AUDIT ) ;
if ( template = = null )
return DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . TemplateNotFound ) ) ;
DataResult result ;
DateTime dtNow = DateTime . Now ;
await TenantDb . Ado . BeginTranAsync ( ) ;
try
{
foreach ( var fee in fees )
if ( await taskService . HasAuthorizedAsync ( ) )
{
var re sult = flowService . CreateFlowInstance ( new CreateFlowInstanceReq
var re quests = fees . Select ( x = > new TaskCreationRequest
{
BusinessId = fee . Id ,
BusinessType = fee . BusinessType ,
T emplateId = template . Id
BusinessId = x . Id ,
TaskTypeName = TaskBaseTypeEnum . FEE_AUDIT . ToString ( ) ,
T askTitle = $"【{TaskBaseTypeEnum.FEE_AUDIT.GetDescription()}】{x.FeeName}"
} ) ;
if ( result . Succeeded )
foreach ( var request in requests )
{
var instance = result . Data as FlowInstance ;
flowService . StartFlowInstance ( instance . Id . ToString ( ) ) ;
result = await taskService . CreateTaskAsync ( request , false ) ;
if ( ! result . Succeeded )
return result ;
var fee = fees . Find ( x = > x . Id = = request . BusinessId ) ;
//变更状态为申请修改
fee . FeeStatus = FeeStatus . ApplyModification ;
//fee.SubmitBy = long.Parse(User.UserId);
//fee.SubmitDate = dtNow;
fee . FlowId = instance . Id ;
fee . Reason = items . FirstOrDefault ( x = > x . FeeRecordId = = fee . Id ) ? . Reason ;
}
}
else
{
var template = await FindTemplateAsync ( TaskBaseTypeEnum . FEE_MODIFY_AUDIT ) ;
if ( template = = null )
return DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . TemplateNotFound ) ) ;
foreach ( var fee in fees )
{
result = flowService . CreateFlowInstance ( new CreateFlowInstanceReq
{
BusinessId = fee . Id ,
BusinessType = fee . BusinessType ,
TemplateId = template . Id
} ) ;
if ( result . Succeeded )
{
var instance = result . Data as FlowInstance ;
flowService . StartFlowInstance ( instance . Id . ToString ( ) ) ;
//变更状态为申请修改
fee . FeeStatus = FeeStatus . ApplyModification ;
fee . Reason = items . FirstOrDefault ( x = > x . FeeRecordId = = fee . Id ) ? . Reason ;
}
}
}
var list = items . ToList ( ) ;
await TenantDb . Insertable ( list ) . ExecuteCommandAsync ( ) ;
await TenantDb . Updateable ( fees ) . UpdateColumns ( x = > new { x . FeeStatus , x . FlowId } ) . ExecuteCommandAsync ( ) ;
await TenantDb . Updateable ( fees ) . UpdateColumns ( x = > new { x . FeeStatus } ) . ExecuteCommandAsync ( ) ;
await TenantDb . Ado . CommitTranAsync ( ) ;
return DataResult . Success ;
@ -638,58 +710,76 @@ namespace DS.WMS.Core.Fee.Method
{
Id = x . Id ,
FeeName = x . FeeName ,
FeeStatus = x . FeeStatus ,
FlowId = x . FlowId
FeeStatus = x . FeeStatus
} ) . ToListAsync ( ) ;
if ( fees . Count = = 0 )
return DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . TemplateNotFound ) ) ;
//未在审批状态中
var fees2 = fees . FindAll ( x = > x . FlowId = = null ) . ToList ( ) ;
if ( fees2 . Count > 0 )
{
string msg = string . Join ( "; " , fees2 . Select ( x = > $"{x.FeeName}" ) ) ;
return DataResult . Failed ( string . Format ( MultiLanguageConst . NoNeedWithdraw , msg ) ) ;
}
var flows = fees . Select ( x = > new FlowInstance { Id = x . FlowId . Value , FlowStatus = FlowStatusEnum . Draft , MakerList = string . Empty } ) . ToList ( ) ;
DataResult result ;
List < Tuple < TaskBaseTypeEnum , long > > taskTypes = [ ] ;
DateTime dtNow = DateTime . Now ;
await TenantDb . Ado . BeginTranAsync ( ) ;
try
{
await Db . Updateable ( flows ) . UpdateColumns ( x = > new { x . FlowStatus , x . MakerList } ) . ExecuteCommandAsync ( ) ;
foreach ( var item in fees )
{
switch ( item . FeeStatus )
{
case FeeStatus . AuditSubmitted :
item . FeeStatus = FeeStatus . Entering ;
taskTypes . Add ( new Tuple < TaskBaseTypeEnum , long > ( TaskBaseTypeEnum . FEE_AUDIT , item . Id ) ) ;
break ;
case FeeStatus . ApplyModification :
item . FeeStatus = FeeStatus . AuditPassed ;
taskTypes . Add ( new Tuple < TaskBaseTypeEnum , long > ( TaskBaseTypeEnum . FEE_MODIFY_AUDIT , item . Id ) ) ;
//删除暂存数据
var entity = await TenantDb . Queryable < FeeModification > ( ) . OrderByDescending (
x = > x . CreateTime ) . Select ( x = > new { x . Id , x . FeeRecordId } ) . FirstAsync ( x = > x . FeeRecordId = = item . Id ) ;
if ( entity ! = null )
{
await TenantDb . Deleteable < FeeModification > ( ) . Where ( x = > x . Id = = entity . Id ) . ExecuteCommandAsync ( ) ;
}
break ;
case FeeStatus . ApplyDeletion :
item . FeeStatus = FeeStatus . AuditPassed ;
taskTypes . Add ( new Tuple < TaskBaseTypeEnum , long > ( TaskBaseTypeEnum . FEE_DELETE_AUDIT , item . Id ) ) ;
break ;
}
item . SubmitBy = long . Parse ( User . UserId ) ;
item . SubmitDate = dtNow ;
item . FlowId = null ;
item . SubmitBy = null ;
item . SubmitDate = null ;
}
await TenantDb . Updateable ( fees ) . UpdateColumns ( x = > new { x . Id , x . FeeStatus , x . SubmitBy , x . SubmitDate , x . FlowId } ) . ExecuteCommandAsync ( ) ;
var groups = taskTypes . GroupBy ( x = > x . Item1 ) ;
if ( await taskService . HasAuthorizedAsync ( ) )
{
foreach ( var group in groups )
{
foreach ( var item in group )
{
await taskService . WithdrawAsync ( new TaskRequest
{
BusinessId = item . Item2 ,
TaskTypeName = item . Item1 . ToString ( )
} , false ) ;
}
}
}
else
{
//未在审批状态中
if ( ! await flowService . Exists ( ids : idArray ) )
return DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . NotInAudit ) ) ;
foreach ( var g in groups )
{
result = await flowService . WithdrawAsync ( g . Key , g . Select ( x = > x . Item2 ) . ToArray ( ) ) ;
if ( ! result . Succeeded )
return result ;
}
}
await TenantDb . Updateable ( fees ) . UpdateColumns ( x = > new { x . FeeStatus , x . SubmitBy , x . SubmitDate } ) . ExecuteCommandAsync ( ) ;
await TenantDb . Ado . CommitTranAsync ( ) ;
return DataResult . Success ;
}
@ -710,6 +800,8 @@ namespace DS.WMS.Core.Fee.Method
/// <returns></returns>
public async Task < DataResult > SubmitBusinessAuditAsync ( long bid , BusinessType type )
{
var taskType = TaskBaseTypeEnum . FEE_BUSINESS_AUDIT ;
var entity = await TenantDb . Queryable < BusinessFeeStatus > ( ) . Where ( x = > x . BusinessId = = bid & &
x . BusinessType = = BusinessType . OceanShippingExport ) . Select ( x = > new BusinessFeeStatus
{
@ -717,54 +809,75 @@ namespace DS.WMS.Core.Fee.Method
BusinessId = x . BusinessId ,
BusinessType = x . BusinessType ,
IsFeeLocking = x . IsFeeLocking ,
BillAuditStatus = x . BillAuditStatus ,
FlowId = x . FlowId
BillAuditStatus = x . BillAuditStatus
} ) . FirstAsync ( ) ;
if ( entity = = null )
return DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . BusinessNotFound ) ) ;
if ( entity . IsFeeLocking . GetValueOrDefault ( ) )
return DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . FeeLocked ) ) ;
if ( entity . FlowId . HasValue )
return DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . FeeRecordIsAuditing ) ) ;
if ( entity . BillAuditStatus = = BillAuditStatus . AuditPassed )
return DataResult . Failed ( string . Format ( MultiLanguageConst . BusinessStatusError , entity . BillAuditStatus . GetDescription ( ) ) ) ;
var template = await FindTemplateAsync ( TaskBaseTypeEnum . FEE_BUSINESS_AUDIT ) ;
if ( template = = null )
return DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . TemplateNotFound ) ) ;
if ( await flowService . IsRunning ( taskType , type , bid ) )
return DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . FeeRecordIsAuditing ) ) ;
var result = flowService . CreateFlowInstance ( new CreateFlowInstanceReq
{
BusinessId = entity . Id ,
BusinessType = entity . BusinessType ,
TemplateId = template . Id
} ) ;
if ( result . Succeeded )
DataResult result ;
await TenantDb . Ado . BeginTranAsync ( ) ;
try
{
var instance = result . Data as FlowInstance ;
flowService . StartFlowInstance ( instance . Id . ToString ( ) ) ;
if ( await taskService . HasAuthorizedAsync ( ) )
{
result = await taskService . SubmitAuditAsync ( new TaskRequest
{
BusinessId = bid ,
BusinessType = type ,
TaskTypeName = taskType . ToString ( )
} , false ) ;
}
else
{
var template = await FindTemplateAsync ( taskType ) ;
if ( template = = null )
return DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . TemplateNotFound ) ) ;
result = flowService . CreateFlowInstance ( new CreateFlowInstanceReq
{
BusinessId = entity . Id ,
BusinessType = entity . BusinessType ,
TemplateId = template . Id
} ) ;
//var instance = result.Data as FlowInstance;
//flowService.StartFlowInstance(instance.Id.ToString());
}
if ( ! result . Succeeded )
return result ;
//变更状态为提交审核
entity . BillAuditStatus = BillAuditStatus . AuditSubmitted ;
entity . BillFeeStatusTime = DateTime . Now ;
entity . FlowId = instance . Id ;
await TenantDb . Updateable ( entity ) . UpdateColumns ( x = > new
{
x . BillAuditStatus ,
x . BillFeeStatusTime ,
x . FlowId
x . BillFeeStatusTime
} ) . ExecuteCommandAsync ( ) ;
//修改关联费用状态为提交审核
await TenantDb . Updateable < FeeRecord > ( ) . Where ( x = > x . BusinessId = = entity . BusinessId & & x . BusinessType = = entity . BusinessType )
. SetColumns ( x = > x . FeeStatus , FeeStatus . AuditSubmitted ) . ExecuteCommandAsync ( ) ;
await TenantDb . Ado . CommitTranAsync ( ) ;
return DataResult . Success ;
}
return DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . Operation_Failed ) ) ;
catch ( Exception ex )
{
await TenantDb . Ado . RollbackTranAsync ( ) ;
await ex . LogAsync ( Db ) ;
return DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . Operation_Failed ) ) ;
}
}
/// <summary>