This commit is contained in:
2023-05-31 10:19:05 +08:00
parent 1b65a7a9e5
commit 9c621c75cd
238 changed files with 9905 additions and 4034 deletions

View File

@@ -10,6 +10,7 @@ using JNPF.FriendlyException;
using JNPF.WorkFlow.Entitys.Dto.FlowBefore;
using JNPF.WorkFlow.Entitys.Enum;
using JNPF.WorkFlow.Entitys.Model;
using JNPF.WorkFlow.Entitys.Model.Properties;
using JNPF.WorkFlow.Interfaces.Manager;
using JNPF.WorkFlow.Interfaces.Repository;
using Microsoft.AspNetCore.Mvc;
@@ -59,12 +60,32 @@ public class FlowBeforeService : IDynamicApiController, ITransient
case "4":
return await _flowTaskRepository.GetBatchWaitList(input);
default:
return PageResult<FlowBeforeListOutput>.SqlSugarPageResult(new SqlSugarPagedList<FlowBeforeListOutput>());
var pageList = new SqlSugarPagedList<FlowBeforeListOutput>()
{
list = new List<FlowBeforeListOutput>(),
pagination = new Pagination()
{
CurrentPage = input.currentPage,
PageSize = input.pageSize,
Total = 0
}
};
return PageResult<FlowBeforeListOutput>.SqlSugarPageResult(pageList);
}
}
catch (Exception ex)
{
return PageResult<FlowBeforeListOutput>.SqlSugarPageResult(new SqlSugarPagedList<FlowBeforeListOutput>());
var pageList = new SqlSugarPagedList<FlowBeforeListOutput>()
{
list = new List<FlowBeforeListOutput>(),
pagination = new Pagination()
{
CurrentPage = input.currentPage,
PageSize = input.pageSize,
Total = 0
}
};
return PageResult<FlowBeforeListOutput>.SqlSugarPageResult(pageList);
}
}
@@ -149,7 +170,7 @@ public class FlowBeforeService : IDynamicApiController, ITransient
}
/// <summary>
/// 批量审批流程列表.
/// 批量审批流程分类列表.
/// </summary>
/// <returns></returns>
[HttpGet("BatchFlowSelector")]
@@ -158,15 +179,36 @@ public class FlowBeforeService : IDynamicApiController, ITransient
return await _flowTaskRepository.BatchFlowSelector();
}
/// <summary>
/// 批量审批流程列表.
/// </summary>
/// <param name="templateId"></param>
/// <returns></returns>
[HttpGet("BatchFlowJsonList/{templateId}")]
public async Task<dynamic> BatchFlowJsonList(string templateId)
{
var list = (await _flowTaskRepository.GetWaitList()).FindAll(x => x.IsBatch == 1 && x.TemplateId == templateId);
var output = new List<object>();
foreach (var item in list)
{
var flowJson = _flowTaskRepository.GetFlowTemplateJsonInfo(x => x.Id == item.FlowId && x.DeleteMark == null);
if (flowJson.IsNotEmptyOrNull())
{
output.Add(new { id = flowJson.Id, fullName =string.Format("{0}(v{1})", flowJson.FullName, flowJson.Version), flowTemplateJson= flowJson.FlowTemplateJson });
}
}
return output.Distinct();
}
/// <summary>
/// 批量审批节点列表.
/// </summary>
/// <param name="flowId">流程id.</param>
/// <returns></returns>
[HttpGet("NodeSelector/{templateId}")]
public async Task<dynamic> NodeSelector(string templateId)
[HttpGet("NodeSelector/{flowId}")]
public async Task<dynamic> NodeSelector(string flowId)
{
return await _flowTaskManager.NodeSelector(templateId);
return await _flowTaskManager.NodeSelector(flowId);
}
/// <summary>
@@ -231,6 +273,39 @@ public class FlowBeforeService : IDynamicApiController, ITransient
{
return await _flowTaskManager.RejectNodeList(taskOperatorId);
}
/// <summary>
/// 子流程详情.
/// </summary>
/// <param name="taskNodeId">节点id.</param>
/// <returns></returns>
[HttpGet("SubFlowInfo/{taskNodeId}")]
public async Task<dynamic> SubFlowInfo(string taskNodeId)
{
var output = new List<object>();
var taskNodeEntity = await _flowTaskRepository.GetTaskNodeInfo(taskNodeId);
if (FlowTaskNodeTypeEnum.subFlow.ParseToString().Equals(taskNodeEntity.NodeType))
{
var childProp = taskNodeEntity.NodePropertyJson.ToObject<ChildTaskProperties>();
foreach (var item in childProp.childTaskId)
{
var childTaskInfo = await _flowTaskManager.GetFlowBeforeInfo(item, childProp.flowId, null, null);
output.Add(childTaskInfo);
}
}
return output;
}
/// <summary>
/// 挂起任务是否存在异步子流程.
/// </summary>
/// <param name="taskId">任务id.</param>
/// <returns></returns>
[HttpGet("Suspend/{taskId}")]
public async Task<dynamic> Suspend(string taskId)
{
return await _flowTaskRepository.AnyFlowTask(x => x.ParentId == taskId && x.IsAsync == 1 && x.DeleteMark == null);
}
#endregion
#region POST
@@ -258,8 +333,13 @@ public class FlowBeforeService : IDynamicApiController, ITransient
public async Task<dynamic> Reject(string taskOperatorId, [FromBody] FlowHandleModel flowHandleModel)
{
var flowTaskParamter = await _flowTaskRepository.GetTaskParamterByOperatorId(taskOperatorId, flowHandleModel);
if (flowTaskParamter.flowTaskEntity.Suspend == 1) throw Oops.Oh(ErrorCode.WF0046);
if (_flowTaskManager.IsSubFlowUpNode(flowTaskParamter))
throw Oops.Oh(ErrorCode.WF0019);
if (flowHandleModel.rejectType.IsNotEmptyOrNull())
{
flowTaskParamter.approversProperties.rejectType = flowHandleModel.rejectType.ParseToInt();
}
return await _flowTaskManager.Reject(flowTaskParamter);
}
@@ -277,6 +357,7 @@ public class FlowBeforeService : IDynamicApiController, ITransient
if (await _flowTaskRepository.AnyFlowTask(x => x.ParentId == flowTaskOperatorRecord.TaskId && x.Status != FlowTaskStatusEnum.Cancel.ParseToInt() && x.DeleteMark == null))
throw Oops.Oh(ErrorCode.WF0018);
var flowTaskParamter = await _flowTaskRepository.GetTaskParamterByOperatorId(flowTaskOperatorRecord.TaskOperatorId, flowHandleModel);
if (flowTaskParamter.flowTaskEntity.Suspend == 1) throw Oops.Oh(ErrorCode.WF0046);
await _flowTaskManager.Recall(flowTaskParamter, flowTaskOperatorRecord);
}
@@ -290,6 +371,7 @@ public class FlowBeforeService : IDynamicApiController, ITransient
public async Task Cancel(string taskId, [FromBody] FlowHandleModel flowHandleModel)
{
var flowTaskParamter = await _flowTaskRepository.GetTaskParamterByTaskId(taskId, flowHandleModel);
if (flowTaskParamter.flowTaskEntity.Suspend == 1) throw Oops.Oh(ErrorCode.WF0046);
if (flowTaskParamter.flowTaskEntity.FlowType == 1)
throw Oops.Oh(ErrorCode.WF0016);
await _flowTaskManager.Cancel(flowTaskParamter);
@@ -321,6 +403,7 @@ public class FlowBeforeService : IDynamicApiController, ITransient
if (nodeEntity.IsNotEmptyOrNull() && nodeEntity.Count > 0)
throw Oops.Oh(ErrorCode.WF0014);
var flowTaskParamter = await _flowTaskRepository.GetTaskParamterByTaskId(taskId, flowHandleModel);
if (flowTaskParamter.flowTaskEntity.Suspend == 1) throw Oops.Oh(ErrorCode.WF0046);
flowTaskParamter.thisFlowTaskOperatorEntityList = await _flowTaskRepository.GetTaskOperatorList(x => x.State == "0" && x.NodeCode == flowHandleModel.nodeCode && x.TaskId == taskId);
await _flowTaskManager.Assigned(flowTaskParamter);
}
@@ -336,6 +419,7 @@ public class FlowBeforeService : IDynamicApiController, ITransient
public async Task SaveAudit(string taskOperatorId, [FromBody] FlowHandleModel flowHandleModel)
{
var flowTaskParamter = await _flowTaskManager.Validation(taskOperatorId, flowHandleModel);
if (flowTaskParamter.flowTaskEntity.Suspend == 1) throw Oops.Oh(ErrorCode.WF0046);
flowTaskParamter.flowTaskOperatorEntity.DraftData = flowHandleModel.formData.ToJsonString();
await _flowTaskRepository.UpdateTaskOperator(flowTaskParamter.flowTaskOperatorEntity);
}
@@ -381,6 +465,7 @@ public class FlowBeforeService : IDynamicApiController, ITransient
public async Task<dynamic> Change([FromBody] FlowHandleModel flowHandleModel)
{
// 清除依次经办数据
if (await _flowTaskRepository.AnyFlowTask(x => x.Id == flowHandleModel.taskId && x.Suspend == 1 && x.DeleteMark == null)) throw Oops.Oh(ErrorCode.WF0046);
await _flowTaskRepository.DeleteTaskOperatorUser(flowHandleModel.taskId);
_flowTaskRepository.DeleteFlowCandidates(x => x.TaskId == flowHandleModel.taskId);
var flowTaskParamter = await _flowTaskRepository.GetTaskParamterByTaskId(flowHandleModel.taskId, flowHandleModel);
@@ -398,5 +483,31 @@ public class FlowBeforeService : IDynamicApiController, ITransient
{
return await Audit(taskOperatorId, flowHandleModel);
}
/// <summary>
/// 挂起.
/// </summary>
/// <param name="taskId">任务id.</param>
/// <param name="flowHandleModel">审批参数.</param>
/// <returns></returns>
[HttpPost("Suspend/{taskId}")]
public async Task Suspend(string taskId,[FromBody] FlowHandleModel flowHandleModel)
{
var flowTaskParamter = await _flowTaskRepository.GetTaskParamterByTaskId(taskId, flowHandleModel);
await _flowTaskManager.Suspend(flowTaskParamter);
}
/// <summary>
/// 恢复.
/// </summary>
/// <param name="taskId">任务id.</param>
/// <param name="flowHandleModel">审批参数.</param>
/// <returns></returns>
[HttpPost("Restore/{taskId}")]
public async Task Restore(string taskId, [FromBody] FlowHandleModel flowHandleModel)
{
var flowTaskParamter = await _flowTaskRepository.GetTaskParamterByTaskId(taskId, flowHandleModel);
await _flowTaskManager.Restore(flowTaskParamter);
}
#endregion
}

