添加项目文件。

This commit is contained in:
2023-03-13 15:00:34 +08:00
parent 42bf06ca3e
commit 1d73df3235
1205 changed files with 185078 additions and 0 deletions

View File

@@ -0,0 +1,213 @@
using JNPF.Apps.Entitys;
using JNPF.Apps.Entitys.Dto;
using JNPF.Apps.Interfaces;
using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Extension;
using JNPF.Common.Filter;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Entitys.System;
using JNPF.WorkFlow.Entitys.Dto.FlowEngine;
using JNPF.WorkFlow.Entitys.Entity;
using JNPF.WorkFlow.Interfaces.Service;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
namespace JNPF.Apps;
/// <summary>
/// App常用数据
/// 版 本V3.2
/// 版 权拓通智联科技有限公司http://www.tuotong-tech.com
/// 日 期2021-06-01 .
/// </summary>
[ApiDescriptionSettings(Tag = "App", Name = "Data", Order = 800)]
[Route("api/App/[controller]")]
public class AppDataService : IAppDataService, IDynamicApiController, ITransient
{
/// <summary>
/// 服务基础仓储.
/// </summary>
private readonly ISqlSugarRepository<AppDataEntity> _repository; // App常用数据
/// <summary>
/// 用户管理.
/// </summary>
private readonly IUserManager _userManager;
/// <summary>
/// 流程管理.
/// </summary>
private readonly IFlowTemplateService _flowTemplateService;
/// <summary>
/// 构造.
/// </summary>
/// <param name="repository"></param>
/// <param name="userManager"></param>
/// <param name="flowTemplateService"></param>
public AppDataService(
ISqlSugarRepository<AppDataEntity> repository,
IUserManager userManager,
IFlowTemplateService flowTemplateService)
{
_repository = repository;
_userManager = userManager;
_flowTemplateService = flowTemplateService;
}
#region Get
/// <summary>
/// 常用数据.
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
[HttpGet("")]
public async Task<dynamic> GetList([FromQuery] string type)
{
List<AppDataEntity>? list = await GetListByType(type);
List<AppDataListOutput>? output = list.Adapt<List<AppDataListOutput>>();
if (type.Equals("1"))
{
foreach (var item in output)
{
var flowJson = _repository.AsSugarClient().Queryable<FlowTemplateJsonEntity>().First(x => x.TemplateId == item.objectId && x.EnabledMark == 1 && x.DeleteMark == null);
if (flowJson != null)
{
item.objectId = flowJson.Id;
}
}
}
return new { list = output };
}
/// <summary>
/// 所有流程.
/// </summary>
/// <returns></returns>
[HttpGet("getFlowList")]
public async Task<dynamic> GetFlowList([FromQuery] FlowEngineListInput input)
{
var list = await _repository.AsSugarClient().Queryable<FlowTemplateEntity>()
.Where(a => a.DeleteMark == null && a.EnabledMark == 1 && a.Type == 0)
.WhereIF(input.category.IsNotEmptyOrNull(), a => a.Category == input.category)
.WhereIF(input.keyword.IsNotEmptyOrNull(), a => a.FullName.Contains(input.keyword) || a.EnCode.Contains(input.keyword))
.OrderBy(a => a.SortCode).OrderBy(a => a.CreatorTime, OrderByType.Desc)
.OrderBy(a => a.LastModifyTime, OrderByType.Desc)
.Select(a => new AppFlowListAllOutput
{
id = a.Id,
icon = a.Icon,
enCode = a.EnCode,
fullName = a.FullName,
iconBackground = a.IconBackground,
isData = SqlFunc.Subqueryable<AppDataEntity>().Where(x => x.ObjectType == "1" && x.CreatorUserId == _userManager.UserId && x.ObjectId == a.Id && x.DeleteMark == null).Any(),
}).ToPagedListAsync(input.currentPage, input.pageSize);
return PageResult<AppFlowListAllOutput>.SqlSugarPageResult(list);
}
/// <summary>
/// 所有流程.
/// </summary>
/// <returns></returns>
[HttpGet("getDataList")]
public async Task<dynamic> GetDataList(string keyword)
{
List<AppDataListAllOutput>? list = (await GetAppMenuList(keyword)).Adapt<List<AppDataListAllOutput>>();
foreach (AppDataListAllOutput? item in list)
{
item.isData = _repository.IsAny(x => x.ObjectType == "2" && x.CreatorUserId == _userManager.UserId && x.ObjectId == item.id && x.DeleteMark == null);
}
List<AppDataListAllOutput>? output = list.ToTree("-1");
return new { list = output };
}
#endregion
#region Post
/// <summary>
/// 新增.
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("")]
public async Task Create([FromBody] AppDataCrInput input)
{
AppDataEntity? entity = input.Adapt<AppDataEntity>();
int isOk = await _repository.AsInsertable(entity).IgnoreColumns(ignoreNullColumn: true).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync();
if (isOk < 1)
throw Oops.Oh(ErrorCode.COM1000);
}
/// <summary>
/// 删除.
/// </summary>
/// <param name="objectId"></param>
/// <returns></returns>
[HttpDelete("{objectId}")]
public async Task Delete(string objectId)
{
AppDataEntity? entity = await _repository.GetSingleAsync(x => x.ObjectId == objectId && x.CreatorUserId == _userManager.UserId && x.DeleteMark == null);
var isOk = await _repository.AsUpdateable(entity).CallEntityMethod(m => m.Delete()).UpdateColumns(it => new { it.DeleteMark, it.DeleteTime, it.DeleteUserId }).ExecuteCommandHasChangeAsync();
if (!isOk)
throw Oops.Oh(ErrorCode.COM1002);
}
#endregion
#region PrivateMethod
/// <summary>
/// 列表.
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
private async Task<List<AppDataEntity>> GetListByType(string type)
{
return await _repository.AsQueryable().Where(x => x.ObjectType == type && x.CreatorUserId == _userManager.UserId && x.DeleteMark == null).ToListAsync();
}
/// <summary>
/// 菜单列表.
/// </summary>
/// <returns></returns>
[NonAction]
public async Task<List<ModuleEntity>> GetAppMenuList(string keyword)
{
List<ModuleEntity>? menuList = new List<ModuleEntity>();
if (_userManager.IsAdministrator)
{
menuList = await _repository.AsSugarClient().Queryable<ModuleEntity>()
.Where(x => x.EnabledMark == 1 && x.Category == "App" && x.DeleteMark == null && x.SystemId == _userManager.User.SystemId)
.WhereIF(!string.IsNullOrEmpty(keyword), x => x.FullName.Contains(keyword) || x.ParentId == "-1")
.OrderBy(o => o.SortCode)
.ToListAsync();
}
else
{
string[]? objectIds = _userManager.Roles.ToArray();
if (objectIds.Length == 0)
return menuList;
List<string>? ids = await _repository.AsSugarClient().Queryable<AuthorizeEntity>()
.Where(x => objectIds.Contains(x.ObjectId) && x.ObjectType == "Role" && x.ItemType == "module").Select(x => x.ItemId).ToListAsync();
if (ids.Count == 0)
return menuList;
menuList = await _repository.AsSugarClient().Queryable<ModuleEntity>()
.Where(x => ids.Contains(x.Id) && x.EnabledMark == 1 && x.Category == "App" && x.DeleteMark == null && x.SystemId == _userManager.User.SystemId)
.WhereIF(!string.IsNullOrEmpty(keyword), x => x.FullName.Contains(keyword) || x.ParentId == "-1")
.OrderBy(o => o.SortCode)
.ToListAsync();
}
return menuList;
}
#endregion
}