|
|
|
@ -21,8 +21,14 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class FeeAuditService : IFeeAuditService
|
|
|
|
|
{
|
|
|
|
|
//待审核的状态值
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 待审核的状态值
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly FeeStatus[] AuditStatusArray = [FeeStatus.AuditSubmitted, FeeStatus.ApplyDeletion, FeeStatus.ApplyModification];
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 工作流运行状态值
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly int RunningStatus = (int)FlowStatusEnum.Running;
|
|
|
|
|
|
|
|
|
|
readonly IServiceProvider _serviceProvider;
|
|
|
|
@ -54,10 +60,43 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
DataResult<List<FeeAuditBusiness>>.PageList(0, null, MultiLanguageConst.DataQuerySuccess);
|
|
|
|
|
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var queryList = GetDataQuery(tenantDb);
|
|
|
|
|
var bidList = flowList.Select(x => x.BusinessId);
|
|
|
|
|
queryList = queryList.Where(x => bidList.Contains(x.Id));
|
|
|
|
|
|
|
|
|
|
List<IConditionalModel> whereList = null;
|
|
|
|
|
if (!request.QueryCondition.IsNullOrEmpty())
|
|
|
|
|
whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
|
|
|
|
|
|
|
|
if (whereList != null)
|
|
|
|
|
queryList = queryList.Where(whereList);
|
|
|
|
|
|
|
|
|
|
var result = queryList.ToQueryPage(request.PageCondition);
|
|
|
|
|
|
|
|
|
|
if (result.Data.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
//关联用户名称
|
|
|
|
|
var userIds = result.Data.Where(x => x.OperatorId.HasValue).Select(x => x.OperatorId.Value)
|
|
|
|
|
.Union(result.Data.Select(x => x.CreateBy))
|
|
|
|
|
.Distinct();
|
|
|
|
|
var users = db.Queryable<SysUser>().Where(x => userIds.Contains(x.Id)).Select(x => new { x.Id, x.UserName }).ToList();
|
|
|
|
|
foreach (var item in result.Data)
|
|
|
|
|
{
|
|
|
|
|
item.CreateByName = users.Find(x => x.Id == item.CreateBy)?.UserName;
|
|
|
|
|
|
|
|
|
|
if (item.OperatorId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
item.Operator = users.Find(x => x.Id == item.OperatorId.Value)?.UserName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取各项业务数据的查询并集
|
|
|
|
|
internal static ISugarQueryable<FeeAuditBusiness> GetDataQuery(SqlSugarScopeProvider tenantDb)
|
|
|
|
|
{
|
|
|
|
|
//海运出口
|
|
|
|
|
var query1 = tenantDb.Queryable<SeaExport, BusinessFeeStatus, FeeRecord>((s, b, f) => new JoinQueryInfos(
|
|
|
|
|
JoinType.Left, s.Id == b.BusinessId && b.BusinessType == BusinessType.OceanShippingExport,
|
|
|
|
@ -121,35 +160,9 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
Yard = s.Yard
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var queryList = tenantDb.UnionAll(new List<ISugarQueryable<FeeAuditBusiness>> { query1 });
|
|
|
|
|
|
|
|
|
|
var bidList = flowList.Select(x => x.BusinessId);
|
|
|
|
|
queryList = queryList.Where(x => bidList.Contains(x.Id));
|
|
|
|
|
|
|
|
|
|
if (whereList != null)
|
|
|
|
|
queryList = queryList.Where(whereList);
|
|
|
|
|
|
|
|
|
|
var result = queryList.ToQueryPage(request.PageCondition);
|
|
|
|
|
|
|
|
|
|
if (result.Data.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
//关联用户名称
|
|
|
|
|
var userIds = result.Data.Where(x => x.OperatorId.HasValue).Select(x => x.OperatorId.Value)
|
|
|
|
|
.Union(result.Data.Select(x => x.CreateBy))
|
|
|
|
|
.Distinct();
|
|
|
|
|
var users = db.Queryable<SysUser>().Where(x => userIds.Contains(x.Id)).Select(x => new { x.Id, x.UserName }).ToList();
|
|
|
|
|
foreach (var item in result.Data)
|
|
|
|
|
{
|
|
|
|
|
item.CreateByName = users.Find(x => x.Id == item.CreateBy)?.UserName;
|
|
|
|
|
|
|
|
|
|
if (item.OperatorId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
item.Operator = users.Find(x => x.Id == item.OperatorId.Value)?.UserName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//海运进口
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
return tenantDb.UnionAll(new List<ISugarQueryable<FeeAuditBusiness>> { query1 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -180,15 +193,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
return DataResult.Failed("提交数据中包含不在待审批状态的费用");
|
|
|
|
|
|
|
|
|
|
var flowIds = fees.Select(x => x.FlowId.GetValueOrDefault());
|
|
|
|
|
var flows = db.Queryable<FlowInstance>().Where(x => flowIds.Contains(x.Id)).Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
x.ActivityId,
|
|
|
|
|
x.BusinessId,
|
|
|
|
|
x.BusinessType,
|
|
|
|
|
x.MakerList
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
var flows = db.Queryable<FlowInstance>().Where(x => flowIds.Contains(x.Id)).ToList();
|
|
|
|
|
if (flows.Count == 0)
|
|
|
|
|
return DataResult.Failed("未能获取审批工作流");
|
|
|
|
|
|
|
|
|
@ -204,10 +209,9 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = flowService.AuditFlowInstance(new FlowInstanceAuditReq
|
|
|
|
|
var result = flowService.AuditFlowInstance(new FlowAuditInfo
|
|
|
|
|
{
|
|
|
|
|
Id = flow.Id,
|
|
|
|
|
NodeId = flow.ActivityId,
|
|
|
|
|
Instance = flow,
|
|
|
|
|
Status = yesOrNo,
|
|
|
|
|
AuditNote = remark
|
|
|
|
|
});
|
|
|
|
@ -225,57 +229,101 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 整单审批
|
|
|
|
|
/// 本票审核(一键审核当前登录用户的所有待审核项)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="yesOrNo">审批结果:1=通过,2=驳回</param>
|
|
|
|
|
/// <param name="remark">备注</param>
|
|
|
|
|
/// <param name="id">业务ID</param>
|
|
|
|
|
/// <param name="businessType">业务类型</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult AuditBusiness(int yesOrNo, string remark, long id, BusinessType businessType)
|
|
|
|
|
public DataResult AuditBusiness(int yesOrNo, string remark)
|
|
|
|
|
{
|
|
|
|
|
var flowList = db.Queryable<FlowInstance>().Where(x => x.FlowStatus == RunningStatus && x.MakerList.Contains(user.UserId))
|
|
|
|
|
.Select(x => new { x.BusinessId, x.BusinessType }).ToList();
|
|
|
|
|
//没有待审批的列表直接返回不再执行后续查询
|
|
|
|
|
if (flowList.Count == 0)
|
|
|
|
|
return DataResult.Failed("当前暂无待审批的费用");
|
|
|
|
|
|
|
|
|
|
var request = new FeeBizAuditRequest
|
|
|
|
|
{
|
|
|
|
|
Items = flowList.Select(x => new BizAudit { Id = x.BusinessId, BusinessType = x.BusinessType }).ToList(),
|
|
|
|
|
Remark = remark,
|
|
|
|
|
Result = yesOrNo
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return AuditBusiness(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 整单审批
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">审批请求</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult AuditBusiness(FeeBizAuditRequest request)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var biz = tenantDb.Queryable<BusinessFeeStatus>().Where(x => x.BusinessId == id && x.BusinessType == businessType)
|
|
|
|
|
var gpList = request.Items.GroupBy(x => x.BusinessType).ToList();
|
|
|
|
|
foreach (var gp in gpList)
|
|
|
|
|
{
|
|
|
|
|
var bIdArr = gp.Select(x => x.Id).ToArray();
|
|
|
|
|
var bizList = tenantDb.Queryable<BusinessFeeStatus>().Where(x => bIdArr.Contains(x.BusinessId) && x.BusinessType == gp.Key)
|
|
|
|
|
.Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
x.BillAuditStatus,
|
|
|
|
|
x.FlowId
|
|
|
|
|
}).First();
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
if (biz == null)
|
|
|
|
|
return DataResult.Failed("未能获取业务信息");
|
|
|
|
|
if (bizList.Count == 0)
|
|
|
|
|
return DataResult.Failed("未能获取业务信息");
|
|
|
|
|
|
|
|
|
|
if (!biz.FlowId.HasValue)
|
|
|
|
|
return DataResult.Failed("业务未处于审批流程中");
|
|
|
|
|
if (!bizList.Any(x => x.FlowId.HasValue))
|
|
|
|
|
return DataResult.Failed("业务未处于审批流程中");
|
|
|
|
|
|
|
|
|
|
if (biz.BillAuditStatus != BillAuditStatus.AuditSubmitted)
|
|
|
|
|
return DataResult.Failed("业务的审批状态不正确");
|
|
|
|
|
if (bizList.Any(x => x.BillAuditStatus != BillAuditStatus.AuditSubmitted))
|
|
|
|
|
return DataResult.Failed("业务的审批状态不正确");
|
|
|
|
|
|
|
|
|
|
var flow = db.Queryable<FlowInstance>().Where(x => x.Id == biz.FlowId.Value).Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
x.ActivityId,
|
|
|
|
|
x.BusinessId,
|
|
|
|
|
x.BusinessType,
|
|
|
|
|
x.MakerList
|
|
|
|
|
}).First();
|
|
|
|
|
var fIdArr = bizList.Select(x => x.FlowId).ToArray();
|
|
|
|
|
var flows = db.Queryable<FlowInstance>().Where(x => fIdArr.Contains(x.Id)).ToList();
|
|
|
|
|
|
|
|
|
|
if (flow == null)
|
|
|
|
|
return DataResult.Failed("未能获取审批工作流");
|
|
|
|
|
if (flows.Count == 0)
|
|
|
|
|
return DataResult.Failed("未能获取审批工作流");
|
|
|
|
|
|
|
|
|
|
if (!flow.MakerList.Contains(user.UserId))
|
|
|
|
|
return DataResult.Failed("所选费用包含不属于当前用户权限范围内的审批,禁止提交");
|
|
|
|
|
if (flows.Any(x => !x.MakerList.Contains(user.UserId)))
|
|
|
|
|
return DataResult.Failed("所选项包含不属于当前用户权限范围内的审批,禁止提交");
|
|
|
|
|
|
|
|
|
|
var result = flowService.AuditFlowInstance(new FlowInstanceAuditReq
|
|
|
|
|
{
|
|
|
|
|
Id = flow.Id,
|
|
|
|
|
NodeId = flow.ActivityId,
|
|
|
|
|
Status = yesOrNo,
|
|
|
|
|
AuditNote = remark
|
|
|
|
|
});
|
|
|
|
|
foreach (var flow in flows)
|
|
|
|
|
{
|
|
|
|
|
var result = flowService.AuditFlowInstance(new FlowAuditInfo
|
|
|
|
|
{
|
|
|
|
|
Instance = flow,
|
|
|
|
|
Status = request.Result,
|
|
|
|
|
AuditNote = request.Remark
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
//todo:记录未能成功审核的数据
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置业务费用锁定状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="items">业务信息</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult SetFeeLocking(IEnumerable<BusinessFeeStatus> items)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
int rows = tenantDb.Updateable<BusinessFeeStatus>(items)
|
|
|
|
|
.WhereColumns(x => new { x.BusinessId, x.BusinessType })
|
|
|
|
|
.UpdateColumns(x => new { x.IsFeeLocking })
|
|
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
return rows > 0 ? DataResult.Success : DataResult.Failed("更新失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -288,17 +336,17 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
var auditType = callback.AuditType.ToEnum<FeeAuditType>();
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
FeeRecord fee = null;
|
|
|
|
|
BusinessFeeStatus businessFee = null;
|
|
|
|
|
BusinessFeeStatus biz = null;
|
|
|
|
|
if (auditType == FeeAuditType.Business)
|
|
|
|
|
{
|
|
|
|
|
businessFee = tenantDb.Queryable<BusinessFeeStatus>().Where(x => x.Id == callback.BusinessId && x.BusinessType == callback.BusinessType)
|
|
|
|
|
biz = tenantDb.Queryable<BusinessFeeStatus>().Where(x => x.Id == callback.BusinessId && x.BusinessType == callback.BusinessType)
|
|
|
|
|
.Select(x => new BusinessFeeStatus
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
BusinessId = x.BusinessId,
|
|
|
|
|
BillAuditStatus = x.BillAuditStatus
|
|
|
|
|
}).First();
|
|
|
|
|
if (businessFee == null)
|
|
|
|
|
if (biz == null)
|
|
|
|
|
return DataResult.Failed("未能找到业务信息,更新状态失败", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -419,28 +467,28 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
FeeStatus status = FeeStatus.RejectSubmission;
|
|
|
|
|
if (callback.FlowStatus == FlowStatusEnum.Approve)
|
|
|
|
|
{
|
|
|
|
|
businessFee.BillAuditStatus = BillAuditStatus.AuditPassed;
|
|
|
|
|
biz.BillAuditStatus = BillAuditStatus.AuditPassed;
|
|
|
|
|
status = FeeStatus.AuditPassed;
|
|
|
|
|
}
|
|
|
|
|
else if (callback.FlowStatus == FlowStatusEnum.Reject)
|
|
|
|
|
{
|
|
|
|
|
businessFee.BillAuditStatus = BillAuditStatus.Rejected;
|
|
|
|
|
biz.BillAuditStatus = BillAuditStatus.Rejected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tenantDb.Updateable(businessFee).UpdateColumns(x => new
|
|
|
|
|
tenantDb.Updateable(biz).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.BillAuditStatus,
|
|
|
|
|
x.FlowId
|
|
|
|
|
}).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tenantDb.Updateable<FeeRecord>()
|
|
|
|
|
.SetColumns(x => x.FeeStatus == status)
|
|
|
|
|
.SetColumns(x => x.FlowId == null)
|
|
|
|
|
.SetColumns(x => x.AuditBy == userId)
|
|
|
|
|
.SetColumns(x => x.AuditOperator == user.UserName)
|
|
|
|
|
.SetColumns(x => x.AuditDate == dtNow)
|
|
|
|
|
.Where(x => x.BusinessId == businessFee.BusinessId && x.BusinessType == callback.BusinessType &&
|
|
|
|
|
.Where(x => x.BusinessId == biz.BusinessId && x.BusinessType == callback.BusinessType &&
|
|
|
|
|
(x.FeeStatus == FeeStatus.Entering || x.FeeStatus == FeeStatus.RejectSubmission)).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
@ -455,7 +503,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
{
|
|
|
|
|
Id = callback.InstanceId,
|
|
|
|
|
Deleted = true,
|
|
|
|
|
DeleteBy = long.Parse(user.UserId),
|
|
|
|
|
DeleteBy = 0,
|
|
|
|
|
DeleteTime = DateTime.Now
|
|
|
|
|
}).UpdateColumns(x => new { x.Deleted, x.DeleteBy, x.DeleteTime }).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|