View File

@@ -6,13 +6,13 @@ using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.Message.Interfaces.Message;
using JNPF.Systems.Entitys.Dto.User;
using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Interfaces.Permission;
using JNPF.WorkFlow.Entitys.Dto.FlowDelegete;
using JNPF.WorkFlow.Entitys.Dto.FlowTemplate;
using JNPF.WorkFlow.Entitys.Entity;
using JNPF.WorkFlow.Interfaces.Repository;
using JNPF.WorkFlow.Interfaces.Service;
using Mapster;
using Microsoft.AspNetCore.Mvc;
@@ -29,15 +29,15 @@ public class FlowDelegateService : IDynamicApiController, ITransient
{
private readonly ISqlSugarRepository<FlowDelegateEntity> _repository;
private readonly IFlowTemplateService _flowTemplateService;
private readonly IFlowTaskRepository _flowTaskRepository;
private readonly IMessageService _messageService;
private readonly IOrganizeService _organizeService;
private readonly IUserManager _userManager;
public FlowDelegateService(ISqlSugarRepository<FlowDelegateEntity> repository, IFlowTemplateService flowTemplateService, IFlowTaskRepository flowTaskRepository, IOrganizeService organizeService, IUserManager userManager)
public FlowDelegateService(ISqlSugarRepository<FlowDelegateEntity> repository, IFlowTemplateService flowTemplateService, IMessageService messageService, IOrganizeService organizeService, IUserManager userManager)
{
_repository = repository;
_flowTemplateService = flowTemplateService;
_flowTaskRepository = flowTaskRepository;
_messageService = messageService;
_organizeService = organizeService;
_userManager = userManager;
}
@@ -72,7 +72,7 @@ public class FlowDelegateService : IDynamicApiController, ITransient
else
{
output = await _repository.AsQueryable().Where(x => x.ToUserId == _userManager.UserId && x.DeleteMark == null)
.WhereIF(!input.keyword.IsNullOrEmpty(), m => m.FlowName.Contains(input.keyword) || m.ToUserName.Contains(input.keyword)).OrderBy(t => t.SortCode)
.WhereIF(!input.keyword.IsNullOrEmpty(), m => m.FlowName.Contains(input.keyword) || m.UserName.Contains(input.keyword)).OrderBy(t => t.SortCode)
.OrderBy(x => x.CreatorTime, OrderByType.Desc).OrderByIF(!string.IsNullOrEmpty(input.keyword), t => t.LastModifyTime, OrderByType.Desc).ToPagedListAsync(input.currentPage, input.pageSize);
}
var pageList = new SqlSugarPagedList<FlowDelegeteListOutput>()
@@ -105,76 +105,102 @@ public class FlowDelegateService : IDynamicApiController, ITransient
var output = new List<FlowTemplateTreeOutput>();
//委托给我的发起流程
var flowDelegateList = await _repository.GetListAsync(x => x.ToUserId == _userManager.UserId && x.Type == "0" && x.EndTime > DateTime.Now && x.StartTime < DateTime.Now && x.DeleteMark == null);
foreach (var item in flowDelegateList)
if (!flowDelegateList.Any())
{
var flowList = await _flowTemplateService.GetFlowFormList(input.flowType.ParseToInt(), item.UserId);
// 非全部流程
if (item.FlowId.IsNotEmptyOrNull())
var pageList = new SqlSugarPagedList<FlowTemplateTreeOutput>()
{
output = output.Union(flowList.FindAll(x => item.FlowId.Contains(x.templateId))).DistinctBy(x => x.id).ToList();
}
else
{
output = output.Union(flowList).DistinctBy(x => x.id).ToList();
}
list = output,
pagination = new Pagination()
{
CurrentPage = input.currentPage,
PageSize = input.pageSize,
Total = output.Count
}
};
return PageResult<FlowTemplateTreeOutput>.SqlSugarPageResult(pageList);
}
if (input.keyword.IsNotEmptyOrNull())
output = output.FindAll(o => o.fullName.Contains(input.keyword) || o.enCode.Contains(input.keyword));
var pageList = new SqlSugarPagedList<FlowTemplateTreeOutput>()
//foreach (var item in flowDelegateList)
//{
// var flowList = await _flowTemplateService.GetFlowFormList(input.flowType.ParseToInt(), item.UserId);
// // 非全部流程
// if (item.FlowId.IsNotEmptyOrNull())
// {
// output = output.Union(flowList.FindAll(x => item.FlowId.Contains(x.templateId))).DistinctBy(x => x.id).ToList();
// }
// else
// {
// output = output.Union(flowList).DistinctBy(x => x.id).ToList();
// }
//}
//if (input.keyword.IsNotEmptyOrNull())
// output = output.FindAll(o => o.fullName.Contains(input.keyword) || o.enCode.Contains(input.keyword));
//var pageList = new SqlSugarPagedList<FlowTemplateTreeOutput>()
//{
// list = output.Skip((input.currentPage - 1) * input.pageSize).Take(input.pageSize).ToList(),
// pagination = new Pagination()
// {
// PageIndex = input.currentPage,
// PageSize = input.pageSize,
// Total = output.Count
// }
//};
//return PageResult<FlowTemplateTreeOutput>.SqlSugarPageResult(pageList);
var flowIds = string.Empty;
if (!flowDelegateList.Any(x => x.FlowId.IsNullOrEmpty()))
{
list = output.Skip((input.currentPage - 1) * input.pageSize).Take(input.pageSize).ToList(),
pagination = new Pagination()
{
CurrentPage = input.currentPage,
PageSize = input.pageSize,
Total = output.Count
}
};
return PageResult<FlowTemplateTreeOutput>.SqlSugarPageResult(pageList);
flowIds = string.Join(",", flowDelegateList.Select(x => x.FlowId).ToList());
}
var list = await _repository.AsSugarClient().Queryable<FlowTemplateEntity>()
.Where(a => a.DeleteMark == null && a.EnabledMark == 1)
.WhereIF(flowIds.IsNotEmptyOrNull(), x => flowIds.Contains(x.Id))
.WhereIF(input.category.IsNotEmptyOrNull(), a => a.Category == input.category)
.WhereIF(input.flowType.IsNotEmptyOrNull(), a => a.Type == input.flowType)
.WhereIF(input.keyword.IsNotEmptyOrNull(), a => a.FullName.Contains(input.keyword) || a.EnCode.Contains(input.keyword))
.Select(a => new FlowTemplateTreeOutput
{
id = a.Id,
category = a.Category,
enCode = a.EnCode,
fullName = a.FullName,
sortCode = a.SortCode,
creatorTime = a.CreatorTime,
lastModifyTime = a.LastModifyTime,
icon = a.Icon,
iconBackground = a.IconBackground,
type = a.Type,
}).MergeTable().OrderBy(a => a.sortCode).OrderBy(a => a.creatorTime, OrderByType.Desc)
.OrderBy(a => a.lastModifyTime, OrderByType.Desc).ToPagedListAsync(input.currentPage, input.pageSize);
return PageResult<FlowTemplateTreeOutput>.SqlSugarPageResult(list);
}
/// <summary>
/// 发起流程委托人.
/// </summary>
/// <param name="flowId">请求参数.</param>
/// <param name="input">请求参数.</param>
/// <returns></returns>
[HttpGet("userList")]
public async Task<dynamic> GetFlowList([FromQuery] string flowId)
{
var output = new List<UserListOutput>();
var userList = await _repository.AsSugarClient()
.Queryable<FlowTemplateJsonEntity, FlowDelegateEntity, UserEntity>((a, b, c) => new JoinQueryInfos(JoinType.Left, b.FlowId.Contains(a.TemplateId)||b.FlowName=="全部流程", JoinType.Left, b.UserId == c.Id))
.Where((a, b, c) => a.Id == flowId && b.Type == "0" && b.ToUserId == _userManager.UserId && b.EndTime > DateTime.Now && b.StartTime < DateTime.Now).Select((a, b, c) => new UserListOutput
{
id = c.Id,
headIcon = SqlFunc.MergeString("/api/File/Image/userAvatar/", c.HeadIcon),
fullName = SqlFunc.MergeString(c.RealName, "/", c.Account),
organizeId = c.OrganizeId
}).Distinct().ToListAsync();
if (!userList.Any())
throw Oops.Oh(ErrorCode.WF0049);
var orgList = _organizeService.GetOrgListTreeName();
var flowJsonModel = _flowTaskRepository.GetFlowTemplateInfo(flowId);
// 委托给我的发起流程
var delagateToMeList = await _repository.GetListAsync(x => x.ToUserId == _userManager.UserId && x.Type == "0" && x.EndTime > DateTime.Now && x.StartTime < DateTime.Now && x.DeleteMark == null);
foreach (var item in delagateToMeList)
foreach (var item in userList)
{
var isDelagateUser = false;
if (item.IsNotEmptyOrNull())
if (!item.id.Equals(_userManager.GetAdminUserId()))
{
if (item.FlowId.IsNotEmptyOrNull())
{
// 非全部流程
isDelagateUser = item.FlowId.Contains(flowJsonModel.templateId);
}
else
{
// 全部流程
var flowList = await _flowTemplateService.GetFlowFormList(flowJsonModel.type.ParseToInt(), item.UserId);
isDelagateUser = flowList.Select(x => x.id).Contains(flowId);
}
}
if (isDelagateUser)
{
UserListOutput userListOutput = new UserListOutput();
var delagateUser = _repository.AsSugarClient().Queryable<UserEntity>().First(x => x.Id == item.UserId && x.EnabledMark == 1 && x.DeleteMark == null);
userListOutput.id = delagateUser.Id;
userListOutput.headIcon = string.Format("/api/File/Image/userAvatar/{0}", delagateUser.HeadIcon);
userListOutput.fullName = string.Format("{0}/{1}", delagateUser.RealName, delagateUser.Account);
userListOutput.organize = orgList.FirstOrDefault(x => x.Id == delagateUser.OrganizeId).Description;
output.Add(userListOutput);
item.organize = orgList.FirstOrDefault(x => x.Id == item.organizeId).Description;
}
}
return new { list = output };
return new { list = userList };
}
#endregion
@@ -207,6 +233,16 @@ public class FlowDelegateService : IDynamicApiController, ITransient
var isOk = await _repository.AsInsertable(entity).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
if (isOk < 1)
throw Oops.Oh(ErrorCode.COM1000);
#region
var toUserIds = new List<string>() { entity.ToUserId };
var type = entity.Type == "0" ? "发起" : "审批";
var title = string.Format("{0}委托人向您发起了{1}委托!", entity.UserName, type);
var parameter = new { type = "2" };
var bodyDic = new Dictionary<string, object>();
bodyDic.Add(entity.ToUserId, parameter);
await _messageService.SentMessage(toUserIds, title, null, bodyDic, 2, "2");
#endregion
}
/// <summary>
@@ -224,6 +260,32 @@ public class FlowDelegateService : IDynamicApiController, ITransient
if (!isOk)
throw Oops.Oh(ErrorCode.COM1001);
}
/// <summary>
/// 结束委托.
/// </summary>
/// <param name="id">id.</param>
[HttpPut("Stop/{id}")]
public async Task Create(string id)
{
var entity = await _repository.GetFirstAsync(x => x.Id == id && x.DeleteMark == null);
if (entity == null)
throw Oops.Oh(ErrorCode.COM1005);
entity.StartTime = DateTime.Now;
entity.EndTime = DateTime.Now;
var isOk = await _repository.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).CallEntityMethod(m => m.LastModify()).ExecuteCommandHasChangeAsync();
if (!isOk)
throw Oops.Oh(ErrorCode.COM1001);
#region
var toUserIds = new List<string>() { entity.ToUserId };
var title = string.Format("{0}向您发起的委托已结束!", entity.UserName);
var parameter = new { type = "2" };
var bodyDic = new Dictionary<string, object>();
bodyDic.Add(entity.ToUserId, parameter);
await _messageService.SentMessage(toUserIds, title, null, bodyDic, 2, "2");
#endregion
}
#endregion
/// <summary>

