bklLiudl
2025-04-02 1bbbbc8bb49411b544626996a1370788142300e0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using AutoMapper;
using Model.ModelDto.SysDto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WMS.Entity.SysEntity;
using WMS.IBLL.ISysServer;
using WMS.IDAL.ISysInterface;
 
namespace WMS.BLL.SysServer
{
    /// <summary>
    /// 角色服务实践
    /// </summary>
    public class RolesServer : IRolesServer
    {
        /// <summary>
        /// 依赖注入
        /// </summary>
        public IRolesRepository _roles { get; set; }
        private readonly IMapper _mapper;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="roles">角色</param>
        /// <param name="mapper">automapper</param>
        public RolesServer(IRolesRepository roles,IMapper mapper)
        {
            _roles = roles; //角色
            _mapper = mapper; //automapper
        }
 
        /// <summary>
        /// 获取角色数据列表
        /// </summary>
        /// <param name="RoleNo">角色号</param>
        /// <param name="RoleName">角色名称</param>
        /// <returns></returns>
        public List<RoleDto> GetRoleList(string RoleNo, string RoleName,string UserId)
        {
            //获取角色信息
            List<RoleDto> rolelist = _roles.GetRoleList(RoleNo, RoleName, UserId);
            //返回数据
            return rolelist;
        }
 
        /// <summary>
        /// 根据编号获取角色信息列表
        /// </summary>
        /// <param name="RoleNo">角色编号</param>
        /// <returns></returns>
        public int GetRoleByNo(string RoleNo)
        {
            List<SysRoles> role = _roles.GetRoleByNo(RoleNo);
            return role.Count;
        }
 
        /// <summary>
        /// 新增角色数据信息
        /// </summary>
        /// <param name="roledto">角色dto</param>
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        public async Task<int> InsertRoleInfo(RoleDto roledto)
        {
            //捕获异常
            try
            {
                //模型映射
                SysRoles roles = _mapper.Map<SysRoles>(roledto);
                //判断角色号是否唯一
                int count = GetRoleByNo(roledto.RoleNo);
                int i = 0;
                if (count > 0)
                {
                    i = 3;
                }
                else if (count == 0)
                {
                    //新增角色信息
                    i = await _roles.InsertRoleInfo(roles);
                }
                
                return i;
            }
            catch (Exception ex)
            {
                //抛出异常
                throw new Exception("角色信息新增异常", ex);
            }
        }
 
 
        /// <summary>
        /// 删除角色信息(逻辑删除)
        /// </summary>
        /// <param name="roles">角色实体模型</param>
        /// <returns></returns>
        public async Task<int> DeleteRoleInfo(SysRoles roles)
        {
            int i = await _roles.DeleteRoleInfo(roles);
            return i;
 
        }
 
        /// <summary>
        /// 编辑角色信息
        /// </summary>
        /// <param name="role">角色实体模型</param>
        /// <returns></returns>
        public async Task<int> UpdateRoleInfo(SysRoles role)
        {
            //修改
            int i = await _roles.UpdateRoleInfo(role);
            return i;
 
        }
 
        /// <summary>
        /// 根据id获取角色信息
        /// </summary>
        /// <param name="roleids">角色id</param>
        /// <returns></returns>
        public SysRoles GetRoleInfoById(int roleids)
        {
            SysRoles role= _roles.GetRoleInfoById(roleids);
            return role;
        }
 
    }
}