64 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			64 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			C#
		
	
	
	
| 
								 | 
							
								using langguanApi.Extensions.AutoDI;
							 | 
						|||
| 
								 | 
							
								using langguanApi.Model.Dto.SystemConfigurationDto;
							 | 
						|||
| 
								 | 
							
								using langguanApi.Model;
							 | 
						|||
| 
								 | 
							
								using langguanApi.Model.Entity;
							 | 
						|||
| 
								 | 
							
								using langguanApi.Model.SystemConfigurationEntity;
							 | 
						|||
| 
								 | 
							
								using StackExchange.Redis;
							 | 
						|||
| 
								 | 
							
								using Mapster;
							 | 
						|||
| 
								 | 
							
								using System.Linq.Expressions;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								namespace langguanApi.Service
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    [ServiceInjection(InjectionType.Transient)]
							 | 
						|||
| 
								 | 
							
								    public class RoleService : BaseService<Model.SystemConfigurationEntity.UserRole>
							 | 
						|||
| 
								 | 
							
								    {
							 | 
						|||
| 
								 | 
							
								        public RoleService(IConfiguration config) : base(config, nameof(Role))
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 用户是否存在
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="input"></param>
							 | 
						|||
| 
								 | 
							
								        /// <returns></returns>
							 | 
						|||
| 
								 | 
							
								        public async Task<bool> Exist(RoleDto input)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            var entity = input.Adapt<UserRole>();
							 | 
						|||
| 
								 | 
							
								            Expression<Func<UserRole, bool>> exp = filter => filter.RoleName == entity.RoleName;
							 | 
						|||
| 
								 | 
							
								            return await base.Exist(exp);
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 新加角色
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="input"></param>
							 | 
						|||
| 
								 | 
							
								        /// <returns></returns>
							 | 
						|||
| 
								 | 
							
								        public async Task<ApiResult> AddRole(RoleDto input)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            if (await Exist(input))
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                return new ApiResult { code = 1, msg = $"{input.RoleName}的角色已存在" };
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            var entity = input.Adapt<UserRole>();
							 | 
						|||
| 
								 | 
							
								            if (entity != null)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                await base.CreateAsync(entity);
							 | 
						|||
| 
								 | 
							
								                return new ApiResult { code = 0, msg = "" };
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            return new ApiResult { code = 1, msg = "菜单添加失败" }; ;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 根据Id,获取多个校色信息
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="ids"></param>
							 | 
						|||
| 
								 | 
							
								        /// <returns></returns>
							 | 
						|||
| 
								 | 
							
								        public async Task<List<UserRole>> GetRoleListByIds(IEnumerable<string> ids)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            Expression<Func<UserRole, bool>> exp = filter => ids.Contains(filter.Id) && filter.IsDelete == false;
							 | 
						|||
| 
								 | 
							
								            var list = (await base.GetListWithExp(exp)).ToList();
							 | 
						|||
| 
								 | 
							
								            return list;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 |