申请单提交审核/撤销

usertest
嵇文龙 6 months ago
parent 974ba3daee
commit b1ec13fe86

@ -8,23 +8,26 @@ public class IdModel
/// <summary>
/// 主键id
/// </summary>
public string Id { get; set; }
public string? Id { get; set; }
/// <summary>
/// 主键ids
/// </summary>
public long[] Ids { get; set; }
public long[]? Ids { get; set; }
/// <summary>
/// 业务类型1、海运出口 2、海运进口
/// </summary>
public int BusinessType { get; set; }
public int? BusinessType { get; set; }
public object Value { get; set; }
/// <summary>
/// 请求值
/// </summary>
public object? Value { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Remark { get; set; }
public string? Remark { get; set; }
}

@ -105,6 +105,12 @@ namespace DS.WMS.Core.Fee.Entity
[SugarColumn(ColumnDescription = "驳回原因", Length = 200)]
public string? Reason { get; set; }
/// <summary>
/// 工作流ID
/// </summary>
[SugarColumn(ColumnDescription = "工作流ID", IsNullable = true)]
public long? FlowId { get; set; }
/// <summary>
/// 费用明细
/// </summary>

@ -5,6 +5,7 @@ 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;
@ -29,7 +30,6 @@ namespace DS.WMS.Core.Fee.Method
flowService = serviceProvider.GetRequiredService<IClientFlowInstanceService>();
}
/// <summary>
/// 获取待付费的业务列表
/// </summary>
@ -37,7 +37,7 @@ namespace DS.WMS.Core.Fee.Method
/// <returns></returns>
public async Task<DataResult<List<FeeApplicationBiz>>> GetBizListAsync(PageRequest request)
{
var queryList = CreateBizQuery(TenantDb);
var queryList = CreateBizQuery();
if (!request.QueryCondition.IsNullOrEmpty())
{
@ -66,10 +66,10 @@ namespace DS.WMS.Core.Fee.Method
}
//创建各项业务数据的查询并集
internal static ISugarQueryable<FeeApplicationBiz> CreateBizQuery(SqlSugarScopeProvider tenantDb)
internal ISugarQueryable<FeeApplicationBiz> CreateBizQuery()
{
//海运出口
var query1 = tenantDb.Queryable<SeaExport>().InnerJoin<FeeRecord>((s, f) => s.Id == f.BusinessId && f.BusinessType == BusinessType.OceanShippingExport)
var query1 = TenantDb.Queryable<SeaExport>().InnerJoin<FeeRecord>((s, f) => s.Id == f.BusinessId && f.BusinessType == BusinessType.OceanShippingExport)
.Where((s, f) => f.FeeStatus == FeeStatus.AuditPassed)
.GroupBy((s, f) => s.Id)
.Select(s => new FeeApplicationBiz
@ -116,7 +116,7 @@ namespace DS.WMS.Core.Fee.Method
//海运进口
return tenantDb.UnionAll(new List<ISugarQueryable<FeeApplicationBiz>> { query1 });
return TenantDb.UnionAll(new List<ISugarQueryable<FeeApplicationBiz>> { query1 });
}
/// <summary>
@ -195,12 +195,10 @@ namespace DS.WMS.Core.Fee.Method
/// <returns></returns>
public async Task<DataResult> DeleteAsync(params long[] ids)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (await tenantDb.Queryable<FeeApplication>().AnyAsync(x => ids.Contains(x.Id) && (x.Status != ApplicationStatus.Pending && x.Status != ApplicationStatus.AuditRejected)))
if (await TenantDb.Queryable<FeeApplication>().AnyAsync(x => ids.Contains(x.Id) && (x.Status != ApplicationStatus.Pending && x.Status != ApplicationStatus.AuditRejected)))
return DataResult.Failed("只能删除状态为‘待审核’或‘驳回’的申请单", MultiLanguageConst.FeeRecordDelete);
bool result = await tenantDb.DeleteNav<FeeApplication>(x => ids.Contains(x.Id)).Include(x => x.Details).ExecuteCommandAsync();
bool result = await TenantDb.DeleteNav<FeeApplication>(x => ids.Contains(x.Id)).Include(x => x.Details).ExecuteCommandAsync();
return result ? DataResult.Successed("删除成功!") : DataResult.Failed("删除失败!");
}
@ -223,11 +221,14 @@ namespace DS.WMS.Core.Fee.Method
ItemCount = SqlFunc.AggregateCount(y.Id)
}).ToListAsync();
if (list.Count == 0)
return DataResult.Failed("未能找到申请单记录");
if (list.Exists(x => x.Status == ApplicationStatus.AuditSubmittd || x.Status == ApplicationStatus.AuditPassed))
return DataResult.Failed("提交内容包含正在审批中/已审批的申请单", MultiLanguageConst.Operation_Failed);
return DataResult.Failed("提交内容包含正在审批中/已审批的申请单");
if (list.Exists(x => x.ItemCount == 0))
return DataResult.Failed("提交审批时必须包含费用明细,请检查", MultiLanguageConst.Operation_Failed);
return DataResult.Failed("提交审批时必须包含费用明细,请检查");
var template = await FindTemplateAsync(auditType);
if (template == null)
@ -244,12 +245,15 @@ namespace DS.WMS.Core.Fee.Method
BusinessId = item.Id,
TemplateId = template.Id
});
if (result.Succeeded)
if (result.Succeeded)
{
item.Status = ApplicationStatus.AuditSubmittd;
item.AuditRemark = remark;
var instance = result.Data as FlowInstance;
flowService.StartFlowInstance(instance.Id.ToString());
await TenantDb.Updateable(item).ExecuteCommandAsync();
item.Status = ApplicationStatus.AuditSubmittd;
item.FlowId = instance.Id;
await TenantDb.Updateable(item).UpdateColumns(x => new { x.Status, x.FlowId }).ExecuteCommandAsync();
}
}
@ -271,7 +275,48 @@ namespace DS.WMS.Core.Fee.Method
/// <returns></returns>
public async Task<DataResult> WithdrawAsync(params long[] ids)
{
throw new NotImplementedException();
var list = await TenantDb.Queryable<FeeApplication>().Where(x => ids.Contains(x.Id)).Select(
x => new FeeApplication
{
Id = x.Id,
ApplicationNO = x.ApplicationNO,
Status = x.Status,
FlowId = x.FlowId
}).ToListAsync();
if (list.Count == 0)
return DataResult.Failed("未能找到申请单记录");
//未在审批状态中
var list2 = list.FindAll(x => x.FlowId == null).ToList();
if (list2.Count > 0)
{
string msg = string.Join("; ", list2.Select(x => $"{x.ApplicationNO}"));
return DataResult.Failed($"以下:{msg} 未在审批状态中,无需撤销");
}
var flows = list.Select(x => new FlowInstance { Id = x.FlowId.Value, FlowStatus = (int)FlowStatusEnum.Draft, MakerList = string.Empty }).ToList();
DateTime dtNow = DateTime.Now;
try
{
await Db.Updateable(flows).UpdateColumns(x => new { x.FlowStatus, x.MakerList }).ExecuteCommandAsync();
foreach (var item in list)
{
item.Status = ApplicationStatus.Pending;
item.FlowId = null;
}
await TenantDb.Updateable(list).UpdateColumns(x => new { x.Status, x.FlowId }).ExecuteCommandAsync();
await TenantDb.Ado.CommitTranAsync();
return DataResult.Successed("提交成功!");
}
catch (Exception ex)
{
await TenantDb.Ado.RollbackTranAsync();
await ex.LogAsync(Db);
return DataResult.Failed("提交失败!");
}
}
}

