bklLiudl
2025-04-07 4e8f58cb41c7b6d570fd1979d80f74ab8a4d00c2
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Model.ModelDto.SysDto;
using WMS.Entity.SysEntity;
using WMS.IBLL.ISysServer;
using WMS.IDAL.ISysInterface;
using System.Security.Cryptography;
using OracleInternal.Secure.Network;
using Utility.Tools;
using System.Linq;
 
namespace WMS.BLL.SysServer
{
    public class UserInforServer : IUserInforServer
    {
        public IUserInforRepository UserSvc { get; set; }
        readonly IMapper _mapper;
        private readonly IFunSettingServer _setting;
        public UserInforServer(IUserInforRepository userSvc, IMapper mapper, IFunSettingServer setting)
        {
            UserSvc = userSvc;
            _mapper = mapper;
            _setting = setting;
        }
 
        public bool LoginAdmin(string loginName, string loginPwd, out int adminId)
        {
            //loginPwd = Md5Tools.CalcMd5(loginPwd);
            var date = UserSvc.GetAllAsync().First(m => m.UserName == loginName && m.PassWord == loginPwd);
            
            if (date != null) //账号密码是否正确
            {
                if (date.Status == "0") //当前账号是否正常启用
                {
                    //最后登陆时间
                    UserSvc.UptUserLoginTime(date.Id);
                    adminId = date.Id;
                    return true;
                }
                else //当前账号被禁用
                {
                    adminId = 0;
                    return true;
                }
            }
            else //账号密码不正确或没有此账号
            {
                adminId = 0;
                return false;
            }
        }
        public SysUserInfor CeShi()
        {
            var date = UserSvc.ceshi();
 
            return date;
 
        }
 
        /// <summary>
        /// 获取用户角色信息
        /// </summary>
        /// <returns></returns>
        public List<UserInfoDto> GetUserRoleList(string UserName, string DepartmentNo, string RoleNo, string Status)
        {
 
            string str = "select user1.Id Id,user1.UserNo UserNo,user1.UserName UserName,user1.RealName RealName,user1.PassWord PassWord,user1.JobNo JobNo,user1.Status Status,user1.Sex Sex,user1.Nationality Nationality,user1.CreateTime CreateTime,user1.CreateUser CreateUser,user1.Paper Paper,user1.Phone Phone,user1.Email Email,user1.Addres Addres,user1.Demo Demo,role.RoleName,user2.RealName CreateUserName,depa.DepartmentName DepartmentName from SysUserInfor user1 left join SysRoles role on user1.RoleNo = role.RoleNo left join SysUserInfor user2 on user1.CreateUser = user2.Id left join SysDepartment depa on user1.DepartmentNo = depa.DepartmentNo where user1.IsDel = '0'";
 
            //判断登录名称是否为空
            if (!string.IsNullOrEmpty(UserName))
            {
                str += $" and user1.UserName like '%{UserName}%'";
            }
            //判断部门号是否为0
            if (!string.IsNullOrEmpty(DepartmentNo))
            {
                str += $" and user1.DepartmentNo = '{DepartmentNo}'";
            }
            //判断角色号是否为空
            if (!string.IsNullOrEmpty(RoleNo))
            {
                str += $" and user1.RoleNo = '{RoleNo}'";
            }
            //判断状态是否为空
            if (!string.IsNullOrEmpty(Status))
            {
                str += $" and user1.Status = '{Status}'";
            }
 
            List<UserInfoDto> userInfoDtos = UserSvc.GetUserRoleList(str);
 
            //var arr = Md5Tools.CalcMd5(userInfoDtos[3].PassWord);
 
            return userInfoDtos;
        }
 
        /// <summary>
        /// 根据编号获取用户信息列表
        /// </summary>
        /// <param name="UserNo">用户编号</param>
        /// <param name="userName">用户登录名</param>
        /// <param name="id">用户ID</param>
        /// <returns></returns>
        public int GetUserInfoByNo(string userNo, string userName,int id)
        {
            string str = $"select * from SysUserInfor where IsDel=0 and (UserNo = '{userNo}' or UserName = '{userName}') ";
            if (id!=0)
            {
                str += $"and Id != {id} ";
            }
            List<SysUserInfor> user = UserSvc.GetUserInfoByNo(str);
            return user.Count;
        }
 
