init commit
This commit is contained in:
100
20220330_Vote/Ewide.Core/Service/App/Dto/AppInput.cs
Normal file
100
20220330_Vote/Ewide.Core/Service/App/Dto/AppInput.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Ewide.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 系统应用参数
|
||||
/// </summary>
|
||||
public class AppInput : PageInputBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public virtual string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 编码
|
||||
/// </summary>
|
||||
public virtual string Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图标
|
||||
/// </summary>
|
||||
public virtual string Icon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图标颜色
|
||||
/// </summary>
|
||||
public virtual string Color { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否默认激活(Y-是,N-否),只能有一个系统默认激活
|
||||
/// 用户登录后默认展示此系统菜单
|
||||
/// </summary>
|
||||
public bool Active { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态(字典 0正常 1停用 2删除)
|
||||
/// </summary>
|
||||
public CommonStatus Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
public int Sort { get; set; }
|
||||
}
|
||||
|
||||
public class AddAppInput : AppInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "应用名称不能为空")]
|
||||
public override string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 编码
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "应用编码不能为空")]
|
||||
public override string Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图标
|
||||
/// </summary>
|
||||
public override string Icon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图标颜色
|
||||
/// </summary>
|
||||
[RegularExpression("^#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3}$", ErrorMessage = "颜色格式不正确")]
|
||||
public override string Color { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteAppInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用Id
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "应用Id不能为空")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateAppInput : AppInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用Id
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "应用Id不能为空")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public class QueryAppInput : DeleteAppInput
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class SetDefaultAppInput : DeleteAppInput
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
33
20220330_Vote/Ewide.Core/Service/App/Dto/AppOutput.cs
Normal file
33
20220330_Vote/Ewide.Core/Service/App/Dto/AppOutput.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
namespace Ewide.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 系统应用参数
|
||||
/// </summary>
|
||||
public class AppOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用Id
|
||||
/// </summary>
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 编码
|
||||
/// </summary>
|
||||
public string Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否默认
|
||||
/// </summary>
|
||||
public bool Active { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
public int Sort { get; set; }
|
||||
}
|
||||
}
|
||||
18
20220330_Vote/Ewide.Core/Service/App/ISysAppService.cs
Normal file
18
20220330_Vote/Ewide.Core/Service/App/ISysAppService.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core.Service
|
||||
{
|
||||
public interface ISysAppService
|
||||
{
|
||||
Task AddApp(AddAppInput input);
|
||||
Task DeleteApp(DeleteAppInput input);
|
||||
Task<SysApp> GetApp([FromQuery] QueryAppInput input);
|
||||
Task<dynamic> GetAppList([FromQuery] AppInput input);
|
||||
Task<dynamic> GetLoginApps(string userId);
|
||||
Task<dynamic> QueryAppPageList([FromQuery] AppInput input);
|
||||
Task SetAsDefault(SetDefaultAppInput input);
|
||||
Task UpdateApp(UpdateAppInput input);
|
||||
Task ChangeUserAppStatus(UpdateAppInput input);
|
||||
}
|
||||
}
|
||||
204
20220330_Vote/Ewide.Core/Service/App/SysAppService.cs
Normal file
204
20220330_Vote/Ewide.Core/Service/App/SysAppService.cs
Normal file
@@ -0,0 +1,204 @@
|
||||
using Ewide.Core.Extension;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 系统应用服务
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Name = "App", Order = 100)]
|
||||
public class SysAppService : ISysAppService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IRepository<SysApp> _sysAppRep; // 应用表仓储
|
||||
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly ISysMenuService _sysMenuService;
|
||||
|
||||
public SysAppService(IRepository<SysApp> sysAppRep,
|
||||
IUserManager userManager,
|
||||
ISysMenuService sysMenuService)
|
||||
{
|
||||
_sysAppRep = sysAppRep;
|
||||
_userManager = userManager;
|
||||
_sysMenuService = sysMenuService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户应用相关信息
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[NonAction]
|
||||
public async Task<dynamic> GetLoginApps(string userId)
|
||||
{
|
||||
var apps = _sysAppRep.DetachedEntities.Where(u => u.Status == (int)CommonStatus.ENABLE);
|
||||
if (!_userManager.SuperAdmin)
|
||||
{
|
||||
var appCodeList = await _sysMenuService.GetUserMenuAppCodeList(userId);
|
||||
apps = apps.Where(u => appCodeList.Contains(u.Code));
|
||||
}
|
||||
var appList = await apps.OrderBy(u => u.Sort).Select(u => new AppOutput
|
||||
{
|
||||
Id = u.Id,
|
||||
Code = u.Code,
|
||||
Name = u.Name,
|
||||
Active = u.Active,
|
||||
Sort = u.Sort
|
||||
}).ToListAsync(); // .OrderByDescending(u => u.Active) // 将激活的放到第一个
|
||||
|
||||
//// 默认激活第一个应用
|
||||
if (appList != null && appList.Count > 0 && !appList[0].Active)
|
||||
appList[0].Active = true;
|
||||
return appList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询系统应用
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysApp/page")]
|
||||
public async Task<dynamic> QueryAppPageList([FromBody] AppInput input)
|
||||
{
|
||||
var apps = await _sysAppRep.DetachedEntities
|
||||
.Where(
|
||||
!string.IsNullOrEmpty(input.Name?.Trim()),
|
||||
u => EF.Functions.Like(u.Name, $"%{input.Name.Trim()}%")
|
||||
)
|
||||
.Where(
|
||||
!string.IsNullOrEmpty(input.Code?.Trim()),
|
||||
u => EF.Functions.Like(u.Code, $"%{input.Code.Trim()}%")
|
||||
)
|
||||
.ToPageData(input);
|
||||
return PageDataResult<SysApp>.PageResult(apps);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加系统应用
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysApp/add")]
|
||||
public async Task AddApp(AddAppInput input)
|
||||
{
|
||||
var isExist = await _sysAppRep.DetachedEntities.AnyAsync(u => u.Name == input.Name || u.Code == input.Code);
|
||||
if (isExist)
|
||||
throw Oops.Oh(ErrorCode.D5000);
|
||||
|
||||
if (input.Active)
|
||||
{
|
||||
isExist = await _sysAppRep.DetachedEntities.AnyAsync(u => u.Active == input.Active);
|
||||
if (isExist)
|
||||
throw Oops.Oh(ErrorCode.D5001);
|
||||
}
|
||||
|
||||
var app = input.Adapt<SysApp>();
|
||||
await app.InsertAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除系统应用
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysApp/delete")]
|
||||
public async Task DeleteApp(DeleteAppInput input)
|
||||
{
|
||||
var app = await _sysAppRep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
||||
// 该应用下是否有状态为正常的菜单
|
||||
var hasMenu = await _sysMenuService.HasMenu(app.Code);
|
||||
if (hasMenu)
|
||||
throw Oops.Oh(ErrorCode.D5002);
|
||||
|
||||
await app.DeleteAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新系统应用
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysApp/edit")]
|
||||
public async Task UpdateApp(UpdateAppInput input)
|
||||
{
|
||||
var isExist = await _sysAppRep.DetachedEntities.AnyAsync(u => (u.Name == input.Name || u.Code == input.Code) && u.Id != input.Id);
|
||||
if (isExist)
|
||||
throw Oops.Oh(ErrorCode.D5000);
|
||||
|
||||
if (input.Active)
|
||||
{
|
||||
isExist = await _sysAppRep.DetachedEntities.AnyAsync(u => u.Active == input.Active && !u.Id.Equals(input.Id));
|
||||
if (isExist)
|
||||
throw Oops.Oh(ErrorCode.D5001);
|
||||
}
|
||||
|
||||
var app = input.Adapt<SysApp>();
|
||||
await app.UpdateExcludeAsync(new[] { nameof(SysApp.Status) }, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取系统应用
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/sysApp/detail")]
|
||||
public async Task<SysApp> GetApp([FromQuery] QueryAppInput input)
|
||||
{
|
||||
return await _sysAppRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取系统应用列表
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/sysApp/list")]
|
||||
public async Task<dynamic> GetAppList([FromQuery] AppInput input)
|
||||
{
|
||||
return await _sysAppRep.DetachedEntities.Where(u => u.Status == (int)CommonStatus.ENABLE).OrderBy(u => u.Sort).ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设为默认应用
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysApp/setAsDefault")]
|
||||
public async Task SetAsDefault(SetDefaultAppInput input)
|
||||
{
|
||||
var apps = await _sysAppRep.Where(u => u.Status == (int)CommonStatus.ENABLE).ToListAsync();
|
||||
apps.ForEach(u =>
|
||||
{
|
||||
u.Active = false;
|
||||
});
|
||||
|
||||
var app = await _sysAppRep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
||||
app.Active = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户状态
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysApp/changeStatus")]
|
||||
public async Task ChangeUserAppStatus(UpdateAppInput input)
|
||||
{
|
||||
if (!Enum.IsDefined(typeof(CommonStatus), input.Status))
|
||||
throw Oops.Oh(ErrorCode.D3005);
|
||||
|
||||
var app = await _sysAppRep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
||||
app.Status = input.Status;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user