From e789e002de5174c0fa51f78a05bf11f9b4c63345 Mon Sep 17 00:00:00 2001
From: qiuyao <qiuyao@hnkhzn.com>
Date: 星期一, 31 三月 2025 08:44:31 +0800
Subject: [PATCH] 修改websocket的端口
---
项目代码/WIDESEAWCS_Server 正式/WIDESEAWCS_SystemServices/Sys_UserService.cs | 172 +++++++++++++++++++++++++++++++++++++++------------------
1 files changed, 117 insertions(+), 55 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 e82f73f..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"
@@ -16,6 +16,7 @@
using SqlSugar;
using ICacheService = WIDESEAWCS_Core.Caches.ICacheService;
using Microsoft.AspNetCore.Builder;
+using WIDESEAWCS_DTO.SerialPort;
namespace WIDESEAWCS_SystemServices
{
@@ -29,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;
}
@@ -73,7 +74,7 @@
{
return WebResponseContent.Instance.Error("鏃犵櫥褰曟潈闄�");
}
- if (disbled.Enable!=1)
+ if (disbled.Enable != 1)
{
return WebResponseContent.Instance.Error("浣犵殑璐﹀彿宸茶绂佺敤锛岃鑱旂郴绠$悊鍛�");
}
@@ -88,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
{
@@ -184,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);
@@ -204,7 +204,7 @@
nameof(Sys_User.UserPwd)
});
//content = WebResponseContent.Instance.OK("瀵嗙爜淇敼鎴愬姛");
- content = WebResponseContent.Instance.OK("瀵嗙爜淇敼鎴愬姛",userId);
+ content = WebResponseContent.Instance.OK("瀵嗙爜淇敼鎴愬姛", userId);
}
catch (Exception ex)
{
@@ -212,7 +212,7 @@
content = WebResponseContent.Instance.Error("鏈嶅姟鍣ㄤ簡鐐归棶棰�,璇风◢鍚庡啀璇�");
}
return content;
-
+
}
public WebResponseContent GetUerType()
@@ -241,12 +241,12 @@
{
- return new WebResponseContent { Status = false, Message="澶辫触"+ex };
+ return new WebResponseContent { Status = false, Message = "澶辫触" + ex };
}
}
- public WebResponseContent PermissionView(int userId, string group)
+ public WebResponseContent PermissionView(int userId, string group)
{
try
{
@@ -298,62 +298,124 @@
}
-
- public WebResponseContent UploaDavatar(List<IFormFile> files, int userId)
+ /// <summary>
+ /// 鍥剧墖鏂囦欢鍚�
+ /// </summary>
+ /// <param name="files"></param>
+ /// <returns></returns>
+ public WebResponseContent SaveFiles(IFormCollection files)
{
- if (files == null || files.Count == 0)
+ if (files == null || files.Files.Count == 0)
return new WebResponseContent { Status = false, Message = "璇蜂笂浼犳枃浠�" };
- // 1. 鎸囧畾鍥哄畾鐨勫瓨鍌ㄧ洰褰�
- //string baseDirectory = @"E:\缇庡瀷\NiuJuKongZhi\椤圭洰浠g爜\WIDESEAWCS_Server 姝e紡\WIDESEAWCS_Server\wwwroot\image\";
- string baseDirectory = @"wwwroot\image\";
-
- // 2. 鐢熸垚瀛愮洰褰曪紝閬垮厤鏂囦欢鍐茬獊
- string subDirectory = $"{DateTime.Now:yyMMddHHmmss}_{new Random().Next(1000, 9999)}";
- string filePath = Path.Combine(baseDirectory, subDirectory);
-
- //3. 纭繚鐩綍瀛樺湪
- if (!Directory.Exists(filePath))
- Directory.CreateDirectory(filePath);
+ // 1. 纭繚瀛樺偍鐩綍瀛樺湪
+ string baseDirectory = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "image");
+ if (!Directory.Exists(baseDirectory))
+ Directory.CreateDirectory(baseDirectory);
try
{
- string uploadedFilePath = "";
- for (int i = 0; i < files.Count; i++)
+ var file = files.Files[0]; // 鍙鐞嗙涓�涓枃浠�
+ string fileName = file.FileName; // 鐩存帴浣跨敤鍓嶇鐨勬枃浠跺悕
+
+ string fullFilePath = Path.Combine(baseDirectory, fileName);
+
+ // 2. 淇濆瓨鏂囦欢锛堝鏋滃瓨鍦紝鍒欒鐩栵級
+ using (var stream = new FileStream(fullFilePath, FileMode.Create))
{
- // 4. 鐢熸垚鍞竴鏂囦欢鍚嶏紙闃叉閲嶅悕瑕嗙洊锛�
- string fileName = $"{Guid.NewGuid()}{Path.GetExtension(files[i].FileName)}";
- string fullFilePath = Path.Combine(filePath, fileName);
-
- // 5. 淇濆瓨鏂囦欢鍒版寚瀹氳矾寰�
- using (var stream = new FileStream(fullFilePath, FileMode.Create))
- {
- files[i].CopyTo(stream);
- }
-
- // 6. 璁板綍鏂囦欢璺緞锛堝瓨鍏ユ暟鎹簱鐨勭浉瀵硅矾寰勶級
- uploadedFilePath = Path.Combine("/image", subDirectory, fileName).Replace("\\", "/");
- break; // 鍙鐞嗙涓�涓枃浠�
+ file.CopyTo(stream);
}
- //7. 鏇存柊鐢ㄦ埛澶村儚璺緞鍒版暟鎹簱
- var user = BaseDal.QueryData(u => u.User_Id == userId).FirstOrDefault();
- if (user != null)
- {
- user.HeadImageUrl = uploadedFilePath;
- UpdateData(user);
- }
- else
- {
- return new WebResponseContent { Status = false, Message = "鐢ㄦ埛涓嶅瓨鍦�" };
- }
-
- return new WebResponseContent { Status = true, Message = "鏂囦欢涓婁紶鎴愬姛", Data = uploadedFilePath };
+ // 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