v3.4.6
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user