94 lines
3.2 KiB
C#
94 lines
3.2 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Routing;
|
|
using Syc.Basic.Web.Dtos.Menu;
|
|
using Syc.Basic.Web.WMS;
|
|
|
|
//using Syc.Basic.Web.Contracts;
|
|
using Syc.Basic.Web.WMS.Dtos.Menu;
|
|
using Syc.Basic.Web.WMS.Entitys;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp.Domain.Repositories;
|
|
|
|
namespace Syc.Basic.Web.Service
|
|
{
|
|
/// <summary>
|
|
/// 菜单服务
|
|
/// </summary>
|
|
public class MenuService : ApiService
|
|
{
|
|
private readonly IRepository<Menu> menuRepository;
|
|
private readonly IRepository<Role> roleRepository;
|
|
|
|
public MenuService(IRepository<Menu> menuRepository, IRepository<Role> roleRepository)
|
|
{
|
|
this.menuRepository = menuRepository;
|
|
this.roleRepository = roleRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取菜单列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<object> GetListAsync()
|
|
{
|
|
var list = await menuRepository.GetListAsync();
|
|
var result = ObjectMapper.Map(list, new List<MenuPlainInfoListDto>());
|
|
return new
|
|
{
|
|
Data = result,
|
|
total = result.Count,
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除菜单
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task Del(DelMenuInput input)
|
|
{
|
|
var menu = await menuRepository.FirstOrDefaultAsync(e => e.Id == input.Id);
|
|
if (menu is null)
|
|
throw Oops.Oh("菜单不存在或已被删除");
|
|
await menuRepository.DeleteAsync(menu);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public async Task Add(UpdateMenuInput input)
|
|
{
|
|
if (await menuRepository.AnyAsync(e => e.Name == input.name.Trim()))
|
|
throw Oops.Oh($"{input.name}已存在");
|
|
if (!input.permissionCode.IsNullOrWhiteSpace())
|
|
{
|
|
if (await menuRepository.AnyAsync(e => e.PermissionCode == input.permissionCode.Trim()))
|
|
throw Oops.Oh("权限标识已存在,请勿重复定义");
|
|
}
|
|
var admins = await roleRepository.GetListAsync(e => e.Code == ConstPool.AdministratorRoleCode);
|
|
var menu = ObjectMapper.Map(input, new Menu());
|
|
menu.Roles.AddRange(admins);
|
|
await menuRepository.InsertAsync(menu);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编辑
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public async Task Edit(UpdateMenuInput input)
|
|
{
|
|
if (await menuRepository.AnyAsync(e => e.Name == input.name.Trim() && e.Id != input.id))
|
|
throw Oops.Oh($"{input.name}已存在");
|
|
|
|
//var menu = await menuRepository.FirstOrDefaultAsync(e => e.Id == input.id);
|
|
var newMenu = ObjectMapper.Map(input, new Menu());
|
|
await menuRepository.UpdateAsync(newMenu);
|
|
}
|
|
}
|
|
} |