        /// <summary>
        /// 新增用户信息
        /// </summary>
        /// <param name="UserInfoDto">用户视图模型</param>
        /// <returns></returns>
        /// <exception cref="Exception">异常</exception>
        public async Task<int> InsertUserInfo(UserInfoDto UserInfoDto)
        {
            //异常
            try
            {
                //数据模型映射
                SysUserInfor userinfo = _mapper.Map<SysUserInfor>(UserInfoDto);
                //判断用户号是否唯一
                int count = GetUserInfoByNo(userinfo.UserNo,userinfo.UserName,0);
                int i = 0;
                if (count > 0)
                {
                    i = 3;
                }
                else if (count ==0)
                {
                    //新增用户
                    i = await UserSvc.InsertUserInfo(userinfo);
                }
                return i;
            }
            catch (Exception ex)
            {
                //抛出异常
                throw new Exception("新增用户信息异常", ex);
            }
 
        }
 
        /// <summary>
        /// 删除用户信息
        /// </summary>
        /// <param name="user">用户实体模型</param>
        /// <returns></returns>
        /// <exception cref="Exception">异常</exception>
        public async Task<int> DeleteUserinfo(SysUserInfor user)
        {
            //异常
            try
            {
                //删除
                int i = await UserSvc.DeleteUserinfo(user);
                //返回数据
                return i;
            }
            catch (Exception ex)
            {
                //抛出异常
                throw new Exception("删除用户信息异常", ex);
            }
        }
 
        /// <summary>
        /// 编辑用户信息
        /// </summary>
        /// <param name="userdto">用户Dto</param>
        /// <returns></returns>
        /// <exception cref="Exception">异常exception>
        public async Task<int> UpdateUserinfo(UserInfoDto userdto)
        {
            //异常
            try
            {
                //映射数据模型
                SysUserInfor userlist = _mapper.Map<SysUserInfor>(userdto);
                //判断用户号是否唯一
                int count = GetUserInfoByNo(userdto.UserNo, userdto.UserName,userdto.Id);
                int i = 0;
                if (count > 0)
                {
                    i = 3;
                }
                else if (count == 0)
                {
                    //编辑
                    i = await UserSvc.UpdateUserinfo(userlist);
                }
               
                return i;
            }
            catch (Exception ex)
            {
                //抛出异常
                throw new Exception("编辑用户信息异常", ex);
            }
        }
 
        /// <summary>
        /// 根据id获取用户信息列表
        /// </summary>
        /// <param name="userids">用户id</param>
        /// <returns></returns>
        public SysUserInfor GetUserInfoById(int userids)
        {
            //获取信息列表
            SysUserInfor user= UserSvc.GetUserInfoById(userids);
            //返回数据
            return user;
        }
 
        /// <summary>
        /// 修改用户密码
        /// </summary>
        /// <param name="pwdOld">原密码</param>
        /// <param name="pwdNew">新密码</param>
        /// <param name="pwdNewTwo">确认密码</param>
        /// <param name="userId">用户id</param>
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        public async Task<int> UptUserPassWord(string pwdOld, string pwdNew, string pwdNewTwo, int userId)
        {
            //捕获异常
            try
            {
                //验证两次新密码是否一致
                if (pwdNew == pwdNewTwo)
                {
                    int i = await UserSvc.UptUserPassWord(pwdOld, pwdNew, pwdNewTwo, userId);
                    return i;
                }
                else
                {
                    return 3;
                }
            }
            catch (Exception ex)
            {
                //抛出异常
                throw new Exception("修改密码异常",ex);
            }
        }
        /// <summary>
        /// x天后提醒用户修改密码
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public int IsPassWordTime(int userId)
        {
            //捕获异常
            try
            {
                SysFunSetting funSettings = _setting.GetFunSettingByNo("Fun026");
                if (funSettings != null && funSettings.IsEnable == "NO")
                {
                    SysUserInfor userinfo = UserSvc.GetAllAsync().First(m => m.Id == userId);
                    if (userinfo.SetPasswordTime != null)
                    {
                        int days = string.IsNullOrEmpty(funSettings.SetValue) ? 30 : Convert.ToInt32(funSettings.SetValue);
                        bool isTime = userinfo.SetPasswordTime.Value.AddDays(days) < DateTime.Now;
                        if (isTime)
                        {
                            return 1;
                        }
                    }
                }
                return 0;
            }
            catch (Exception ex)
            {
                //抛出异常
                throw new Exception("修改密码异常", ex);
            }
        }
    }
}