View File

@@ -1,4 +1,5 @@
using JNPF.Common.Core.Manager;
using JNPF.Common.Const;
using JNPF.Common.Core.Manager;
using JNPF.Common.Core.Manager.Files;
using JNPF.Common.Enums;
using JNPF.Common.Extension;
@@ -225,7 +226,7 @@ public class FlowEngineService : IFlowEngineService, IDynamicApiController, ITra
{
var formTemplateBase = new TemplateParsingBase(entity.FormTemplateJson, entity.Tables, true);
formDataFieldList = formTemplateBase.SingleFormData
.Where(x => x.__config__.jnpfKey != "relationForm" && x.__config__.jnpfKey != "relationFlow")
.Where(x => x.__config__.jnpfKey != JnpfKeyConst.RELATIONFORM && x.__config__.jnpfKey != "relationFlow")
.Select(x => new FlowEngineFieldOutput() { vmodel = x.__vModel__, label = x.__config__.label }).ToList();
}
@@ -543,21 +544,6 @@ public class FlowEngineService : IFlowEngineService, IDynamicApiController, ITra
FormData = entity.FormTemplateJson
};
var res = await _visualDevService.NoTblToTable(devEntity, mTableName);
entity.Tables = res.Tables;
entity.FormTemplateJson = res.FormData;
var entityData = await _runService.GetInfo(entity.Id);
if (entityData != null && entityData.Data != null)
{
var sqlList = _visualDevService.DataToInsertSql(mTableName, entityData.Data);
if (sqlList.Any())
{
var link = await _flowTaskRepository.GetLinkInfo(entity.DbLinkId) ?? _dataBaseManager.GetTenantDbLink(_userManager.TenantId, _userManager.TenantDbName);
foreach (var item in sqlList)
{
await _dataBaseManager.ExecuteSql(link, item);
}
}
}
}
#endregion
}

View File

@@ -7,11 +7,13 @@ using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.Systems.Entitys.Dto.ModuleForm;
using JNPF.Systems.Entitys.Model.DataBase;
using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Entitys.System;
using JNPF.Systems.Interfaces.System;
using JNPF.VisualDev.Engine.Core;
using JNPF.VisualDev.Engine.Model;
using JNPF.VisualDev.Interfaces;
using JNPF.WorkFlow.Entitys.Dto.FlowEngine;
using JNPF.WorkFlow.Entitys.Dto.FlowForm;
@@ -163,6 +165,7 @@ public class FlowFormService : IDynamicApiController, ITransient
entity.EnabledMark = 0;
//entity.TableJson = "[]";
entity.DraftJson = entity.ToJsonString();
entity.LastModifyTime = null;
var result = await _repository.AsSugarClient().Insertable(entity).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
_ = result ?? throw Oops.Oh(ErrorCode.WF0002);
}
@@ -175,19 +178,20 @@ public class FlowFormService : IDynamicApiController, ITransient
[HttpGet("GetFormById/{id}")]
public async Task<dynamic> GetFormById(string id)
{
var entity = await GetInfo(id);
if (entity == null || entity.EnabledMark != 1) throw Oops.Oh(ErrorCode.COM1016);
var tempId = _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().Where(x => x.Id.Equals(entity.FlowId)).Select(x => x.TemplateId).First();
if (tempId == null) throw Oops.Oh(ErrorCode.COM1016);
if (!_repository.AsSugarClient().Queryable<FlowTemplateEntity>().Where(x => x.Id.Equals(tempId) && x.EnabledMark.Equals(1)).Any()) throw Oops.Oh(ErrorCode.COM1017);
var res = await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity, FlowTemplateEntity>((a, b) => new JoinQueryInfos(JoinType.Left, a.TemplateId == b.Id))
.Select((a, b) => new
{
id = SqlFunc.IIF(b.EnabledMark == 0, null, a.Id),
enCode = b.EnCode,
}).MergeTable().FirstAsync(a => a.id.Equals(entity.FlowId));
if (res == null) throw Oops.Oh(ErrorCode.COM1016);
return res;
var model = new { id = string.Empty, enCode = string.Empty, enabledMark = 0 };
var form = await GetInfo(id);
if (form == null) throw Oops.Oh(ErrorCode.COM1019);
if (form != null && form.FlowId.IsNotEmptyOrNull())
model = _repository.AsSugarClient().Queryable<FlowTemplateEntity>().Where(x => x.Id.Equals(form.FlowId)).Select(x => new { id = x.Id, enCode = x.EnCode, enabledMark = (int)x.EnabledMark }).First();
if (model == null || model.id.IsNullOrEmpty()) throw Oops.Oh(ErrorCode.COM1016);
if (form.FlowType == 1 && form.FormType == 1 && model.enabledMark != 1)
{
// 代码生成的功能流程需要判断流程是否启用。
throw Oops.Oh(ErrorCode.COM1017);
}
return model;
}
#endregion
@@ -372,6 +376,7 @@ public class FlowFormService : IDynamicApiController, ITransient
Id = entity.Id,
State = 1,
WebType = 3,
EnableFlow = 1,
FullName = entity.FullName,
EnCode = entity.EnCode,
FormData = entity.PropertyJson
@@ -387,6 +392,22 @@ public class FlowFormService : IDynamicApiController, ITransient
}
var dbLink = await _runService.GetDbLink(newEntity.DbLinkId);
var MainTable = newEntity.TableJson.ToList<TableModel>().Find(m => m.typeId.Equals("1")); // 主表
if (MainTable != null)
{
if (!_dataBaseManager.IsAnyColumn(dbLink, MainTable?.table, "f_flowtaskid"))
{
var pFieldList = new List<DbTableFieldModel>() { new DbTableFieldModel() { field = "F_FlowTaskId", fieldName = "流程任务Id", dataType = "varchar", dataLength = "50", allowNull = 1 } };
_dataBaseManager.AddTableColumn(dbLink, MainTable?.table, pFieldList);
}
if (!_dataBaseManager.IsAnyColumn(dbLink, MainTable?.table, "f_flowid"))
{
var pFieldList = new List<DbTableFieldModel>() { new DbTableFieldModel() { field = "F_FlowId", fieldName = "流程引擎Id", dataType = "varchar", dataLength = "50", allowNull = 1 } };
_dataBaseManager.AddTableColumn(dbLink, MainTable?.table, pFieldList);
}
}
entity.DraftJson = entity.ToJsonString();
entity.EnabledMark = 1;
var isOk = await _repository.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).CallEntityMethod(x => x.LastModify()).ExecuteCommandHasChangeAsync();

