From 4073bcc6e43f8f72945da396915f32d9d986967c Mon Sep 17 00:00:00 2001 From: yanjinhui <3306209981@qq.com> Date: 星期三, 26 三月 2025 10:15:51 +0800 Subject: [PATCH] 11 --- 项目代码/WIDESEAWCS_Server 正式/WIDESEAWCS_SystemServices/Sys_UserService.cs | 149 +++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 137 insertions(+), 12 deletions(-) diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server \346\255\243\345\274\217/WIDESEAWCS_SystemServices/Sys_UserService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server \346\255\243\345\274\217/WIDESEAWCS_SystemServices/Sys_UserService.cs" index 8871a36..55c3023 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server \346\255\243\345\274\217/WIDESEAWCS_SystemServices/Sys_UserService.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server \346\255\243\345\274\217/WIDESEAWCS_SystemServices/Sys_UserService.cs" @@ -12,6 +12,11 @@ using System.Net; using WIDESEAWCS_Core.Caches; using WIDESEA_ISerialPortRepository; +using Microsoft.AspNetCore.Http; +using SqlSugar; +using ICacheService = WIDESEAWCS_Core.Caches.ICacheService; +using Microsoft.AspNetCore.Builder; +using WIDESEAWCS_DTO.SerialPort; namespace WIDESEAWCS_SystemServices { @@ -25,13 +30,13 @@ private readonly IPutakeRepository _putakeRepository; public Sys_UserService(ISys_UserRepository repository, IUnitOfWorkManage unitOfWorkManage, - ICacheService cacheService, ISys_MenuService menuService , ISys_RoleRepository roleRepository, ILoginHistoryRepository loginHistoryRepository, IPutakeRepository putakeRepository) : base(repository) + ICacheService cacheService, ISys_MenuService menuService, ISys_RoleRepository roleRepository, ILoginHistoryRepository loginHistoryRepository, IPutakeRepository putakeRepository) : base(repository) { _unitOfWorkManage = unitOfWorkManage; _cacheService = cacheService; _menuService = menuService; _RoleRepository = roleRepository; - _RoleRepository= roleRepository; + _RoleRepository = roleRepository; _loginHistoryRepository = loginHistoryRepository; _putakeRepository = putakeRepository; } @@ -69,7 +74,7 @@ { return WebResponseContent.Instance.Error("鏃犵櫥褰曟潈闄�"); } - if (disbled.Enable!=1) + if (disbled.Enable != 1) { return WebResponseContent.Instance.Error("浣犵殑璐﹀彿宸茶绂佺敤锛岃鑱旂郴绠$悊鍛�"); } @@ -84,18 +89,16 @@ var loghis = new Dt_LoginHistory { Account = user.UserName, - TrurName=user.UserTrueName, - CreateDate=DateTime.Now - - + TrurName = user.UserTrueName, + CreateDate = DateTime.Now }; - + _cacheService.AddOrUpdate(user.UserId.ToString(), token); _loginHistoryRepository.AddData(loghis); - content = WebResponseContent.Instance.OK(data: new { token, userName = user.UserTrueName, img = user.HeadImageUrl,ID=user.UserId }); + content = WebResponseContent.Instance.OK(data: new { token, userName = user.UserTrueName, img = user.HeadImageUrl, ID = user.UserId, RoleId=user.RoleId }); } else { @@ -180,6 +183,7 @@ if (newPwd.Length < 6) return WebResponseContent.Instance.Error("瀵嗙爜涓嶈兘灏戜簬6浣�"); int userId = App.User.UserId; + string userCurrentPwd = BaseDal.QueryFirst(x => x.User_Id == userId, s => s.UserPwd); string _oldPwd = oldPwd.EncryptDES(AppSecret.User); @@ -199,8 +203,8 @@ nameof(Sys_User.LastModifyPwdDate), nameof(Sys_User.UserPwd) }); - - content = WebResponseContent.Instance.OK("瀵嗙爜淇敼鎴愬姛"); + //content = WebResponseContent.Instance.OK("瀵嗙爜淇敼鎴愬姛"); + content = WebResponseContent.Instance.OK("瀵嗙爜淇敼鎴愬姛", userId); } catch (Exception ex) { @@ -208,6 +212,7 @@ content = WebResponseContent.Instance.Error("鏈嶅姟鍣ㄤ簡鐐归棶棰�,璇风◢鍚庡啀璇�"); } return content; + } public WebResponseContent GetUerType() @@ -236,7 +241,7 @@ { - return new WebResponseContent { Status = false, Message="澶辫触"+ex }; + return new WebResponseContent { Status = false, Message = "澶辫触" + ex }; } } @@ -292,5 +297,125 @@ } } + + /// <summary> + /// 鍥剧墖鏂囦欢鍚� + /// </summary> + /// <param name="files"></param> + /// <returns></returns> + public WebResponseContent SaveFiles(IFormCollection files) + { + if (files == null || files.Files.Count == 0) + return new WebResponseContent { Status = false, Message = "璇蜂笂浼犳枃浠�" }; + + // 1. 纭繚瀛樺偍鐩綍瀛樺湪 + string baseDirectory = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "image"); + if (!Directory.Exists(baseDirectory)) + Directory.CreateDirectory(baseDirectory); + + try + { + var file = files.Files[0]; // 鍙鐞嗙涓�涓枃浠� + string fileName = file.FileName; // 鐩存帴浣跨敤鍓嶇鐨勬枃浠跺悕 + + string fullFilePath = Path.Combine(baseDirectory, fileName); + + // 2. 淇濆瓨鏂囦欢锛堝鏋滃瓨鍦紝鍒欒鐩栵級 + using (var stream = new FileStream(fullFilePath, FileMode.Create)) + { + file.CopyTo(stream); + } + + // 3. 杩斿洖鏂囦欢鍚� + return new WebResponseContent { Status = true, Message = "鏂囦欢涓婁紶鎴愬姛", Data = fileName }; + } + catch (Exception ex) + { + return new WebResponseContent { Status = false, Message = "涓婁紶鏂囦欢澶辫触锛�" + ex.Message }; + } + } + + /// <summary> + /// 鏇存柊瀵嗙爜 + /// </summary> + /// <param name="id"></param> + /// <param name="oldPwd"></param> + /// <param name="newPwd"></param> + /// <returns></returns> + public WebResponseContent UpdatePwd(int id, string oldPwd, string newPwd) + { + WebResponseContent content = new WebResponseContent(); + oldPwd = oldPwd?.Trim(); + newPwd = newPwd?.Trim(); + + try + { + if (string.IsNullOrEmpty(oldPwd)) return content.Error("鏃у瘑鐮佷笉鑳戒负绌�"); + if (string.IsNullOrEmpty(newPwd)) return content.Error("鏂板瘑鐮佷笉鑳戒负绌�"); + if (newPwd.Length < 6) return content.Error("瀵嗙爜涓嶈兘灏戜簬6浣�"); + + // 鑾峰彇鐢ㄦ埛褰撳墠瀵嗙爜 + string userCurrentPwd = BaseDal.QueryFirst(x => x.User_Id == id, s => s.UserPwd) ?? ""; + + if (string.IsNullOrEmpty(userCurrentPwd)) return content.Error("鐢ㄦ埛涓嶅瓨鍦ㄦ垨瀵嗙爜鏈缃�"); + + //// 杩涜瀵嗙爜鍔犲瘑瀵规瘮 + //string _oldPwd = oldPwd.EncryptDES(AppSecret.User); + //if (_oldPwd != userCurrentPwd) return content.Error("鏃у瘑鐮佷笉姝g‘"); + + // 鐢熸垚鏂板瘑鐮佸姞瀵嗗�� + string _newPwd = newPwd.EncryptDES(AppSecret.User); + if (userCurrentPwd == _newPwd) return content.Error("鏂板瘑鐮佷笉鑳戒笌鏃у瘑鐮佺浉鍚�"); + + // 鏇存柊瀵嗙爜 + bool isUpdated = BaseDal.UpdateData(new Sys_User + { + User_Id = id, + UserPwd = _newPwd, + LastModifyPwdDate = DateTime.Now + }, new List<string> + { + nameof(Sys_User.LastModifyPwdDate), + nameof(Sys_User.UserPwd) + }); + + if (!isUpdated) + { + return content.Error("瀵嗙爜淇敼澶辫触锛岃绋嶅悗閲嶈瘯"); + } + + return content.OK("瀵嗙爜淇敼鎴愬姛", id); + } + catch (Exception ex) + { + Console.WriteLine($"淇敼瀵嗙爜寮傚父: {ex.Message}"); + return content.Error($"鏈嶅姟鍣ㄩ敊璇�: {ex.Message}"); + } + } + + public WebResponseContent Upuserbase(UserDTO userDTO) + { + try + { + var user = BaseDal.QueryData(x => x.User_Id == userDTO.id).FirstOrDefault(); + if (user==null) + { + return new WebResponseContent { Status = false, Message = "娌℃壘鍒拌鐢ㄦ埛" }; + } + user.UserTrueName = userDTO.usertruename; + user.PhoneNo = userDTO.phone; + user.HeadImageUrl = userDTO.files; + BaseDal.UpdateData(user); // 纭繚鏇存柊鍒版暟鎹簱 + return new WebResponseContent { Status = true, Data = user }; + } + catch (Exception ex) + { + + return new WebResponseContent { Status = false ,Message="澶辫触锛�"+ex}; + } + + } } } + + -- Gitblit v1.9.3