@ -58,7 +58,7 @@ namespace DS.WMS.Core.Fee.Method
if (flowList.Count == 0)
DataResult<List<FeeAuditBusiness>>.PageList(0, null, MultiLanguageConst.DataQuerySuccess);
var queryList = CreateQuery(TenantDb, flowList);
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());
@ -105,7 +105,7 @@ namespace DS.WMS.Core.Fee.Method
if (flowList.Count == 0)
DataResult<List<FeeAuditBusiness>>.PageList(0, null, MultiLanguageConst.DataQuerySuccess);
var queryList = CreateBizQuery(TenantDb, flowList);
var queryList = CreateBizQuery(flowList);
if (!request.QueryCondition.IsNullOrEmpty())
{
@ -136,7 +136,7 @@ namespace DS.WMS.Core.Fee.Method
}
//创建各项费用数据的查询并集
internal static ISugarQueryable<FeeAuditBusiness> CreateQuery(SqlSugarScopeProvider TenantDb, IEnumerable<FlowInstance> additions)
internal ISugarQueryable<FeeAuditBusiness> CreateQuery(IEnumerable<FlowInstance> additions)
{
//海运出口
var ids1 = additions?.Where(x => x.BusinessType == BusinessType.OceanShippingExport).Select(x => x.BusinessId).ToArray();
@ -222,7 +222,7 @@ namespace DS.WMS.Core.Fee.Method
}
//创建各项业务数据的查询并集
internal static ISugarQueryable<FeeAuditBusiness> CreateBizQuery(SqlSugarScopeProvider TenantDb, IEnumerable<FlowInstance> additions)
internal ISugarQueryable<FeeAuditBusiness> CreateBizQuery(IEnumerable<FlowInstance> additions)
{
//海运出口
var ids1 = additions?.Where(x => x.BusinessType == BusinessType.OceanShippingExport).Select(x => x.BusinessId).ToArray();
@ -650,7 +650,7 @@ namespace DS.WMS.Core.Fee.Method
}
finally
{
await feeService.WriteBackStatusAsync(TenantDb, callback.BusinessId, callback.BusinessType);
await feeService.WriteBackStatusAsync(callback.BusinessId, callback.BusinessType.Value);
}
}