View File

@@ -54,6 +54,7 @@ public class FlowLaunchService : IDynamicApiController, ITransient
var entity = _flowTaskRepository.GetTaskFirstOrDefault(id);
if (entity == null)
throw Oops.Oh(ErrorCode.COM1005);
if (entity.Suspend == 1) throw Oops.Oh(ErrorCode.WF0046);
if (!entity.ParentId.Equals("0") && entity.ParentId.IsNotEmptyOrNull())
throw Oops.Oh(ErrorCode.WF0003, entity.FullName);
if (entity.FlowType == 1)
@@ -75,6 +76,8 @@ public class FlowLaunchService : IDynamicApiController, ITransient
public async Task Revoke(string id, [FromBody] FlowHandleModel flowHandleModel)
{
var flowTaskParamter = await _flowTaskRepository.GetTaskParamterByTaskId(id, flowHandleModel);
if (flowTaskParamter.flowTaskEntity.Suspend == 1) throw Oops.Oh(ErrorCode.WF0046);
if (await _flowTaskRepository.AnyFlowTask(x => flowTaskParamter.flowTaskEntity.Id == x.ParentId && x.DeleteMark == null && x.Suspend == 1)) throw Oops.Oh(ErrorCode.WF0046);
if (flowTaskParamter.flowTaskEntity.Status != 1)
throw Oops.Oh(ErrorCode.WF0011);
if (flowTaskParamter.flowTaskEntity.ParentId.IsNotEmptyOrNull()&& !flowTaskParamter.flowTaskEntity.ParentId.Equals("0"))
@@ -91,6 +94,7 @@ public class FlowLaunchService : IDynamicApiController, ITransient
public async Task Press(string id)
{
var flowTaskParamter = await _flowTaskRepository.GetTaskParamterByTaskId(id, null);
if (flowTaskParamter.flowTaskEntity.Suspend == 1) throw Oops.Oh(ErrorCode.WF0046);
await _flowTaskManager.Press(flowTaskParamter);
}
#endregion

View File

@@ -51,6 +51,10 @@ public class FlowMonitorService : IDynamicApiController, ITransient
if (tsakList.Any()) throw Oops.Oh(ErrorCode.WF0012, tsakList.FirstOrDefault().FullName);
tsakList = await _flowTaskRepository.GetTaskList(x => ids.Contains(x.Id) && !x.ParentId.Equals("0") && !SqlFunc.IsNullOrEmpty(x.ParentId));
if (tsakList.Any()) throw Oops.Oh(ErrorCode.WF0003, tsakList.FirstOrDefault().FullName);
tsakList = await _flowTaskRepository.GetTaskList(x => ids.Contains(x.Id) && x.Suspend == 1);
if (tsakList.Any()) throw Oops.Oh(ErrorCode.WF0047, tsakList.FirstOrDefault().FullName);
tsakList = await _flowTaskRepository.GetTaskList(x => ids.Contains(x.ParentId) && x.DeleteMark == null && x.Suspend == 1);
if (tsakList.Any()) throw Oops.Oh(ErrorCode.WF0047, tsakList.FirstOrDefault().FullName);
foreach (var item in input.ids.Split(","))
{
var entity = _flowTaskRepository.GetTaskFirstOrDefault(item);

View File

@@ -13,6 +13,7 @@ using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Entitys.System;
using JNPF.Systems.Interfaces.Permission;
using JNPF.Systems.Interfaces.System;
using JNPF.VisualDev.Entitys;
using JNPF.WorkFlow.Entitys.Dto.FlowTemplate;
using JNPF.WorkFlow.Entitys.Entity;
using JNPF.WorkFlow.Entitys.Model;
@@ -36,7 +37,6 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
private readonly ISqlSugarRepository<FlowTemplateEntity> _repository;
private readonly IFlowTaskRepository _flowTaskRepository;
private readonly IDictionaryDataService _dictionaryDataService;
private readonly IUserRelationService _userRelationService;
private readonly IUserManager _userManager;
private readonly IFileManager _fileManager;
private readonly ITenant _db;
@@ -45,7 +45,6 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
ISqlSugarRepository<FlowTemplateEntity> repository,
IFlowTaskRepository flowTaskRepository,
IDictionaryDataService dictionaryDataService,
IUserRelationService userRelationService,
IUserManager userManager,
IFileManager fileManager,
ISqlSugarClient context)
@@ -53,7 +52,6 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
_repository = repository;
_flowTaskRepository = flowTaskRepository;
_dictionaryDataService = dictionaryDataService;
_userRelationService = userRelationService;
_userManager = userManager;
_fileManager = fileManager;
_db = context.AsTenant();
@@ -70,12 +68,12 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
public async Task<dynamic> GetList([FromQuery] FlowTemplateListQuery input)
{
var objList = _flowTaskRepository.GetCurrentUserObjId();
var list = await _repository.AsSugarClient().Queryable<FlowTemplateEntity, FlowTemplateJsonEntity, FlowEngineVisibleEntity>((a, b, c) => new JoinQueryInfos(JoinType.Left, a.Id == b.TemplateId, JoinType.Left, a.Id == c.FlowId))
.Where((a, b) => a.DeleteMark == null && b.DeleteMark == null && b.EnabledMark == 1)
.WhereIF(_userManager.User.IsAdministrator == 0, (a, b, c) => a.CreatorUserId == _userManager.UserId || (objList.Contains(c.OperatorId) && c.Type == "2"))
var list = await _repository.AsSugarClient().Queryable<FlowTemplateEntity, FlowEngineVisibleEntity>((a, b) => new JoinQueryInfos(JoinType.Left, a.Id == b.FlowId))
.Where(a => a.DeleteMark == null)
.WhereIF(_userManager.User.IsAdministrator == 0, (a, b) => a.CreatorUserId == _userManager.UserId || (objList.Contains(b.OperatorId) && b.Type == "2"))
.WhereIF(input.category.IsNotEmptyOrNull(), a => a.Category == input.category)
.WhereIF(input.keyword.IsNotEmptyOrNull(), a => a.FullName.Contains(input.keyword) || a.EnCode.Contains(input.keyword))
.Select((a, b) => new FlowTemplateListOutput
.Select(a => new FlowTemplateListOutput
{
category = SqlFunc.Subqueryable<DictionaryDataEntity>().Where(d => d.Id == a.Category).Select(d => d.FullName),
id = a.Id,
@@ -90,8 +88,6 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
lastModifyUser = SqlFunc.Subqueryable<UserEntity>().Where(u => u.Id == a.LastModifyUserId).Select(u => SqlFunc.MergeString(u.RealName, "/", u.Account)),
sortCode = a.SortCode,
type = a.Type,
visibleType = b.VisibleType,
version = b.Version,
hasAssistBtn = SqlFunc.IIF((_userManager.UserId == a.CreatorUserId || _userManager.User.IsAdministrator == 1), 1, 0),
}).Distinct().MergeTable().OrderBy(a => a.sortCode).OrderBy(a => a.creatorTime, OrderByType.Desc)
.OrderByIF(!string.IsNullOrEmpty(input.keyword), t => t.lastModifyTime, OrderByType.Desc).ToPagedListAsync(input.currentPage, input.pageSize);
@@ -105,11 +101,25 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
[HttpGet("ListAll")]
public async Task<dynamic> GetListAll()
{
var list1 = await GetFlowFormList(0);
foreach (var item in list1)
{
item.id = item.templateId;
}
//var list1 = await GetFlowFormList(0);
var list1 = await _repository.AsSugarClient().Queryable<FlowTemplateEntity>()
.Where(a => a.DeleteMark == null && a.EnabledMark == 1)
.Select(a => new FlowTemplateTreeOutput
{
id = a.Id,
creatorTime = a.CreatorTime,
enCode = a.EnCode,
enabledMark = a.EnabledMark,
fullName = a.FullName,
icon = a.Icon,
iconBackground = a.IconBackground,
lastModifyTime = a.LastModifyTime,
sortCode = a.SortCode,
parentId = a.Category,
category = a.Category,
type = a.Type,
}).Distinct().MergeTable().OrderBy(a => a.sortCode).OrderBy(a => a.creatorTime, OrderByType.Desc)
.OrderBy(t => t.lastModifyTime, OrderByType.Desc).ToListAsync();
if (list1.Any())
{
var dicDataInfo = await _dictionaryDataService.GetInfo(list1.FirstOrDefault().parentId);
@@ -143,22 +153,41 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
[HttpGet("PageListAll")]
public async Task<dynamic> GetListPageAll([FromQuery] FlowTemplateListQuery input)
{
var data = await GetFlowFormList(input.flowType.ParseToInt());
if (input.category.IsNotEmptyOrNull())
data = data.FindAll(x => x.category == input.category);
if (input.keyword.IsNotEmptyOrNull())
data = data.FindAll(o => o.fullName.Contains(input.keyword) || o.enCode.Contains(input.keyword));
var pageList = new SqlSugarPagedList<FlowTemplateTreeOutput>()
{
list = data.Skip((input.currentPage - 1) * input.pageSize).Take(input.pageSize).ToList(),
pagination = new Pagination()
//var data = await GetFlowFormList(input.flowType.ParseToInt());
//if (input.category.IsNotEmptyOrNull())
// data = data.FindAll(x => x.category == input.category);
//if (input.keyword.IsNotEmptyOrNull())
// data = data.FindAll(o => o.fullName.Contains(input.keyword) || o.enCode.Contains(input.keyword));
//var pageList = new SqlSugarPagedList<FlowTemplateTreeOutput>()
//{
// list = data.Skip((input.currentPage - 1) * input.pageSize).Take(input.pageSize).ToList(),
// pagination = new Pagination()
// {
// PageIndex = input.currentPage,
// PageSize = input.pageSize,
// Total = data.Count
// }
//};
//return PageResult<FlowTemplateTreeOutput>.SqlSugarPageResult(pageList);
var list = await _repository.AsSugarClient().Queryable<FlowTemplateEntity>()
.Where(a => a.DeleteMark == null && a.Type == 0 && a.EnabledMark == 1)
.WhereIF(input.category.IsNotEmptyOrNull(), a => a.Category == input.category)
.WhereIF(input.keyword.IsNotEmptyOrNull(), a => a.FullName.Contains(input.keyword) || a.EnCode.Contains(input.keyword))
.Select(a => new FlowTemplateListOutput
{
CurrentPage = input.currentPage,
PageSize = input.pageSize,
Total = data.Count
}
};
return PageResult<FlowTemplateTreeOutput>.SqlSugarPageResult(pageList);
id = a.Id,
creatorTime = a.CreatorTime,
enCode = a.EnCode,
enabledMark = a.EnabledMark,
fullName = a.FullName,
icon = a.Icon,
iconBackground = a.IconBackground,
lastModifyTime = a.LastModifyTime,
sortCode = a.SortCode,
type = a.Type,
}).Distinct().MergeTable().OrderBy(a => a.sortCode).OrderBy(a => a.creatorTime, OrderByType.Desc)
.OrderByIF(!string.IsNullOrEmpty(input.keyword), t => t.lastModifyTime, OrderByType.Desc).ToPagedListAsync(input.currentPage, input.pageSize);
return PageResult<FlowTemplateListOutput>.SqlSugarPageResult(list);
}
/// <summary>
@@ -169,8 +198,23 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
[HttpGet("{id}/FlowJsonList")]
public async Task<dynamic> GetFlowJsonList(string id, [FromQuery] FlowTemplateListQuery input)
{
var flowJosnEntity = await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().FirstAsync(x => x.Id == input.flowId && x.DeleteMark == null);
if (flowJosnEntity.IsNullOrEmpty())
{
var pageList = new SqlSugarPagedList<FlowTemplateJsonInfoOutput>()
{
list = new List<FlowTemplateJsonInfoOutput>(),
pagination = new Pagination()
{
CurrentPage = input.currentPage,
PageSize = input.pageSize,
Total = 0
}
};
return PageResult<FlowTemplateJsonInfoOutput>.SqlSugarPageResult(pageList);
}
var whereLambda = LinqExpression.And<FlowTemplateJsonEntity>();
whereLambda = whereLambda.And(x => x.DeleteMark == null && x.TemplateId == id);
whereLambda = whereLambda.And(x => x.DeleteMark == null && x.TemplateId == flowJosnEntity.TemplateId && x.FullName == flowJosnEntity.FullName);
var start = new DateTime();
var end = new DateTime();
if (input.endTime != null && input.startTime != null)
@@ -188,13 +232,14 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
.Select((a) => new FlowTemplateJsonInfoOutput
{
id = a.Id,
fullName = a.FullName,
version = a.Version,
enabledMark = a.EnabledMark,
creatorUser = SqlFunc.Subqueryable<UserEntity>().Where(u => u.Id == a.CreatorUserId).Select(u => SqlFunc.MergeString(u.RealName, "/", u.Account)),
creatorTime = a.CreatorTime,
lastModifyTime = a.LastModifyTime,
flowTemplateJson = a.FlowTemplateJson,
}).MergeTable().OrderBy(a => a.creatorTime, OrderByType.Desc)
}).MergeTable().OrderBy(a => a.enabledMark, OrderByType.Desc).OrderBy(a => a.creatorTime, OrderByType.Desc)
.OrderByIF(!string.IsNullOrEmpty(input.keyword), t => t.lastModifyTime, OrderByType.Desc).ToPagedListAsync(input.currentPage, input.pageSize);
return PageResult<FlowTemplateJsonInfoOutput>.SqlSugarPageResult(list);
}
@@ -207,8 +252,32 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
[HttpGet("{id}")]
public async Task<dynamic> GetInfo(string id)
{
//var output = (await _repository.GetFirstAsync(x => x.Id == id && x.DeleteMark == null)).Adapt<FlowTemplateInfoOutput>();
//output.onlineDev = _repository.AsSugarClient().Queryable<VisualDevEntity>().Any(x => x.Id == id && x.DeleteMark == null);
//var flowJsonList = await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().Where(x => x.TemplateId == id && x.EnabledMark == 1 && x.DeleteMark == null).Select(x => new { id = x.Id, flowId = x.Id, fullName = x.FullName, flowTemplateJson = x.FlowTemplateJson }).ToListAsync();
//output.flowTemplateJson = flowJsonList.ToJsonString();
//return output;
var output = (await _repository.GetFirstAsync(x => x.Id == id && x.DeleteMark == null)).Adapt<FlowTemplateInfoOutput>();
output.flowTemplateJson = _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().First(x => x.TemplateId == id && x.EnabledMark == 1 && x.DeleteMark == null)?.FlowTemplateJson;
var flowFormEntity = _repository.AsSugarClient().Queryable<FlowFormEntity>().First(x => x.FlowId == id && x.FlowType == 1 && x.FormType == 2 && x.DeleteMark == null);
if (flowFormEntity.IsNotEmptyOrNull())
{
output.onlineDev = true;
output.onlineFormId = flowFormEntity.Id;
}
var flowJsonList = new List<FlowJsonInfo>();
var flowTemplateJsonEntityList = await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().Where(x => x.TemplateId == id && x.EnabledMark == 1 && x.DeleteMark == null).OrderBy(x => x.SortCode).ToListAsync();
foreach (var item in flowTemplateJsonEntityList)
{
var flowJosn = new FlowJsonInfo();
flowJosn.id = item.Id;
flowJosn.flowId = item.Id;
flowJosn.fullName = item.FullName;
var flowIds = _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().Where(x => x.GroupId == item.GroupId && x.DeleteMark == null).Select(x => x.Id).ToList();
flowJosn.isDelete = await _flowTaskRepository.AnyFlowTask(x => x.DeleteMark == null && flowIds.Contains(x.FlowId));
flowJosn.flowTemplateJson = item.FlowTemplateJson?.ToObject<FlowTemplateJsonModel>();
flowJsonList.Add(flowJosn);
}
output.flowTemplateJson = flowJsonList.ToJsonString();
return output;
}
@@ -245,6 +314,29 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
return new { list = output };
}
/// <summary>
/// 列表(子流程选择流程).
/// </summary>
/// <param name="type">(预留字段).</param>
/// <returns></returns>
[HttpGet("PageChildListAll")]
public async Task<dynamic> PageChildListAll([FromQuery] FlowTemplateListQuery input)
{
var list = await _repository.AsSugarClient().Queryable<FlowTemplateEntity, FlowTemplateJsonEntity>((a, b) => new JoinQueryInfos(JoinType.Right, a.Id == b.TemplateId))
.Where((a, b) => a.DeleteMark == null && a.EnabledMark == 1 && a.Type == input.flowType && b.DeleteMark == null && b.EnabledMark == 1)
.WhereIF(input.keyword.IsNotEmptyOrNull(), (a, b) => b.FullName.Contains(input.keyword))
.Select((a, b) => new FlowTemplateTreeOutput
{
id = b.Id,
fullName = b.FullName,
creatorTime = a.CreatorTime,
lastModifyTime = a.LastModifyTime,
sortCode = a.SortCode,
}).MergeTable().OrderBy(a => a.sortCode).OrderBy(a => a.creatorTime, OrderByType.Desc)
.OrderBy(a => a.lastModifyTime, OrderByType.Desc).ToPagedListAsync(input.currentPage, input.pageSize);
return PageResult<FlowTemplateTreeOutput>.SqlSugarPageResult(list);
}
/// <summary>
/// 导出.
/// </summary>
@@ -255,8 +347,9 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
{
var importModel = new FlowTemplateImportOutput();
importModel.flowTemplate = await _repository.GetFirstAsync(x => x.Id == id && x.DeleteMark == null);
importModel.flowTemplateJson = await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().FirstAsync(x => x.TemplateId == id && x.EnabledMark == 1 && x.DeleteMark == null);
importModel.visibleList = await _repository.AsSugarClient().Queryable<FlowEngineVisibleEntity>().Where(x => x.FlowId == importModel.flowTemplateJson.Id).ToListAsync();
importModel.flowTemplateJson = await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().Where(x => x.TemplateId == id && x.EnabledMark == 1 && x.DeleteMark == null).ToListAsync();
var flowJsonIds = importModel.flowTemplateJson.Select(x => x.Id).ToList();
importModel.visibleList = await _repository.AsSugarClient().Queryable<FlowEngineVisibleEntity>().Where(x => flowJsonIds.Contains(x.FlowId)).ToListAsync();
var jsonStr = importModel.ToJsonString();
return await _fileManager.Export(jsonStr, importModel.flowTemplate.FullName, ExportFileType.ffe);
}
@@ -333,9 +426,34 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
{
var entity = await _repository.GetFirstAsync(x => x.EnCode == code && x.DeleteMark == null);
if (entity == null) Oops.Oh(ErrorCode.COM1005);
var jsonEntity = await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().FirstAsync(x => x.TemplateId == entity.Id && x.EnabledMark == 1 && x.DeleteMark == null);
if (jsonEntity == null) Oops.Oh(ErrorCode.COM1005);
return jsonEntity.Id;
return entity.Id;
}
/// <summary>
/// 发起流程列表(下拉).
/// </summary>
/// <returns></returns>
[HttpGet("FlowJsonList/{teplateId}")]
public async Task<dynamic> GetFlowJsonList(string teplateId, string type)
{
var flowJsonList = (await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().Where(x => x.TemplateId == teplateId && x.EnabledMark == 1 && x.DeleteMark == null).OrderBy(x => x.SortCode).ToListAsync()).Adapt<List<FlowTemplateJsonInfoOutput>>();
if (!flowJsonList.Any()) throw Oops.Oh(ErrorCode.COM1016);
if (!_userManager.IsAdministrator && type == "1")
{
// 判断当前用户是否有发起权限
foreach (var item in flowJsonList.FindAll(x => x.visibleType == 1))
{
// 指定发起人.
var visibleUserList = await _repository.AsSugarClient().Queryable<FlowEngineVisibleEntity, UserRelationEntity>((a, b) => new JoinQueryInfos(JoinType.Left, a.OperatorId == b.ObjectId || a.OperatorId == b.UserId))
.Where((a, b) => a.FlowId == item.id && a.Type == "1").Select((a, b) => b.UserId).Distinct().ToListAsync();
if (!visibleUserList.Contains(_userManager.UserId))
{
flowJsonList.Remove(item);
}
}
}
if (!flowJsonList.Any()) throw Oops.Oh(ErrorCode.WF0049);
return flowJsonList;
}
#endregion
@@ -355,11 +473,13 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
var flowTemplateJsonIdList = await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().Where(x => x.TemplateId == id).Select(x => x.Id).ToListAsync();
if (await _flowTaskRepository.AnyFlowTask(x => x.DeleteMark == null && flowTemplateJsonIdList.Contains(x.FlowId)))
throw Oops.Oh(ErrorCode.WF0037);
if (await _repository.AsSugarClient().Queryable<FlowFormEntity>().AnyAsync(x => x.FlowId == id))
throw Oops.Oh(ErrorCode.WF0052);
_db.BeginTran();
await _repository.AsSugarClient().Deleteable<FlowEngineVisibleEntity>(a => flowTemplateJsonIdList.Contains(a.FlowId)).ExecuteCommandHasChangeAsync();
await _repository.AsSugarClient().Deleteable<FlowFormRelationEntity>(a => flowTemplateJsonIdList.Contains(a.FlowId)).ExecuteCommandHasChangeAsync();
await _repository.AsSugarClient().Deleteable<FlowTemplateJsonEntity>(a => flowTemplateJsonIdList.Contains(a.Id)).ExecuteCommandHasChangeAsync();
await _repository.AsSugarClient().Updateable<FlowFormEntity>().SetColumns(x => x.FlowId == null).Where(x => flowTemplateJsonIdList.Contains(x.FlowId)).ExecuteCommandAsync();
await _repository.AsSugarClient().Deleteable<FlowFormRelationEntity>(a => a.FlowId == id).ExecuteCommandHasChangeAsync();
await _repository.AsSugarClient().Updateable<FlowFormEntity>().SetColumns(x => x.FlowId == null).Where(x => x.FlowId == id).ExecuteCommandAsync();
var isOk = await _repository.AsUpdateable(flowTemplateEntity).CallEntityMethod(m => m.Delete()).UpdateColumns(it => new { it.DeleteMark, it.DeleteTime, it.DeleteUserId }).ExecuteCommandHasChangeAsync();
_db.CommitTran();
if (!isOk)
@@ -393,7 +513,7 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
if (await _repository.IsAnyAsync(x => x.Id != id && (x.EnCode == input.enCode || x.FullName == input.fullName) && x.DeleteMark == null))
throw Oops.Oh(ErrorCode.COM1004);
var flowTemplateEntity = input.Adapt<FlowTemplateEntity>();
var result = await Update(flowTemplateEntity, input.flowTemplateJson);
var result = await Update(flowTemplateEntity, input.flowTemplateJson, input.onlineFormId);
if (result.IsNullOrEmpty())
throw Oops.Oh(ErrorCode.COM1001);
return result;
@@ -410,13 +530,24 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
var entity = await _repository.GetFirstAsync(x => x.Id == id && x.DeleteMark == null);
if (entity == null)
throw Oops.Oh(ErrorCode.COM1005);
var flowTemplateJsonEntity = await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().FirstAsync(x => x.TemplateId == id && x.EnabledMark == 1 && x.DeleteMark == null);
var random = RandomExtensions.NextLetterAndNumberString(new Random(), 5).ToLower();
entity.FullName = string.Format("{0}副本{1}", entity.FullName, random);
entity.EnCode = string.Format("{0}{1}", entity.EnCode, random);
if (entity.FullName.Length >= 50 || entity.EnCode.Length >= 50)
throw Oops.Oh(ErrorCode.COM1009);
var result = await Create(entity, flowTemplateJsonEntity.FlowTemplateJson);
var flowJsonList = new List<FlowJsonInfo>();
var flowTemplateJsonEntityList = await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().Where(x => x.TemplateId == id && x.EnabledMark == 1 && x.DeleteMark == null).ToListAsync();
foreach (var item in flowTemplateJsonEntityList)
{
var flowJosn = new FlowJsonInfo();
flowJosn.id = item.Id;
flowJosn.flowId = item.Id;
flowJosn.fullName = item.FullName;
flowJosn.isDelete = await _flowTaskRepository.AnyFlowTask(x => x.DeleteMark == null && x.FlowId == item.Id);
flowJosn.flowTemplateJson = item.FlowTemplateJson?.ToObject<FlowTemplateJsonModel>();
flowJsonList.Add(flowJosn);
}
var result = await Create(entity, flowJsonList.ToJsonString());
_ = result ?? throw Oops.Oh(ErrorCode.WF0002);
}
@@ -494,11 +625,24 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
[HttpPost("{id}/MainVersion")]
public async Task MainVersion(string id)
{
var jsonInfo = await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().FirstAsync(x => x.Id == id && x.DeleteMark == null);
await _repository.AsSugarClient().Updateable<FlowTemplateJsonEntity>().SetColumns(it => it.EnabledMark == 0).Where(it => it.Id != id && it.TemplateId == jsonInfo.TemplateId).ExecuteCommandHasChangeAsync();
var isOk = await _repository.AsSugarClient().Updateable<FlowTemplateJsonEntity>().SetColumns(it => it.EnabledMark == 1).Where(it => it.Id == id && it.TemplateId == jsonInfo.TemplateId).ExecuteCommandHasChangeAsync();
if (!isOk)
throw Oops.Oh(ErrorCode.COM1003);
foreach (var item in id.Split(","))
{
var jsonInfo = await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().FirstAsync(x => x.Id == item && x.DeleteMark == null);
await _repository.AsSugarClient().Updateable<FlowTemplateJsonEntity>().SetColumns(it => new FlowTemplateJsonEntity()
{
EnabledMark = 0,
LastModifyUserId = _userManager.UserId,
LastModifyTime = SqlFunc.GetDate()
}).Where(it => it.EnabledMark == 1 && it.TemplateId == jsonInfo.TemplateId && it.FullName == jsonInfo.FullName).ExecuteCommandHasChangeAsync();
var isOk = await _repository.AsSugarClient().Updateable<FlowTemplateJsonEntity>().SetColumns(it => new FlowTemplateJsonEntity()
{
EnabledMark = 1,
LastModifyUserId = _userManager.UserId,
LastModifyTime = SqlFunc.GetDate()
}).Where(it => it.Id == item && it.TemplateId == jsonInfo.TemplateId && it.FullName == jsonInfo.FullName).ExecuteCommandHasChangeAsync();
if (!isOk)
throw Oops.Oh(ErrorCode.COM1003);
}
}
/// <summary>
@@ -511,9 +655,11 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
{
if (await _flowTaskRepository.AnyFlowTask(x => x.DeleteMark == null && x.FlowId == id))
throw Oops.Oh(ErrorCode.WF0037);
var jsonInfo = await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().FirstAsync(x => x.Id == id && x.DeleteMark == null);
var launchFormIdList = new List<string>();
GetFormIdList(jsonInfo.FlowTemplateJson.ToObject<FlowTemplateJsonModel>(), launchFormIdList);
await _repository.AsSugarClient().Deleteable<FlowFormRelationEntity>(a => a.FlowId == id && launchFormIdList.Contains(a.FormId)).ExecuteCommandHasChangeAsync();
var isOk = await _repository.AsSugarClient().Updateable<FlowTemplateJsonEntity>().SetColumns(it => new FlowTemplateJsonEntity() { DeleteMark = 1, DeleteTime = SqlFunc.GetDate(), DeleteUserId = _userManager.UserId }).Where(it => it.Id == id).ExecuteCommandHasChangeAsync();
await _repository.AsSugarClient().Deleteable<FlowFormRelationEntity>(a => a.FlowId == id).ExecuteCommandHasChangeAsync();
await _repository.AsSugarClient().Updateable<FlowFormEntity>().SetColumns(x => x.FlowId == null).Where(x => x.FlowId==id).ExecuteCommandAsync();
if (!isOk)
throw Oops.Oh(ErrorCode.COM1003);
}
@@ -597,46 +743,65 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
_db.BeginTran();
var formIdList = new List<string>();
entity.Id = SnowflakeIdHelper.NextId();
entity.EnabledMark = entity.EnabledMark == null ? 0 : entity.EnabledMark;
var flowTemplateJsonEntity = new FlowTemplateJsonEntity();
flowTemplateJsonEntity.Id = SnowflakeIdHelper.NextId();
flowTemplateJsonEntity.TemplateId = entity.Id;
flowTemplateJsonEntity.Version = "1";
flowTemplateJsonEntity.FlowTemplateJson = flowTemplateJson;
entity.EnabledMark = 0;
if (flowTemplateJson.IsNotEmptyOrNull())
{
var visibleList = GetFlowEngineVisibleList(flowTemplateJson);
flowTemplateJsonEntity.VisibleType = visibleList.Count == 0 ? 0 : 1;
foreach (var item in visibleList)
var index = 0;
foreach (var item in flowTemplateJson.ToObject<List<FlowJsonInfo>>())
{
item.FlowId = flowTemplateJsonEntity.Id;
item.SortCode = visibleList.IndexOf(item);
item.Type = "1";
}
if (visibleList.Count > 0)
await _repository.AsSugarClient().Insertable(visibleList).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
#region
GetFormIdList(flowTemplateJson.ToObject<FlowTemplateJsonModel>(), formIdList);
foreach (var item in formIdList)
{
var formRelationEntity = new FlowFormRelationEntity
var flowTemplateJsonEntity = new FlowTemplateJsonEntity();
flowTemplateJsonEntity.Id = SnowflakeIdHelper.NextId();
flowTemplateJsonEntity.TemplateId = entity.Id;
flowTemplateJsonEntity.Version = "1";
flowTemplateJsonEntity.FlowTemplateJson = item.flowTemplateJson.ToJsonString();
flowTemplateJsonEntity.FullName = item.fullName;
flowTemplateJsonEntity.SortCode = index++;
flowTemplateJsonEntity.GroupId = SnowflakeIdHelper.NextId();
var visibleList = GetFlowEngineVisibleList(item.flowTemplateJson.ToJsonString());
flowTemplateJsonEntity.VisibleType = visibleList.Count == 0 ? 0 : 1;
foreach (var visible in visibleList)
{
Id = SnowflakeIdHelper.NextId(),
FlowId = flowTemplateJsonEntity.Id,
FormId = item
};
await _repository.AsSugarClient().Insertable(formRelationEntity).ExecuteReturnEntityAsync();
visible.FlowId = flowTemplateJsonEntity.Id;
visible.SortCode = visibleList.IndexOf(visible);
visible.Type = "1";
}
if (visibleList.Count > 0)
await _repository.AsSugarClient().Insertable(visibleList).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
await _repository.AsSugarClient().Insertable(flowTemplateJsonEntity).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
#region
if (entity.Type == 1)
{
var formId = item.flowTemplateJson.properties.ToObject<StartProperties>()?.formId;
if (formIdList.Any() && !formIdList.Contains(formId))
{
throw Oops.Oh(ErrorCode.WF0043);
}
else
{
formIdList.Add(formId);
}
if (await _repository.AsSugarClient().Queryable<FlowFormEntity>().AnyAsync(x => x.Id == formId && x.FlowId != entity.Id && !SqlFunc.IsNullOrEmpty(x.FlowId)))
throw Oops.Oh(ErrorCode.WF0043);
await _repository.AsSugarClient().Updateable<FlowFormEntity>().SetColumns(x => x.FlowId == entity.Id).Where(x => x.Id == formId).ExecuteCommandAsync();
}
else
{
var launchFormIdList = new List<string>();
GetFormIdList(item.flowTemplateJson, launchFormIdList);
foreach (var launchFormId in launchFormIdList)
{
var formRelationEntity = new FlowFormRelationEntity
{
Id = SnowflakeIdHelper.NextId(),
FlowId = entity.Id,
FormId = launchFormId
};
await _repository.AsSugarClient().Insertable(formRelationEntity).ExecuteReturnEntityAsync();
}
}
#endregion
}
if (entity.Type == 1)
{
if (await _repository.AsSugarClient().Queryable<FlowFormEntity>().AnyAsync(x => x.Id == formIdList.FirstOrDefault() && !SqlFunc.IsNullOrEmpty(x.FlowId)))
throw Oops.Oh(ErrorCode.WF0043);
await _repository.AsSugarClient().Updateable<FlowFormEntity>().SetColumns(x => x.FlowId == flowTemplateJsonEntity.Id).Where(x => x.Id == formIdList.FirstOrDefault()).ExecuteCommandAsync();
}
#endregion
}
await _repository.AsSugarClient().Insertable(flowTemplateJsonEntity).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
var result = await _repository.AsSugarClient().Insertable(entity).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
if (result == null)
throw Oops.Oh(ErrorCode.COM1005);
@@ -657,75 +822,134 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
/// <param name="visibleList">可见范围.</param>
/// <returns></returns>
[NonAction]
private async Task<object> Update(FlowTemplateEntity entity, string flowTemplateJson)
private async Task<object> Update(FlowTemplateEntity entity, string flowTemplateJson, string onlineFormId)
{
try
{
_db.BeginTran();
var flag = false;
var isMainVersionId = new List<string>();
var formIdList = new List<string>();
var flowTemplateJsonEntity = await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().FirstAsync(x => x.TemplateId == entity.Id && x.DeleteMark == null && x.EnabledMark == 1);
if (flowTemplateJsonEntity.FlowTemplateJson.IsNotEmptyOrNull())
{
// 清空就模板关联表单数据
string oldFormId = flowTemplateJsonEntity.FlowTemplateJson.ToObject<FlowTemplateJsonModel>().properties.ToObject<StartProperties>().formId;
await _repository.AsSugarClient().Updateable<FlowFormEntity>().SetColumns(x => x.FlowId == null).Where(x => x.Id == oldFormId).ExecuteCommandAsync();
await _repository.AsSugarClient().Deleteable<FlowFormRelationEntity>().Where(x => x.FlowId == flowTemplateJsonEntity.Id).ExecuteCommandAsync();
}
var isCreate = flowTemplateJsonEntity.FlowTemplateJson.Equals(flowTemplateJson);//流程json是否变更
flowTemplateJsonEntity.FlowTemplateJson = flowTemplateJson;
var groupIdList = new List<string>(); // 未删除的分组id.
if (flowTemplateJson.IsNotEmptyOrNull())
{
var visibleList = GetFlowEngineVisibleList(flowTemplateJson);
flowTemplateJsonEntity.VisibleType = visibleList.Count == 0 ? 0 : 1;
if ((await _flowTaskRepository.AnyFlowTask(x => x.DeleteMark == null && x.FlowId == flowTemplateJsonEntity.Id)) && !isCreate)
var index = 0;
foreach (var item in flowTemplateJson.ToObject<List<FlowJsonInfo>>())
{
flag = true;
flowTemplateJsonEntity.Version = ((await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().Where(x => x.TemplateId == entity.Id).Select(x => SqlFunc.AggregateMax(SqlFunc.ToInt64(x.Version))).FirstAsync()).ParseToInt() + 1).ToString();
flowTemplateJsonEntity.Id = SnowflakeIdHelper.NextId();
flowTemplateJsonEntity.EnabledMark = 0;
await _repository.AsSugarClient().Insertable(flowTemplateJsonEntity).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
}
else
{
await _repository.AsSugarClient().Updateable(flowTemplateJsonEntity).IgnoreColumns(ignoreAllNullColumns: true).CallEntityMethod(m => m.LastModify()).ExecuteCommandHasChangeAsync();
await _repository.AsSugarClient().Deleteable<FlowEngineVisibleEntity>(a => a.FlowId == flowTemplateJsonEntity.Id).ExecuteCommandHasChangeAsync();
}
foreach (var item in visibleList)
{
item.FlowId = flowTemplateJsonEntity.Id;
item.SortCode = visibleList.IndexOf(item);
item.Type = "1";
}
if (visibleList.Count > 0)
await _repository.AsSugarClient().Insertable(visibleList).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
GetFormIdList(flowTemplateJson.ToObject<FlowTemplateJsonModel>(), formIdList);
foreach (var item in formIdList)
{
var formRelationEntity = new FlowFormRelationEntity
var flowTemplateJsonEntity = await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().FirstAsync(x => x.Id == item.id && x.DeleteMark == null);
var visibleList = GetFlowEngineVisibleList(item.flowTemplateJson.ToJsonString());
if (flowTemplateJsonEntity.IsNullOrEmpty())
{
Id = SnowflakeIdHelper.NextId(),
FlowId = flowTemplateJsonEntity.Id,
FormId = item
};
await _repository.AsSugarClient().Insertable(formRelationEntity).ExecuteReturnEntityAsync();
}
if (entity.Type == 1)
{
if (await _repository.AsSugarClient().Queryable<FlowFormEntity>().AnyAsync(x => x.Id == formIdList.FirstOrDefault() && !SqlFunc.IsNullOrEmpty(x.FlowId)))
throw Oops.Oh(ErrorCode.WF0043);
await _repository.AsSugarClient().Updateable<FlowFormEntity>().SetColumns(x => x.FlowId == flowTemplateJsonEntity.Id).Where(x => x.Id == formIdList.FirstOrDefault()).ExecuteCommandAsync();
flowTemplateJsonEntity = new FlowTemplateJsonEntity();
flowTemplateJsonEntity.Id = SnowflakeIdHelper.NextId();
flowTemplateJsonEntity.TemplateId = entity.Id;
flowTemplateJsonEntity.Version = "1";
flowTemplateJsonEntity.FlowTemplateJson = item.flowTemplateJson.ToJsonString();
flowTemplateJsonEntity.FullName = item.fullName;
flowTemplateJsonEntity.SortCode = index++;
flowTemplateJsonEntity.VisibleType = visibleList.Count == 0 ? 0 : 1;
flowTemplateJsonEntity.GroupId = SnowflakeIdHelper.NextId();
foreach (var visible in visibleList)
{
visible.FlowId = flowTemplateJsonEntity.Id;
visible.SortCode = visibleList.IndexOf(visible);
visible.Type = "1";
}
if (visibleList.Count > 0)
await _repository.AsSugarClient().Insertable(visibleList).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
await _repository.AsSugarClient().Insertable(flowTemplateJsonEntity).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
groupIdList.Add(flowTemplateJsonEntity.GroupId);
}
else
{
// 清空就模板关联表单数据
if (entity.Type == 1)
{
string oldFormId = flowTemplateJsonEntity.FlowTemplateJson.ToObject<FlowTemplateJsonModel>().properties.ToObject<StartProperties>().formId;
await _repository.AsSugarClient().Updateable<FlowFormEntity>().SetColumns(x => x.FlowId == null).Where(x => x.Id == oldFormId).ExecuteCommandAsync();
}
else
{
await _repository.AsSugarClient().Deleteable<FlowFormRelationEntity>().Where(x => x.FlowId == entity.Id).ExecuteCommandAsync();
}
if (!groupIdList.Contains(flowTemplateJsonEntity.GroupId))
{
groupIdList.Add(flowTemplateJsonEntity.GroupId);
}
var isCreate = flowTemplateJsonEntity.FlowTemplateJson.Equals(item.flowTemplateJson.ToJsonString());//流程json是否变更
flowTemplateJsonEntity.FlowTemplateJson = item.flowTemplateJson.ToJsonString();
flowTemplateJsonEntity.SortCode = index++;
flowTemplateJsonEntity.FullName = item.fullName;
flowTemplateJsonEntity.VisibleType = visibleList.Count == 0 ? 0 : 1;
if ((await _flowTaskRepository.AnyFlowTask(x => x.DeleteMark == null && x.FlowId == flowTemplateJsonEntity.Id)) && !isCreate)
{
flag = true;
await _repository.AsSugarClient().Updateable(flowTemplateJsonEntity).UpdateColumns(it => new { it.FullName, it.SortCode }).ExecuteCommandHasChangeAsync();
flowTemplateJsonEntity.Version = ((await _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().Where(x => x.TemplateId == entity.Id && x.FullName == item.fullName).Select(x => SqlFunc.AggregateMax(SqlFunc.ToInt64(x.Version))).FirstAsync()).ParseToInt() + 1).ToString();
flowTemplateJsonEntity.Id = SnowflakeIdHelper.NextId();
flowTemplateJsonEntity.EnabledMark = 0;
flowTemplateJsonEntity.LastModifyTime = null;
flowTemplateJsonEntity.LastModifyUserId = null;
await _repository.AsSugarClient().Insertable(flowTemplateJsonEntity).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
isMainVersionId.Add(flowTemplateJsonEntity.Id);
}
else
{
await _repository.AsSugarClient().Updateable(flowTemplateJsonEntity).IgnoreColumns(ignoreAllNullColumns: true).CallEntityMethod(m => m.LastModify()).ExecuteCommandHasChangeAsync();
await _repository.AsSugarClient().Deleteable<FlowEngineVisibleEntity>(a => a.FlowId == flowTemplateJsonEntity.Id).ExecuteCommandHasChangeAsync();
}
}
foreach (var visible in visibleList)
{
visible.FlowId = flowTemplateJsonEntity.Id;
visible.SortCode = visibleList.IndexOf(visible);
visible.Type = "1";
}
if (visibleList.Count > 0)
await _repository.AsSugarClient().Insertable(visibleList).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
if (entity.Type == 1)
{
var formId = item.flowTemplateJson.properties.ToObject<StartProperties>()?.formId;
if (formIdList.Any() && !formIdList.Contains(formId))
{
throw Oops.Oh(ErrorCode.WF0043);
}
else
{
formIdList.Add(formId);
}
if ((await _repository.AsSugarClient().Queryable<FlowFormEntity>().AnyAsync(x => x.Id == formId && x.FlowId != entity.Id && !SqlFunc.IsNullOrEmpty(x.FlowId))) && formId != onlineFormId)
throw Oops.Oh(ErrorCode.WF0043);
await _repository.AsSugarClient().Updateable<FlowFormEntity>().SetColumns(x => x.FlowId == entity.Id).Where(x => x.Id == formId).ExecuteCommandAsync();
}
else
{
// 发起流程表单id
var launchFormIdList = new List<string>();
GetFormIdList(item.flowTemplateJson, launchFormIdList);
foreach (var launchFormId in launchFormIdList)
{
var formRelationEntity = new FlowFormRelationEntity
{
Id = SnowflakeIdHelper.NextId(),
FlowId = entity.Id,
FormId = launchFormId
};
await _repository.AsSugarClient().Insertable(formRelationEntity).ExecuteReturnEntityAsync();
}
}
}
// 删除未使用的流程
await _repository.AsSugarClient().Deleteable<FlowTemplateJsonEntity>().Where(x => x.TemplateId == entity.Id && !groupIdList.Contains(x.GroupId)).ExecuteCommandAsync();
}
var isOk = await _repository.AsSugarClient().Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).CallEntityMethod(m => m.LastModify()).ExecuteCommandHasChangeAsync();
_db.CommitTran();
return new { isMainVersion = flag, id = flowTemplateJsonEntity.Id };
return new { isMainVersion = flag, id = string.Join(",", isMainVersionId) };
}
catch (AppFriendlyException ex)
catch (Exception ex)
{
_db.RollbackTran();
throw Oops.Oh(ex.ErrorCode);
return null;
}
}
@@ -818,7 +1042,7 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
.Select((a, b) => new FlowTemplateTreeOutput
{
category = a.Category,
id = b.Id,
id = a.Id,
description = a.Description,
creatorTime = a.CreatorTime,
creatorUser = SqlFunc.Subqueryable<UserEntity>().Where(u => u.Id == a.CreatorUserId).Select(u => SqlFunc.MergeString(u.RealName, "/", u.Account)),
@@ -871,7 +1095,7 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
/// <param name="formIdList"></param>
private void GetFormIdList(FlowTemplateJsonModel template, List<string> formIdList)
{
if (template.IsNotEmptyOrNull()&&!template.type.Equals("subFlow"))
if (template.IsNotEmptyOrNull() && !template.type.Equals("subFlow") && !template.type.Equals("timer"))
{
if (template.properties["formId"].ToString().IsNotEmptyOrNull())
{
@@ -884,4 +1108,4 @@ public class FlowTemplateService : IFlowTemplateService, IDynamicApiController,
}
}
#endregion
}
}