From 4d9d8d22e3666076988c30afb4e7c6fe365c19aa Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期二, 06 一月 2026 18:53:04 +0800
Subject: [PATCH] 1.修复一个回复错误的问题;

---
 SourceCode/Bond/Servo/CUserManager2.cpp |  156 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 153 insertions(+), 3 deletions(-)

diff --git a/SourceCode/Bond/Servo/CUserManager2.cpp b/SourceCode/Bond/Servo/CUserManager2.cpp
index e06165f..402b2f6 100644
--- a/SourceCode/Bond/Servo/CUserManager2.cpp
+++ b/SourceCode/Bond/Servo/CUserManager2.cpp
@@ -1,12 +1,34 @@
-#include "stdafx.h"
+锘�#include "stdafx.h"
 #include "CUserManager2.h"
 #include "ToolUnits.h"
+#include <vector>
+#include <map>
+#include <utility>
+#include <algorithm>
 #include <sstream>
 #include <cwchar>
 
 std::vector<std::wstring> SplitLines(const std::wstring& text) 
 {
 	std::wstringstream ss(text); std::vector<std::wstring> v; std::wstring line; while (std::getline(ss, line)) v.push_back(line); return v;
+}
+
+std::vector<std::wstring> SplitByDelimiter(const std::wstring& text, wchar_t delimiter)
+{
+	std::vector<std::wstring> parts;
+	size_t start = 0;
+	while (start <= text.length()) {
+		size_t pos = text.find(delimiter, start);
+		if (pos == std::wstring::npos) {
+			parts.push_back(text.substr(start));
+			break;
+		}
+
+		parts.push_back(text.substr(start, pos - start));
+		start = pos + 1;
+	}
+
+	return parts;
 }
 
 template<typename Fn>
@@ -19,7 +41,7 @@
 	return L"";
 }
 
-// 获取单例实例
+// 鑾峰彇鍗曚緥瀹炰緥
 CUserManager2& CUserManager2::getInstance() {
 	static CUserManager2 instance;
 	return instance;
@@ -45,10 +67,33 @@
 	bool hasAny = false;
 	for (auto& ln : SplitLines(buffer)) { if (!ln.empty()) { hasAny = true; break; } }
 	if (!hasAny) {
-		const wchar_t* roles = L"Admin:100\nEngineer:50\nOperator:10\n";
+		const wchar_t* roles = L"Admin:100\nEE:80\nPE:50\nOperator:10\n";
 		(void)UX_SetRoleDefinitions(roles);
 		(void)UX_AddUser(L"admin", L"Administrator", L"admin123", L"Admin");
+
+		UX_DefineAction(L"start", L"鍚姩鏈哄彴", L"Operator"); 
+		UX_DefineAction(L"stop", L"鍋滄満", L"Operator");
+		UX_DefineAction(L"recipe", L"缂栬緫閰嶆柟", L"PE");
+		UX_DefineAction(L"delVarialbles", L"鍒犻櫎鍙橀噺", L"PE");
+		UX_DefineAction(L"addVarialbles", L"鏂板鍙橀噺", L"PE");
+		UX_DefineAction(L"editVarialbles", L"缂栬緫鍙橀噺", L"PE");
+		UX_DefineAction(L"addReports", L"鏂板Report", L"PE");
+		UX_DefineAction(L"editReports", L"缂栬緫Report", L"PE");
+		UX_DefineAction(L"delReports", L"鍒犻櫎Report", L"PE");
+		UX_DefineAction(L"addEvents", L"鏂板Event", L"PE");
+		UX_DefineAction(L"editEvents", L"缂栬緫Event", L"PE");
+		UX_DefineAction(L"delEvents", L"鍒犻櫎Event", L"PE");
 	}
+	// 纭繚鏉冮檺瀹氫箟瀛樺湪锛堝箓绛夛級
+	UX_DefineAction(L"addVarialbles", L"鏂板鍙橀噺", L"PE");
+	UX_DefineAction(L"editVarialbles", L"缂栬緫鍙橀噺", L"PE");
+	UX_DefineAction(L"delVarialbles", L"鍒犻櫎鍙橀噺", L"PE");
+	UX_DefineAction(L"addReports", L"鏂板Report", L"PE");
+	UX_DefineAction(L"editReports", L"缂栬緫Report", L"PE");
+	UX_DefineAction(L"delReports", L"鍒犻櫎Report", L"PE");
+	UX_DefineAction(L"delEvents", L"鍒犻櫎Event", L"PE");
+	UX_DefineAction(L"addEvents", L"鏂板Event", L"PE");
+	UX_DefineAction(L"editEvents", L"缂栬緫Event", L"PE");
 }
 
 bool CUserManager2::login(const char* pszAccount, const char* pszPwd)
