|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
using DS.WMS.Core.Code.Entity;
|
|
|
|
|
using DS.WMS.Core.Fee.Dtos;
|
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
|
using DS.WMS.Core.Fee.Interface;
|
|
|
|
|
using DS.WMS.Core.Flow.Dtos;
|
|
|
|
|
using DS.WMS.Core.Flow.Entity;
|
|
|
|
|
using DS.WMS.Core.Flow.Interface;
|
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 费用审核
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class FeeAuditService : FeeServiceBase, IFeeAuditService
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 待审核的状态值
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly FeeStatus[] AuditStatusArray = [FeeStatus.AuditSubmitted, FeeStatus.ApplyDeletion, FeeStatus.ApplyModification];
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 一键审核支持的类型
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly string[] AuditTypes = [AuditType.FeeAudit.ToString(), AuditType.FeeModify.ToString(), AuditType.FeeDelete.ToString()];
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 工作流运行状态值
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly int RunningStatus = (int)FlowStatusEnum.Running;
|
|
|
|
|
|
|
|
|
|
readonly IClientFlowInstanceService flowService;
|
|
|
|
|
readonly IFeeRecordService feeService;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="serviceProvider"></param>
|
|
|
|
|
public FeeAuditService(IServiceProvider serviceProvider) : base(serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
flowService = serviceProvider.GetRequiredService<IClientFlowInstanceService>();
|
|
|
|
|
feeService = serviceProvider.GetRequiredService<IFeeRecordService>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取费用审核列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<List<FeeAuditBusiness>>> GetListAsync(PageRequest request)
|
|
|
|
|
{
|
|
|
|
|
var flowList = await Db.Queryable<FlowInstance>().Where(x => x.FlowStatus == RunningStatus
|
|
|
|
|
&& SqlFunc.SplitIn(x.MakerList, User.UserId) && AuditTypes.Contains(x.AuditType))
|
|
|
|
|
.Select(x => new FlowInstance { BusinessId = x.BusinessId, BusinessType = x.BusinessType }).ToListAsync();
|
|
|
|
|
//没有待审批的列表直接返回不再执行后续查询
|
|
|
|
|
if (flowList.Count == 0)
|
|
|
|
|
DataResult<List<FeeAuditBusiness>>.PageList(0, null, MultiLanguageConst.DataQuerySuccess);
|
|
|
|
|
|
|
|
|
|
var queryList = CreateQuery(flowList);
|
|
|
|
|
//queryList = queryList.Where(x => SqlFunc.Subqueryable<FlowInstance>().Where(
|
|
|
|
|
// y => y.BusinessId == x.Id && y.BusinessType == x.BusinessType && SqlFunc.SplitIn(y.MakerList, User.UserId)).Any());
|
|
|
|
|
|
|
|
|
|
if (!request.QueryCondition.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
var whereList = Db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
|
|
|
queryList = queryList.Where(whereList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = await queryList.ToQueryPageAsync(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 = await Db.Queryable<SysUser>().Where(x => userIds.Contains(x.Id)).Select(x => new { x.Id, x.UserName }).ToListAsync();
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取整票审核列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<List<FeeAuditBusiness>>> GetBizListAsync(PageRequest request)
|
|
|
|
|
{
|
|
|
|
|
string auditType = AuditType.FeeBusiness.ToString();
|
|
|
|
|
var flowList = await Db.Queryable<FlowInstance>().Where(x => x.FlowStatus == RunningStatus
|
|
|
|
|
&& SqlFunc.SplitIn(x.MakerList, User.UserId) && x.AuditType == auditType)
|
|
|
|
|
.Select(x => new FlowInstance { BusinessId = x.BusinessId, BusinessType = x.BusinessType }).ToListAsync();
|
|
|
|
|
//没有待审批的列表直接返回不再执行后续查询
|
|
|
|
|
if (flowList.Count == 0)
|
|
|
|
|
DataResult<List<FeeAuditBusiness>>.PageList(0, null, MultiLanguageConst.DataQuerySuccess);
|
|
|
|
|
|
|
|
|
|
var queryList = CreateBizQuery(flowList);
|
|
|
|
|
|
|
|
|
|
if (!request.QueryCondition.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
var whereList = Db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
|
|
|
queryList = queryList.Where(whereList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = await queryList.ToQueryPageAsync(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 = await Db.Queryable<SysUser>().Where(x => UserIds.Contains(x.Id)).Select(x => new { x.Id, x.UserName }).ToListAsync();
|
|
|
|
|
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 ISugarQueryable<FeeAuditBusiness> CreateQuery(IEnumerable<FlowInstance> additions)
|
|
|
|
|
{
|
|
|
|
|
//海运出口
|
|
|
|
|
var ids1 = additions?.Where(x => x.BusinessType == BusinessType.OceanShippingExport).Select(x => x.BusinessId).ToArray();
|
|
|
|
|
var query1 = TenantDb.Queryable<SeaExport, BusinessFeeStatus, FeeRecord, CodeSource, CodeSourceDetail>((s, b, f, cs, csd) => new JoinQueryInfos(
|
|
|
|
|
JoinType.Left, s.Id == b.BusinessId && b.BusinessType == BusinessType.OceanShippingExport,
|
|
|
|
|
JoinType.Inner, s.Id == f.BusinessId && f.BusinessType == BusinessType.OceanShippingExport && AuditStatusArray.Contains(f.FeeStatus),
|
|
|
|
|
JoinType.Left, s.SourceId == cs.Id,
|
|
|
|
|
JoinType.Left, s.SourceDetailId == csd.Id
|
|
|
|
|
))
|
|
|
|
|
.WhereIF(ids1 != null && ids1.Length > 0, (s, b, f) => ids1.Contains(f.Id))
|
|
|
|
|
.GroupBy(s => s.Id)
|
|
|
|
|
.Select((s, b, f, cs, csd) => new FeeAuditBusiness
|
|
|
|
|
{
|
|
|
|
|
Id = s.Id,
|
|
|
|
|
AccountDate = s.AccountDate,
|
|
|
|
|
APFeeStatus = b.APFeeStatus,
|
|
|
|
|
ARFeeStatus = b.ARFeeStatus,
|
|
|
|
|
BusinessType = BusinessType.OceanShippingExport,
|
|
|
|
|
BusinessStatus = s.BusinessStatusName,
|
|
|
|
|
BusinessDate = s.BusinessDate,//业务日期
|
|
|
|
|
BLType = s.BLType,
|
|
|
|
|
CargoId = s.CargoId,
|
|
|
|
|
Carrier = s.Carrier,
|
|
|
|
|
AgencyId = s.AgentId,
|
|
|
|
|
CBM = s.CBM,
|
|
|
|
|
CntrTotal = s.CntrTotal,
|
|
|
|
|
ContractNo = s.ContractNo,
|
|
|
|
|
CreateBy = s.CreateBy,
|
|
|
|
|
CustomerId = s.CustomerId,
|
|
|
|
|
CustomerName = s.CustomerName,//委托单位
|
|
|
|
|
CustomerNo = s.CustomerNo,
|
|
|
|
|
CustomerService = s.CustomerService,
|
|
|
|
|
CustomNo = s.CustomNo,
|
|
|
|
|
CustomsNum = s.CustomsNum,
|
|
|
|
|
DangerClass = s.DangerClass,
|
|
|
|
|
Destination = s.Destination,
|
|
|
|
|
DischargePort = s.DischargePort,
|
|
|
|
|
Doc = s.Doc,
|
|
|
|
|
ETD = s.ETD,
|
|
|
|
|
Forwarder = s.Forwarder,
|
|
|
|
|
GoodsName = s.GoodsName,
|
|
|
|
|
HBLNO = s.HBLNO,
|
|
|
|
|
InvoiceNo = s.InvoiceNo,
|
|
|
|
|
IsBusinessLocking = b.IsBusinessLocking,
|
|
|
|
|
IsFeeLocking = b.IsFeeLocking,
|
|
|
|
|
IssueType = s.IssueType,
|
|
|
|
|
KGS = s.KGS,
|
|
|
|
|
LoadPort = s.LoadPort,
|
|
|
|
|
MBLFrt = s.MBLFrt,
|
|
|
|
|
MBLNO = s.MBLNO,
|
|
|
|
|
Note = s.Note,
|
|
|
|
|
OperatorId = s.OperatorId,
|
|
|
|
|
OrderNo = s.OrderNo,
|
|
|
|
|
PKGS = s.PKGS,
|
|
|
|
|
ReceiptPlace = s.ReceiptPlace,
|
|
|
|
|
Remark = s.Remark,
|
|
|
|
|
SaleDeptId = s.SaleDeptId,
|
|
|
|
|
//SaleDeptName //所属部门
|
|
|
|
|
SaleId = s.SaleId,
|
|
|
|
|
SaleName = s.Sale,//揽货人
|
|
|
|
|
SourceId = s.SourceId,
|
|
|
|
|
SourceName = cs.SourceName,
|
|
|
|
|
SourceDetailId = s.SourceDetailId,
|
|
|
|
|
DetailName = csd.DetailName,
|
|
|
|
|
TradeTerm = s.TradeTerm,
|
|
|
|
|
TransitTerms = s.Service,//运输条款
|
|
|
|
|
Vessel = s.Vessel,//船名
|
|
|
|
|
Voyage = s.Voyno,//航次
|
|
|
|
|
Yard = s.Yard
|
|
|
|
|
//BusinessUnit = //经营单位
|
|
|
|
|
//ChangeOrder //更改单
|
|
|
|
|
//ChangeReason //更改单更改原因
|
|
|
|
|
//FreightRatio //运杂费比例
|
|
|
|
|
//查询:运输类型 (枚举值,暂未建立)
|
|
|
|
|
//查询:是否费用提交
|
|
|
|
|
//查询:利润减少
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//海运进口
|
|
|
|
|
//var ids2 = additions?.Where(x => x.BusinessType == BusinessType.OceanShippingImport).Select(x => x.BusinessId).ToArray();
|
|
|
|
|
|
|
|
|
|
return TenantDb.UnionAll(new List<ISugarQueryable<FeeAuditBusiness>> { query1 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//创建各项业务数据的查询并集
|
|
|
|
|
internal ISugarQueryable<FeeAuditBusiness> CreateBizQuery(IEnumerable<FlowInstance> additions)
|
|
|
|
|
{
|
|
|
|
|
//海运出口
|
|
|
|
|
var ids1 = additions?.Where(x => x.BusinessType == BusinessType.OceanShippingExport).Select(x => x.BusinessId).ToArray();
|
|
|
|
|
var query1 = TenantDb.Queryable<SeaExport, BusinessFeeStatus, CodeSource, CodeSourceDetail>((s, b, cs, csd) => new JoinQueryInfos(
|
|
|
|
|
JoinType.Left, s.Id == b.BusinessId && b.BusinessType == BusinessType.OceanShippingExport,
|
|
|
|
|
JoinType.Left, s.SourceId == cs.Id,
|
|
|
|
|
JoinType.Left, s.SourceDetailId == csd.Id
|
|
|
|
|
))
|
|
|
|
|
.WhereIF(ids1 != null && ids1.Length > 0, (s, b) => ids1.Contains(s.Id))
|
|
|
|
|
.GroupBy(s => s.Id)
|
|
|
|
|
.Select((s, b, cs, csd) => new FeeAuditBusiness
|
|
|
|
|
{
|
|
|
|
|
Id = s.Id,
|
|
|
|
|
AccountDate = s.AccountDate,
|
|
|
|
|
APFeeStatus = b.APFeeStatus,
|
|
|
|
|
ARFeeStatus = b.ARFeeStatus,
|
|
|
|
|
BusinessType = BusinessType.OceanShippingExport,
|
|
|
|
|
BusinessStatus = s.BusinessStatusName,
|
|
|
|
|
BusinessDate = s.BusinessDate,//业务日期
|
|
|
|
|
BLType = s.BLType,
|
|
|
|
|
CargoId = s.CargoId,
|
|
|
|
|
Carrier = s.Carrier,
|
|
|
|
|
AgencyId = s.AgentId,
|
|
|
|
|
CBM = s.CBM,
|
|
|
|
|
CntrTotal = s.CntrTotal,
|
|
|
|
|
ContractNo = s.ContractNo,
|
|
|
|
|
CreateBy = s.CreateBy,
|
|
|
|
|
CustomerId = s.CustomerId,
|
|
|
|
|
CustomerName = s.CustomerName,//委托单位
|
|
|
|
|
CustomerNo = s.CustomerNo,
|
|
|
|
|
CustomerService = s.CustomerService,
|
|
|
|
|
CustomNo = s.CustomNo,
|
|
|
|
|
CustomsNum = s.CustomsNum,
|
|
|
|
|
DangerClass = s.DangerClass,
|
|
|
|
|
Destination = s.Destination,
|
|
|
|
|
DischargePort = s.DischargePort,
|
|
|
|
|
Doc = s.Doc,
|
|
|
|
|
ETD = s.ETD,
|
|
|
|
|
Forwarder = s.Forwarder,
|
|
|
|
|
GoodsName = s.GoodsName,
|
|
|
|
|
HBLNO = s.HBLNO,
|
|
|
|
|
InvoiceNo = s.InvoiceNo,
|
|
|
|
|
IsBusinessLocking = b.IsBusinessLocking,
|
|
|
|
|
IsFeeLocking = b.IsFeeLocking,
|
|
|
|
|
IssueType = s.IssueType,
|
|
|
|
|
KGS = s.KGS,
|
|
|
|
|
LoadPort = s.LoadPort,
|
|
|
|
|
MBLFrt = s.MBLFrt,
|
|
|
|
|
MBLNO = s.MBLNO,
|
|
|
|
|
Note = s.Note,
|
|
|
|
|
OperatorId = s.OperatorId,
|
|
|
|
|
OrderNo = s.OrderNo,
|
|
|
|
|
PKGS = s.PKGS,
|
|
|
|
|
ReceiptPlace = s.ReceiptPlace,
|
|
|
|
|
Remark = s.Remark,
|
|
|
|
|
SaleDeptId = s.SaleDeptId,
|
|
|
|
|
//SaleDeptName //所属部门
|
|
|
|
|
SaleId = s.SaleId,
|
|
|
|
|
SaleName = s.Sale,//揽货人
|
|
|
|
|
SourceId = s.SourceId,
|
|
|
|
|
SourceName = cs.SourceName,
|
|
|
|
|
SourceDetailId = s.SourceDetailId,
|
|
|
|
|
DetailName = csd.DetailName,
|
|
|
|
|
TradeTerm = s.TradeTerm,
|
|
|
|
|
TransitTerms = s.Service,//运输条款
|
|
|
|
|
Vessel = s.Vessel,//船名
|
|
|
|
|
Voyage = s.Voyno,//航次
|
|
|
|
|
Yard = s.Yard
|
|
|
|
|
//BusinessUnit = //经营单位
|
|
|
|
|
//ChangeOrder //更改单
|
|
|
|
|
//ChangeReason //更改单更改原因
|
|
|
|
|
//FreightRatio //运杂费比例
|
|
|
|
|
//查询:运输类型 (枚举值,暂未建立)
|
|
|
|
|
//查询:是否费用提交
|
|
|
|
|
//查询:利润减少
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//海运进口
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return TenantDb.UnionAll(new List<ISugarQueryable<FeeAuditBusiness>> { query1 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 按费用批量审核
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="yesOrNo">审批结果:1=通过,2=驳回</param>
|
|
|
|
|
/// <param name="remark">备注</param>
|
|
|
|
|
/// <param name="idArray">待审批的费用ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult> AuditAsync(int yesOrNo, string remark, params long[] idArray)
|
|
|
|
|
{
|
|
|
|
|
var fees = await TenantDb.Queryable<FeeRecord>().Where(x => idArray.Contains(x.Id)).Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
x.FeeName,
|
|
|
|
|
x.FeeStatus,
|
|
|
|
|
x.FlowId
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (fees.Count == 0)
|
|
|
|
|
return DataResult.Failed("未能获取费用信息");
|
|
|
|
|
|
|
|
|
|
if (fees.Exists(x => !x.FlowId.HasValue))
|
|
|
|
|
return DataResult.Failed("提交数据中包含不在审批流程中的费用");
|
|
|
|
|
|
|
|
|
|
if (fees.Exists(x => !AuditStatusArray.Contains(x.FeeStatus)))
|
|
|
|
|
return DataResult.Failed("提交数据中包含不在待审批状态的费用");
|
|
|
|
|
|
|
|
|
|
var flowIds = fees.Select(x => x.FlowId.GetValueOrDefault());
|
|
|
|
|
var flows = await Db.Queryable<FlowInstance>().Where(x => flowIds.Contains(x.Id)).ToListAsync();
|
|
|
|
|
if (flows.Count == 0)
|
|
|
|
|
return DataResult.Failed("未能获取审批工作流");
|
|
|
|
|
|
|
|
|
|
if (flows.Exists(x => !x.MakerList.Contains(User.UserId)))
|
|
|
|
|
return DataResult.Failed("所选费用包含不属于当前用户权限范围内的审批,禁止提交");
|
|
|
|
|
|
|
|
|
|
List<string> list = [];
|
|
|
|
|
foreach (var fee in fees)
|
|
|
|
|
{
|
|
|
|
|
var flow = flows.Find(x => x.Id == fee.FlowId.Value);
|
|
|
|
|
if (flow == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = flowService.AuditFlowInstance(new FlowAuditInfo
|
|
|
|
|
{
|
|
|
|
|
Instance = flow,
|
|
|
|
|
Status = yesOrNo,
|
|
|
|
|
AuditNote = remark
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
list.Add(fee.FeeName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (list.Count > 0)
|
|
|
|
|
return DataResult.Failed($"部分费用审批失败:{string.Join("、", list)}");
|
|
|
|
|
|
|
|
|
|
return DataResult.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 本票审核(一键审核当前登录用户的所有待审核项)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="yesOrNo">审批结果:1=通过,2=驳回</param>
|
|
|
|
|
/// <param name="remark">备注</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult> AuditAsync(int yesOrNo, string remark)
|
|
|
|
|
{
|
|
|
|
|
var recordIds = await Db.Queryable<FlowInstance>().Where(x => x.FlowStatus == RunningStatus &&
|
|
|
|
|
SqlFunc.SplitIn(x.MakerList, User.UserId) && AuditTypes.Contains(x.AuditType))
|
|
|
|
|
.Select(x => x.BusinessId).ToArrayAsync();
|
|
|
|
|
//没有待审批的列表直接返回不再执行后续查询
|
|
|
|
|
if (recordIds.Length == 0)
|
|
|
|
|
return DataResult.Failed("当前暂无待审批的费用");
|
|
|
|
|
|
|
|
|
|
return await AuditAsync(yesOrNo, remark, recordIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 按业务批量审核
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult> AuditAsync(FeeBizAuditRequest request)
|
|
|
|
|
{
|
|
|
|
|
var list1 = request.Items.Select(x => x.Id).ToList();
|
|
|
|
|
var list2 = request.Items.Select(x => x.BusinessType).Distinct().ToList();
|
|
|
|
|
var recordIds = await TenantDb.Queryable<FeeRecord>().Where(x =>
|
|
|
|
|
list1.Contains(x.BusinessId) && list2.Contains(x.BusinessType) && AuditStatusArray.Contains(x.FeeStatus))
|
|
|
|
|
.Select(x => x.Id).ToArrayAsync();
|
|
|
|
|
|
|
|
|
|
//没有待审批的列表直接返回不再执行后续查询
|
|
|
|
|
if (recordIds.Length == 0)
|
|
|
|
|
return DataResult.Failed("当前暂无待审批的费用");
|
|
|
|
|
|
|
|
|
|
return await AuditAsync(request.Result, request.Remark, recordIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 整单审核
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">审批请求</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult> AuditBusinessAsync(FeeBizAuditRequest request)
|
|
|
|
|
{
|
|
|
|
|
var gpList = request.Items.GroupBy(x => x.BusinessType).ToList();
|
|
|
|
|
foreach (var gp in gpList)
|
|
|
|
|
{
|
|
|
|
|
var bIdArr = gp.Select(x => x.Id).ToArray();
|
|
|
|
|
var bizList = await TenantDb.Queryable<BusinessFeeStatus>().Where(x => bIdArr.Contains(x.BusinessId) && x.BusinessType == gp.Key)
|
|
|
|
|
.Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
x.BillAuditStatus,
|
|
|
|
|
x.FlowId
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (bizList.Count == 0)
|
|
|
|
|
return DataResult.Failed("未能获取业务信息");
|
|
|
|
|
|
|
|
|
|
if (!bizList.Any(x => x.FlowId.HasValue))
|
|
|
|
|
return DataResult.Failed("业务未处于审批流程中");
|
|
|
|
|
|
|
|
|
|
if (bizList.Any(x => x.BillAuditStatus != BillAuditStatus.AuditSubmitted))
|
|
|
|
|
return DataResult.Failed("业务的审批状态不正确");
|
|
|
|
|
|
|
|
|
|
var fIdArr = bizList.Select(x => x.FlowId).ToArray();
|
|
|
|
|
string auditType = AuditType.FeeBusiness.ToString();
|
|
|
|
|
var flows = await Db.Queryable<FlowInstance>().Where(x => fIdArr.Contains(x.Id) && x.AuditType == auditType).ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (flows.Count == 0)
|
|
|
|
|
return DataResult.Failed("未能获取审批工作流");
|
|
|
|
|
|
|
|
|
|
if (flows.Any(x => !x.MakerList.Contains(User.UserId)))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
foreach (var flow in flows)
|
|
|
|
|
{
|
|
|
|
|
var result = flowService.AuditFlowInstance(new FlowAuditInfo
|
|
|
|
|
{
|
|
|
|
|
Instance = flow,
|
|
|
|
|
Status = request.Result,
|
|
|
|
|
AuditNote = request.Remark
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
//todo:记录未能成功审核的数据
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置业务费用锁定状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="items">业务信息</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult> SetFeeLockingAsync(IEnumerable<BusinessFeeStatus> items)
|
|
|
|
|
{
|
|
|
|
|
int rows = await TenantDb.Updateable<BusinessFeeStatus>(items)
|
|
|
|
|
.WhereColumns(x => new { x.BusinessId, x.BusinessType })
|
|
|
|
|
.UpdateColumns(x => new { x.IsFeeLocking })
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
return rows > 0 ? DataResult.Success : DataResult.Failed("更新失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据审批结果更新审批状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="callback">回调信息</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult> UpdateStatusAsync(FlowCallback callback)
|
|
|
|
|
{
|
|
|
|
|
var auditType = callback.AuditType.ToEnum<AuditType>();
|
|
|
|
|
FeeRecord fee = null;
|
|
|
|
|
BusinessFeeStatus biz = null;
|
|
|
|
|
if (auditType == AuditType.FeeBusiness)
|
|
|
|
|
{
|
|
|
|
|
biz = await 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
|
|
|
|
|
}).FirstAsync();
|
|
|
|
|
if (biz == null)
|
|
|
|
|
return DataResult.Failed("未能找到业务信息,更新状态失败", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fee = await TenantDb.Queryable<FeeRecord>().Where(x => x.Id == callback.BusinessId && x.BusinessType == callback.BusinessType).Select(
|
|
|
|
|
x => new FeeRecord { Id = x.Id, FeeStatus = x.FeeStatus }).FirstAsync();
|
|
|
|
|
if (fee == null)
|
|
|
|
|
return DataResult.Failed("未能找到费用记录,更新状态失败", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
|
|
|
|
|
fee.Reason = callback.RejectReason;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long UserId = long.Parse(User.UserId);
|
|
|
|
|
DateTime dtNow = DateTime.Now;
|
|
|
|
|
await TenantDb.Ado.BeginTranAsync();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
switch (auditType)
|
|
|
|
|
{
|
|
|
|
|
case AuditType.FeeAudit:
|
|
|
|
|
fee.AuditBy = UserId;
|
|
|
|
|
fee.AuditOperator = User.UserName;
|
|
|
|
|
fee.AuditDate = dtNow;
|
|
|
|
|
|
|
|
|
|
if (callback.FlowStatus == FlowStatusEnum.Approve)
|
|
|
|
|
{
|
|
|
|
|
fee.FeeStatus = FeeStatus.AuditPassed;
|
|
|
|
|
fee.Reason = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
else if (callback.FlowStatus == FlowStatusEnum.Reject)
|
|
|
|
|
fee.FeeStatus = FeeStatus.RejectSubmission;
|
|
|
|
|
|
|
|
|
|
await TenantDb.Updateable(fee).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.FeeStatus,
|
|
|
|
|
x.AuditBy,
|
|
|
|
|
x.AuditOperator,
|
|
|
|
|
x.AuditDate,
|
|
|
|
|
x.Reason,
|
|
|
|
|
x.FlowId
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case AuditType.FeeModify:
|
|
|
|
|
//申请修改审核成功需要回填费用信息
|
|
|
|
|
if (callback.FlowStatus == FlowStatusEnum.Approve)
|
|
|
|
|
{
|
|
|
|
|
var fm = await TenantDb.Queryable<FeeModification>().Where(x => x.FeeRecordId == fee.Id).OrderByDescending(x => x.CreateTime).FirstAsync();
|
|
|
|
|
if (fm == null)
|
|
|
|
|
return DataResult.Failed("未找到费用修改信息,更新失败", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
|
|
|
|
|
var entity = fm.Adapt<FeeRecord>();
|
|
|
|
|
entity.Id = fm.FeeRecordId;
|
|
|
|
|
entity.FeeStatus = FeeStatus.AuditPassed;
|
|
|
|
|
entity.Reason = callback.RejectReason;
|
|
|
|
|
entity.UpdateBy = UserId;
|
|
|
|
|
entity.UpdateTime = dtNow;
|
|
|
|
|
//全表更新
|
|
|
|
|
await TenantDb.Updateable(entity).IgnoreColumns(
|
|
|
|
|
x => new { x.AuditBy, x.AuditDate, x.AuditOperator, x.SubmitBy, x.SubmitDate }).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
//逻辑删除暂存数据
|
|
|
|
|
fm.Deleted = true;
|
|
|
|
|
fm.DeleteTime = dtNow;
|
|
|
|
|
fm.DeleteBy = UserId;
|
|
|
|
|
await TenantDb.Updateable(fm).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.DeleteBy,
|
|
|
|
|
x.Deleted,
|
|
|
|
|
x.DeleteTime
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else if (callback.FlowStatus == FlowStatusEnum.Reject)
|
|
|
|
|
{
|
|
|
|
|
fee.FeeStatus = FeeStatus.RejectApplication;
|
|
|
|
|
await TenantDb.Updateable(fee).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.FeeStatus,
|
|
|
|
|
x.Reason,
|
|
|
|
|
x.FlowId
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case AuditType.FeeDelete:
|
|
|
|
|
if (callback.FlowStatus == FlowStatusEnum.Approve)
|
|
|
|
|
{
|
|
|
|
|
fee.Deleted = true;
|
|
|
|
|
fee.DeleteBy = UserId;
|
|
|
|
|
fee.DeleteTime = dtNow;
|
|
|
|
|
|
|
|
|
|
await TenantDb.Updateable(fee).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.DeleteBy,
|
|
|
|
|
x.Deleted,
|
|
|
|
|
x.DeleteTime,
|
|
|
|
|
x.Reason,
|
|
|
|
|
x.FlowId
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
//TenantDb.Deleteable(fee).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fee.FeeStatus = FeeStatus.RejectApplication;
|
|
|
|
|
|
|
|
|
|
await TenantDb.Updateable(fee).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.FeeStatus,
|
|
|
|
|
x.Reason,
|
|
|
|
|
x.FlowId
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case AuditType.FeeBusiness:
|
|
|
|
|
FeeStatus status = FeeStatus.RejectSubmission;
|
|
|
|
|
if (callback.FlowStatus == FlowStatusEnum.Approve)
|
|
|
|
|
{
|
|
|
|
|
biz.BillAuditStatus = BillAuditStatus.AuditPassed;
|
|
|
|
|
status = FeeStatus.AuditPassed;
|
|
|
|
|
}
|
|
|
|
|
else if (callback.FlowStatus == FlowStatusEnum.Reject)
|
|
|
|
|
{
|
|
|
|
|
biz.BillAuditStatus = BillAuditStatus.Rejected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await TenantDb.Updateable(biz).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.BillAuditStatus,
|
|
|
|
|
x.FlowId
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
await 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 == biz.BusinessId && x.BusinessType == callback.BusinessType &&
|
|
|
|
|
(x.FeeStatus == FeeStatus.Entering || x.FeeStatus == FeeStatus.RejectSubmission)).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return DataResult.Failed("费用未处于审批状态,更新失败", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//驳回申请则逻辑删除关联工作流
|
|
|
|
|
if (callback.FlowStatus == FlowStatusEnum.Reject)
|
|
|
|
|
{
|
|
|
|
|
await Db.Updateable(new FlowInstance
|
|
|
|
|
{
|
|
|
|
|
Id = callback.InstanceId,
|
|
|
|
|
Deleted = true,
|
|
|
|
|
DeleteBy = 0,
|
|
|
|
|
DeleteTime = DateTime.Now
|
|
|
|
|
}).UpdateColumns(x => new { x.Deleted, x.DeleteBy, x.DeleteTime }).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await TenantDb.Ado.CommitTranAsync();
|
|
|
|
|
return DataResult.Successed("提交成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
await TenantDb.Ado.RollbackTranAsync();
|
|
|
|
|
await ex.LogAsync(Db);
|
|
|
|
|
return DataResult.Failed("提交失败!", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
await feeService.WriteBackStatusAsync(callback.BusinessId, callback.BusinessType.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//public DataResult<List<FeeAudit>> GetListByPage(PageRequest request)
|
|
|
|
|
//{
|
|
|
|
|
// var whereList = Db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
|
|
|
|
|
|
|
|
// var query1 = TenantDb.Queryable<FeeRecord>()
|
|
|
|
|
// .InnerJoin<SeaExport>((x, y) => x.BusinessId == y.Id)
|
|
|
|
|
// .LeftJoin<InfoClient>((x, y, z) => x.CustomerId == z.Id)
|
|
|
|
|
// .Select((x, y, z) => new FeeAudit
|
|
|
|
|
// {
|
|
|
|
|
// Id = x.Id,
|
|
|
|
|
// BusinessId = x.BusinessId,
|
|
|
|
|
// BusinessType = x.BusinessType,
|
|
|
|
|
// FeeStatus = x.FeeStatus,
|
|
|
|
|
// FeeType = x.FeeType,
|
|
|
|
|
// FeeName = x.FeeName,
|
|
|
|
|
// FeeEnName = x.FeeEnName,
|
|
|
|
|
// CustomerName = x.CustomerName,
|
|
|
|
|
// CustomerFullName = z.Description, //结算对象全称
|
|
|
|
|
// CustomerType = x.CustomerType,
|
|
|
|
|
// CustomerTypeText = x.CustomerTypeText,
|
|
|
|
|
// Unit = x.Unit,
|
|
|
|
|
// UnitText = x.UnitText,
|
|
|
|
|
// UnitPrice = x.UnitPrice,
|
|
|
|
|
// TaxUnitPrice = x.TaxUnitPrice,
|
|
|
|
|
// Quantity = x.Quantity,
|
|
|
|
|
// TaxRate = x.TaxRate,
|
|
|
|
|
// NoTaxAmount = x.NoTaxAmount,
|
|
|
|
|
// Amount = x.Amount,
|
|
|
|
|
// Currency = x.Currency,
|
|
|
|
|
// CurrencyText = x.CurrencyText,
|
|
|
|
|
// ExchangeRate = x.ExchangeRate,
|
|
|
|
|
// AccTaxRate = x.AccTaxRate,//销项汇率
|
|
|
|
|
// Remark = x.Remark,
|
|
|
|
|
// IsAdvancedPay = x.IsAdvancedPay,//是否垫付
|
|
|
|
|
// IsInvoice = x.IsInvoice, //是否开发票
|
|
|
|
|
// //FRT
|
|
|
|
|
// CommissionRate = x.CommissionRate, //佣金比率
|
|
|
|
|
// CreateBy = x.CreateBy,
|
|
|
|
|
// CreateTime = x.CreateTime,
|
|
|
|
|
// AuditOperator = x.AuditOperator,
|
|
|
|
|
// AuditDate = x.AuditDate,
|
|
|
|
|
// SettlementAmount = x.SettlementAmount,//结算金额
|
|
|
|
|
// InvoiceAmount = x.InvoiceAmount,//开票金额
|
|
|
|
|
// OrderAmount = x.OrderAmount,//申请金额
|
|
|
|
|
// InvoiceNum = x.InvoiceNum,//发票号
|
|
|
|
|
// Tax = x.Tax,//税额
|
|
|
|
|
// DebitNo = x.DebitNo,//对账编号
|
|
|
|
|
// SubmitBy = x.SubmitBy,
|
|
|
|
|
// SubmitDate = x.SubmitDate,
|
|
|
|
|
// SaleOrg = x.SaleOrg,
|
|
|
|
|
// Reason = x.Reason,
|
|
|
|
|
// IsOpen = x.IsOpen,//是否机密
|
|
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// var queryList = TenantDb.UnionAll(new List<ISugarQueryable<FeeAudit>> { query1 });
|
|
|
|
|
// var result = queryList.Where(whereList).ToQueryPage(request.PageCondition);
|
|
|
|
|
|
|
|
|
|
// if (result.Data.Count > 0)
|
|
|
|
|
// {
|
|
|
|
|
// //关联用户名称
|
|
|
|
|
// var UserIds = result.Data.Where(x => x.SubmitBy.HasValue).Select(x => x.SubmitBy.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.SubmitBy.HasValue)
|
|
|
|
|
// {
|
|
|
|
|
// item.SubmitByName = Users.Find(x => x.Id == item.SubmitBy.Value)?.UserName;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// return result;
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|