@ -523,7 +523,7 @@ namespace DS.WMS.Core.Fee.Method
FlowId = x.FlowId
}).ToListAsync();
if (fees.IsNullOrEmpty())
if (fees.Count == 0)
return DataResult.Failed("未能找到费用记录", MultiLanguageConst.Operation_Failed);
//未在审批状态中
@ -536,9 +536,9 @@ namespace DS.WMS.Core.Fee.Method
var flows = fees.Select(x => new FlowInstance { Id = x.FlowId.Value, FlowStatus = (int)FlowStatusEnum.Draft, MakerList = string.Empty }).ToList();
DateTime dtNow = DateTime.Now;
await TenantDb.Ado.BeginTranAsync();
try
{
await TenantDb.Ado.BeginTranAsync();
await Db.Updateable(flows).UpdateColumns(x => new { x.FlowStatus, x.MakerList }).ExecuteCommandAsync();
foreach (var item in fees)
@ -798,7 +798,6 @@ namespace DS.WMS.Core.Fee.Method
/// <summary>
/// 回写业务表费用状态
/// </summary>
/// <param name="TenantDb"></param>
/// <param name="businessId">业务ID</param>
/// <param name="businessType">业务类型</param>
/// <returns></returns>

@ -15,7 +15,6 @@ namespace DS.WMS.Core.Fee.Method
/// </summary>
public abstract class FeeServiceBase
{
const long PERMISSION_ID = 1793490768447541248;
/// <summary>
/// //默认本币
/// </summary>
@ -68,10 +67,8 @@ namespace DS.WMS.Core.Fee.Method
protected async Task<FlowTemplateTenant> FindTemplateAsync(AuditType auditType)
{
string typeStr = auditType.ToString();
return await Db.Queryable<FlowTemplateTenant>().Where(x =>
x.Status == StatusEnum.Enable &&
x.PermissionId == PERMISSION_ID &&
x.AuditType == typeStr).FirstAsync();
return await Db.Queryable<FlowTemplateTenant>().FirstAsync(x =>
x.Status == StatusEnum.Enable && x.AuditType == typeStr);
}
/// <summary>

@ -9,7 +9,7 @@ namespace DS.WMS.Core.Flow.Dtos
public long BusinessId { get; set; }
public BusinessType BusinessType { get; set; }
public BusinessType? BusinessType { get; set; }
public string AuditType { get; set; }

@ -8,7 +8,7 @@ namespace DS.WMS.Core.Flow.Entity;
/// <summary>
/// 工作流实例
/// </summary>
[SqlSugar.SugarTable("sys_flow_instance")]
[SugarTable("sys_flow_instance")]
public class FlowInstance : BaseTenantModel<long>
{
/// <summary>
@ -18,7 +18,7 @@ public class FlowInstance : BaseTenantModel<long>
public long BusinessId { get; set; }
[Description("业务类型")]
public BusinessType BusinessType { get; set; }
public BusinessType? BusinessType { get; set; }
/// <summary>
/// 模板Id

@ -441,7 +441,7 @@ public class FlowInstanceService : IFlowInstanceService
var response = await http.PostAsync(uri, jsonRequest);
if (!response.IsSuccessStatusCode)
{
new HttpRequestException("回调请求失败", null, response.StatusCode).LogAsync(db);
await new HttpRequestException("回调请求失败", null, response.StatusCode).LogAsync(db);
}
//更新回调执行标识
@ -450,7 +450,7 @@ public class FlowInstanceService : IFlowInstanceService
}
catch (Exception ex)
{
ex.LogAsync(db);
await ex.LogAsync(db);
}
finally
{

@ -70,15 +70,29 @@ namespace DS.WMS.FeeApi.Controllers
return await _service.DeleteAsync(model.Ids);
}
/// <summary>
/// 发起审批
/// </summary>
/// <param name="model">申请单ID</param>
/// <returns></returns>
[HttpPost, Route("ApplyAudit")]
public async Task<DataResult> ApplyAuditAsync([FromBody] IdModel model)
{
if (model.Ids == null || model.Ids.Length == 0)
return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest);
return await _service.SubmitForApprovalAsync(AuditType.PaidApplication, model.Remark, model.Ids);
}
/// <summary>
/// 撤销审批
/// </summary>
/// <param name="model">申请单ID</param>
/// <returns></returns>
[NonAction]
[HttpPost, Route("Withdraw")]
public async Task<DataResult> WithdrawAsync(IdModel model)
{
if (model.Id == null || model.Ids.Length == 0)
if (model.Ids == null || model.Ids.Length == 0)
return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest);
return await _service.WithdrawAsync(model.Ids);

@ -100,7 +100,7 @@ namespace DS.WMS.FeeApi.Controllers
[HttpPost, Route("Delete")]
public async Task<DataResult> DeleteAsync([FromBody] IdModel model)
{
if (model == null || model.Ids?.Length == 0)
if (model.Ids == null || model.Ids.Length == 0)
return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest);
return await _feeService.DeleteAsync(model.Ids);
@ -114,7 +114,7 @@ namespace DS.WMS.FeeApi.Controllers
[HttpPost, Route("ApplyAudit")]
public async Task<DataResult> ApplyAuditAsync([FromBody] IdModel model)
{
if (model == null || model.Ids?.Length == 0)
if (model.Ids == null || model.Ids?.Length == 0)
return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest);
return await _feeService.SubmitForApprovalAsync(AuditType.FeeAudit, model.Remark, model.Ids);
@ -173,7 +173,7 @@ namespace DS.WMS.FeeApi.Controllers
if (model == null || !long.TryParse(model.Id, out long bid))
return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest);
return await _feeService.SubmitBusinessAuditAsync(bid, (BusinessType)model.BusinessType);
return await _feeService.SubmitBusinessAuditAsync(bid, (BusinessType)model.BusinessType.Value);
}
/// <summary>
@ -187,7 +187,7 @@ namespace DS.WMS.FeeApi.Controllers
if (model == null || model.Ids?.Length == 0)
return DataResult<CostAccountingForm>.Failed("参数无效", MultiLanguageConst.IllegalRequest);
return await _feeService.GetPrintInfoAsync((BusinessType)model.BusinessType, model.Ids);
return await _feeService.GetPrintInfoAsync((BusinessType)model.BusinessType.Value, model.Ids);
}
/// <summary>