@@ -98,3 +143,108 @@
 
 	return (maxLvl > 0) && (myLvl >= maxLvl);
 }
+
+std::vector<CUserManager2::RoleInfo> CUserManager2::getRoles()
+{
+	std::vector<RoleInfo> roles;
+	auto txt = ReadBufferVia([](wchar_t* b, int n) { return UX_GetRoles(b, n); });
+	if (txt.empty()) {
+		return roles;
+	}
+
+	for (auto& line : SplitLines(txt)) {
+		if (line.empty()) continue;
+		size_t pos = line.find(L':');
+		RoleInfo info;
+		info.name = (pos == std::wstring::npos) ? line : line.substr(0, pos);
+		if (pos != std::wstring::npos) {
+			info.level = _wtoi(line.substr(pos + 1).c_str());
+		}
+
+		if (!info.name.empty()) {
+			roles.push_back(std::move(info));
+		}
+	}
+
+	std::sort(roles.begin(), roles.end(), [](const RoleInfo& a, const RoleInfo& b) {
+		if (a.level == b.level) {
+			return a.name < b.name;
+		}
+		return a.level > b.level;
+	});
+
+	return roles;
+}
+std::vector<CUserManager2::UserInfo> CUserManager2::getUsers()
+{
+	std::vector<UserInfo> users;
+	auto txt = ReadBufferVia([](wchar_t* b, int n) { return UX_GetUsers(b, n); });
+	if (txt.empty()) {
+		return users;
+	}
+
+	std::map<int, std::wstring> roleMap;
+	for (auto& role : getRoles()) {
+		roleMap[role.level] = role.name;
+	}
+
+	for (auto& line : SplitLines(txt)) {
+		if (line.empty()) continue;
+		auto parts = SplitByDelimiter(line, L',');
+		UserInfo info;
+		if (!parts.empty()) info.userName = parts[0];
+		if (parts.size() > 1) info.displayName = parts[1];
+		if (parts.size() > 2) info.roleLevel = _wtoi(parts[2].c_str());
+		if (parts.size() > 3) info.enabled = (_wtoi(parts[3].c_str()) != 0);
+		auto it = roleMap.find(info.roleLevel);
+		if (it != roleMap.end()) {
+			info.roleName = it->second;
+		}
+		users.push_back(std::move(info));
+	}
+
+	return users;
+}
+
+int CUserManager2::addUser(const std::wstring& userName, const std::wstring& displayName,
+	const std::wstring& password, const std::wstring& roleName, bool enabled)
+{
+	int rc = UX_AddUser(userName.c_str(), displayName.c_str(), password.c_str(), roleName.c_str());
+	if (rc == UX_OK && !enabled) {
+		UX_EnableUser(userName.c_str(), 0);
+	}
+
+	return rc;
+}
+
+int CUserManager2::updateUser(const std::wstring& userName, const std::wstring& displayName,
+	const std::wstring& password, const std::wstring& roleName, bool enabled)
+{
+	const wchar_t* disp = displayName.empty() ? nullptr : displayName.c_str();
+	const wchar_t* pwd = password.empty() ? nullptr : password.c_str();
+	const wchar_t* role = roleName.empty() ? nullptr : roleName.c_str();
+	return UX_UpdateUser(userName.c_str(), disp, pwd, role, enabled ? 1 : 0);
+}
+
+int CUserManager2::deleteUser(const std::wstring& userName)
+{
+	return UX_DeleteUser(userName.c_str());
+}
+
+int CUserManager2::setUserEnabled(const std::wstring& userName, bool enabled)
+{
+	return UX_EnableUser(userName.c_str(), enabled ? 1 : 0);
+}
+
+int CUserManager2::resetPassword(const std::wstring& userName, const std::wstring& password)
+{
+	return UX_ResetPassword(userName.c_str(), password.c_str());
+}
+
+
+
+
+
+
+
+

--
Gitblit v1.9.3