@ -1132,3 +1132,31 @@
2024-06-11 10:02:13.5619 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Source\Repos\DS8\ds-wms-service\DS.WMS.FeeApi\bin\Debug\net8.0\nlog.config
2024-06-11 10:02:13.5619 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile
2024-06-11 10:02:13.5619 Info Configuration initialized.
2024-06-11 14:14:46.5991 Info Registered target NLog.Targets.FileTarget(Name=allfile)
2024-06-11 14:14:46.6366 Info Registered target NLog.Targets.FileTarget(Name=ownFile-web)
2024-06-11 14:14:46.6405 Info Registered target NLog.Targets.ColoredConsoleTarget(Name=console)
2024-06-11 14:14:46.6405 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False
2024-06-11 14:14:46.6566 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Source\Repos\DS8\ds-wms-service\DS.WMS.FeeApi\bin\Debug\net8.0\nlog.config
2024-06-11 14:14:46.6566 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile
2024-06-11 14:14:46.6566 Info Configuration initialized.
2024-06-11 14:35:51.7642 Info Registered target NLog.Targets.FileTarget(Name=allfile)
2024-06-11 14:35:51.7922 Info Registered target NLog.Targets.FileTarget(Name=ownFile-web)
2024-06-11 14:35:51.7952 Info Registered target NLog.Targets.ColoredConsoleTarget(Name=console)
2024-06-11 14:35:51.7952 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False
2024-06-11 14:35:51.8117 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Source\Repos\DS8\ds-wms-service\DS.WMS.FeeApi\bin\Debug\net8.0\nlog.config
2024-06-11 14:35:51.8117 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile
2024-06-11 14:35:51.8117 Info Configuration initialized.
2024-06-11 15:38:07.4778 Info Registered target NLog.Targets.FileTarget(Name=allfile)
2024-06-11 15:38:07.5100 Info Registered target NLog.Targets.FileTarget(Name=ownFile-web)
2024-06-11 15:38:07.5144 Info Registered target NLog.Targets.ColoredConsoleTarget(Name=console)
2024-06-11 15:38:07.5144 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False
2024-06-11 15:38:07.5294 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Source\Repos\DS8\ds-wms-service\DS.WMS.FeeApi\bin\Debug\net8.0\nlog.config
2024-06-11 15:38:07.5294 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile
2024-06-11 15:38:07.5294 Info Configuration initialized.
2024-06-11 15:46:56.8035 Info Registered target NLog.Targets.FileTarget(Name=allfile)
2024-06-11 15:46:56.8347 Info Registered target NLog.Targets.FileTarget(Name=ownFile-web)
2024-06-11 15:46:56.8347 Info Registered target NLog.Targets.ColoredConsoleTarget(Name=console)
2024-06-11 15:46:56.8486 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False
2024-06-11 15:46:56.8603 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Source\Repos\DS8\ds-wms-service\DS.WMS.FeeApi\bin\Debug\net8.0\nlog.config
2024-06-11 15:46:56.8603 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile
2024-06-11 15:46:56.8603 Info Configuration initialized.

Loading…
Cancel
Save