common.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. #include "common.h"
  2. #include "elog.h"
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/sysinfo.h>
  6. #include <sys/ioctl.h>
  7. #include <sys/socket.h>
  8. #include <net/if.h>
  9. #include <arpa/inet.h>
  10. #include <sys/vfs.h>
  11. #undef LOG_TAG
  12. #define LOG_TAG "main"
  13. GlobalDeviceManager __globalDeviceManage={0};
  14. GlobalDeviceManager __globalDeviceManage2={0};
  15. int ntp_sync_flag=0;
  16. unsigned long __globalSxIdx;
  17. _User_Log _GlobalUserLoginInfo;
  18. UserInfo _GlobalUserInfoNew;
  19. char _GlobalUserToken[64];
  20. MenuAuthority _GlobalMenuAuthority;
  21. NTPManager _globalNTPManager;
  22. void printf_global_device_info(GlobalDeviceInfo* _globalDeviceInfo)
  23. {
  24. log_d("******global device info********* ");
  25. log_d("product.id:%d ", _globalDeviceInfo->product.id);
  26. log_d("product.number:%s ", _globalDeviceInfo->product.number);
  27. log_d("product.name:%s ", _globalDeviceInfo->product.name);
  28. log_d("product.ype:%d ", _globalDeviceInfo->product.type);
  29. log_d("product.pwr_type:%d ", _globalDeviceInfo->product.pwr_type);
  30. log_d("product.version:%s ", _globalDeviceInfo->product.version);
  31. log_d("product.count:%d ", _globalDeviceInfo->product.count);
  32. log_d("product.samp_time:%d ", _globalDeviceInfo->product.samp_time);
  33. log_d("product.save_time:%d ", _globalDeviceInfo->product.save_time);
  34. log_d("cascade.mode:%d ", _globalDeviceInfo->cascade.mode);
  35. log_d("cascade.addr:%d ", _globalDeviceInfo->cascade.addr);
  36. log_d("cascade.baudrate:%d ", _globalDeviceInfo->cascade.baudrate);
  37. log_d("relay.path:%s ", _globalDeviceInfo->relay.path);
  38. log_d("******************************** ");
  39. }
  40. void printf_global_power_manage_info(GlobalPowerManger* _globalPowerManger)
  41. {
  42. printf("******global power manage info********* ");
  43. printf("product_id:%d ", _globalPowerManger->product_id);
  44. printf("product_ch_id:%d ", _globalPowerManger->product_ch_id);
  45. printf("product_ch_name:%s ", _globalPowerManger->product_ch_name);
  46. printf("product_ch_type:%d ", _globalPowerManger->product_ch_type);
  47. printf("product_ch_status:%d ", _globalPowerManger->product_ch_status);
  48. printf("product_ch_NF_status:%d ", _globalPowerManger->product_ch_NF_status);
  49. printf("product_ch_start_delay:%d ", _globalPowerManger->product_ch_start_delay);
  50. printf("product_ch_stop_delay:%d ", _globalPowerManger->product_ch_stop_delay);
  51. printf("product_vol_upper_enable:%d ", _globalPowerManger->global_over_manager->product_vol_upper_enable);
  52. printf("product_vol_upper_threshold:%0.2f ", _globalPowerManger->global_over_manager->product_vol_upper_threshold);
  53. printf("product_vol_over_upper_threshold_ctrl:%d ", _globalPowerManger->global_over_manager->product_vol_over_upper_threshold_ctrl);
  54. printf("product_vol_over_upper_threshold_para:%d ", _globalPowerManger->global_over_manager->product_vol_over_upper_threshold_ctrl_para);
  55. printf("product_vol_lower_enable:%d ", _globalPowerManger->global_over_manager->product_vol_lower_enable);
  56. printf("product_vol_lower_threshold:%0.2f ", _globalPowerManger->global_over_manager->product_vol_lower_threshold);
  57. printf("product_vol_over_lower_threshold_ctrl:%d ", _globalPowerManger->global_over_manager->product_vol_over_lower_threshold_ctrl);
  58. printf("product_vol_over_lower_threshold_ctrl_para:%d ", _globalPowerManger->global_over_manager->product_vol_over_lower_threshold_ctrl_para);
  59. printf("product_cur_upper_enable:%d ", _globalPowerManger->global_over_manager->product_cur_upper_enable);
  60. printf("product_cur_upper_threshold:%0.2f ", _globalPowerManger->global_over_manager->product_cur_upper_threshold);
  61. printf("product_cur_over_upper_threshold_ctrl:%d ", _globalPowerManger->global_over_manager->product_cur_over_upper_threshold_ctrl);
  62. printf("product_cur_over_upper_threshold_ctrl_para:%d ", _globalPowerManger->global_over_manager->product_cur_over_upper_threshold_ctrl_para);
  63. printf("product_pwr_upper_enable:%d ", _globalPowerManger->global_over_manager->product_pwr_upper_enable);
  64. printf("product_pwr_upper_threshold:%0.2f ", _globalPowerManger->global_over_manager->product_pwr_upper_threshold);
  65. printf("product_pwr_over_upper_threshold_ctrl:%d ", _globalPowerManger->global_over_manager->product_pwr_over_upper_threshold_ctrl);
  66. printf("product_pwr_over_upper_threshold_ctrl_para:%d ", _globalPowerManger->global_over_manager->product_pwr_over_upper_threshold_ctrl_para);
  67. printf("product_pwrcon_upper_enable:%d ", _globalPowerManger->global_over_manager->product_pwrcon_upper_enable);
  68. printf("product_pwrcon_upper_threshold:%0.2f ", _globalPowerManger->global_over_manager->product_pwrcon_upper_threshold);
  69. printf("product_pwrcon_over_upper_threshold_ctrl:%d ", _globalPowerManger->global_over_manager->product_pwrcon_over_upper_threshold_ctrl);
  70. printf("product_pwrcon_over_upper_threshold_ctrl_para:%d ", _globalPowerManger->global_over_manager->product_pwrcon_over_upper_threshold_ctrl_para);
  71. printf("******************************** ");
  72. }
  73. //打印电源信息
  74. void printf_power_info(GlobalPowerInfo* _globalPowerInfo)
  75. {
  76. struct list_head *pos;
  77. GlobalPowerInfo* _temp;
  78. int i = 0;
  79. list_for_each_entry(_temp, &_globalPowerInfo->list, list)
  80. {
  81. printf("i:%d ", i++);
  82. printf("samp_time:%s ", _temp->samp_time);
  83. printf("product_id:%d ", _temp->product_id);
  84. }
  85. }
  86. void INIT_LIST_HEAD(struct list_head *list)
  87. {
  88. list->next = list->prev = list;
  89. }
  90. /**
  91. * EasyLogger demo
  92. */
  93. // void test_elog(void) {
  94. // uint8_t buf[256]= {0};
  95. // int i = 0;
  96. // for (i = 0; i < sizeof(buf); i++)
  97. // {
  98. // buf[i] = i;
  99. // }
  100. // while(true) {
  101. // /* test log output for all level */
  102. // log_a("Hello EasyLogger!");
  103. // log_e("Hello EasyLogger!");
  104. // log_w("Hello EasyLogger!");
  105. // log_i("Hello EasyLogger!");
  106. // log_d("Hello EasyLogger!");
  107. // log_v("Hello EasyLogger!");
  108. // // elog_raw("Hello EasyLogger!");
  109. // elog_hexdump("test", 16, buf, sizeof(buf));
  110. // sleep(5);
  111. // }
  112. // }
  113. #if(1)
  114. void initLogger(void)
  115. {
  116. setbuf(stdout, NULL);
  117. elog_init();
  118. elog_set_fmt(ELOG_LVL_ASSERT, ELOG_FMT_ALL);
  119. elog_set_fmt(ELOG_LVL_ERROR, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
  120. elog_set_fmt(ELOG_LVL_WARN, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
  121. elog_set_fmt(ELOG_LVL_INFO, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
  122. elog_set_fmt(ELOG_LVL_DEBUG, ELOG_FMT_ALL & ~ELOG_FMT_FUNC);
  123. elog_set_fmt(ELOG_LVL_VERBOSE, ELOG_FMT_ALL & ~ELOG_FMT_FUNC);
  124. elog_set_text_color_enabled(true);
  125. elog_start();
  126. log_i("Smart Pdu Application Running!");
  127. }
  128. #endif
  129. /// @brief 获取系统mem大小
  130. /// @param totalSize
  131. /// @return
  132. int getTotalMemorySize(unsigned int* totalSize)
  133. {
  134. struct sysinfo memInfo;
  135. if (sysinfo(&memInfo) != -1) {
  136. *totalSize = memInfo.totalram;
  137. // printf("Total RAM size: %lu bytes\n", memInfo.totalram);
  138. // printf("Free RAM size: %lu bytes\n", memInfo.freeram);
  139. }
  140. else
  141. {
  142. *totalSize = 0 ;
  143. return -1;
  144. }
  145. return 0;
  146. }
  147. /// @brief 返回设备IP地址
  148. /// @param dev 网口名
  149. /// @return
  150. char* getLocalIpAddress(char* dev)
  151. {
  152. int fd;
  153. struct ifreq ifr;
  154. static char ip_addr[64];
  155. fd = socket(AF_INET, SOCK_DGRAM, 0);
  156. ifr.ifr_addr.sa_family = AF_INET;
  157. strncpy(ifr.ifr_name, dev, IFNAMSIZ-1);
  158. ioctl(fd, SIOCGIFADDR, &ifr);
  159. close(fd);
  160. char *p=inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
  161. if(!p) {
  162. return NULL;
  163. }
  164. strcpy(ip_addr, p);
  165. return ip_addr;
  166. }
  167. // 获取MAC地址的函数
  168. char* get_mac_address(const char *iface_name)
  169. {
  170. int fd;
  171. struct ifreq ifr;
  172. unsigned char *mac;
  173. static char mac_str[32];
  174. snprintf(mac_str, sizeof(mac_str), "%02d:%02d:%02d:%02d:%02d:%02d",
  175. 0, 0, 0, 0, 0, 0);
  176. // 创建一个socket
  177. if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
  178. perror("socket error");
  179. return mac_str;
  180. }
  181. // 设置接口名称
  182. strncpy(ifr.ifr_name, iface_name, IFNAMSIZ - 1);
  183. // 获取MAC地址
  184. if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) {
  185. perror("ioctl error");
  186. close(fd);
  187. return mac_str;
  188. }
  189. // ifr.ifr_hwaddr.sa_data是一个包含硬件地址的字节数组
  190. mac = (unsigned char *)ifr.ifr_hwaddr.sa_data;
  191. // 将MAC地址转换为字符串格式
  192. snprintf(mac_str, sizeof(mac_str), "%02X:%02X:%02X:%02X:%02X:%02X",
  193. mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  194. // 关闭socket
  195. close(fd);
  196. return mac_str;
  197. }
  198. /// @brief 获取磁盘使用率
  199. /// @param reused
  200. void get_disk_occupy(char ** reused)
  201. {
  202. const unsigned short MAXBUFSIZE = 1024;
  203. char currentDirectoryPath[ MAXBUFSIZE ];
  204. getcwd(currentDirectoryPath, MAXBUFSIZE);
  205. //printf("当前目录:%s\n",currentDirectoryPath);
  206. char cmd[50] = "df ";
  207. strcat(cmd, currentDirectoryPath);
  208. //printf("%s\n",cmd);
  209. char buffer[MAXBUFSIZE];
  210. FILE* pipe = popen(cmd, "r");
  211. char fileSys[20];
  212. char blocks[20];
  213. char used[20];
  214. char free[20];
  215. char percent[10];
  216. char moment[20];
  217. if (!pipe)
  218. {
  219. return;
  220. }
  221. if (fgets(buffer, sizeof(buffer), pipe) != NULL)
  222. {
  223. sscanf(buffer, "%s %s %s %s %s %s", fileSys, blocks, used, free, percent, moment);
  224. }
  225. if (fgets(buffer, sizeof(buffer), pipe) != NULL)
  226. {
  227. sscanf(buffer, "%s %s %s %s %s %s", fileSys, blocks, used, free, percent, moment);
  228. }
  229. //printf("desk used:%s\n",percent);
  230. strcpy(*reused, percent);
  231. return;
  232. }
  233. int set_local_timeandzone(struct tm* t, int zone)
  234. {
  235. char buf[128];
  236. struct timeval tv;
  237. switch(zone)
  238. {
  239. case -11:
  240. sprintf(buf, "ln -sf /usr/share/zoneinfo/Pacific/Midway /etc/localtime");
  241. break;
  242. case -10:
  243. sprintf(buf, "ln -sf /usr/share/zoneinfo/HST /etc/localtime");
  244. break;
  245. case -9:
  246. sprintf(buf, "ln -sf /usr/share/zoneinfo/America/Adak /etc/localtime");
  247. break;
  248. case -8:
  249. sprintf(buf, "ln -sf /usr/share/zoneinfo/America/Boise /etc/localtime");
  250. break;
  251. case -7:
  252. sprintf(buf, "ln -sf /usr/share/zoneinfo/MST /etc/localtime");
  253. break;
  254. case -6:
  255. sprintf(buf, "ln -sf /usr/share/zoneinfo/America/Chicago /etc/localtime");
  256. break;
  257. case -5:
  258. sprintf(buf, "ln -sf /usr/share/zoneinfo/America/Detroit /etc/localtime");
  259. break;
  260. case -4:
  261. sprintf(buf, "ln -sf /usr/share/zoneinfo/America/Halifax /etc/localtime");
  262. break;
  263. case -3:
  264. sprintf(buf, "ln -sf /usr/share/zoneinfo/America/Maceio /etc/localtime");
  265. break;
  266. case -2:
  267. sprintf(buf, "ln -sf /usr/share/zoneinfo/America/Noronha /etc/localtime");
  268. break;
  269. case -1:
  270. sprintf(buf, "ln -sf /usr/share/zoneinfo/America/Scoresbysund /etc/localtime");
  271. break;
  272. case 0:
  273. sprintf(buf, "ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime");
  274. break;
  275. case 1:
  276. sprintf(buf, "ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime");
  277. break;
  278. case 2:
  279. sprintf(buf, "ln -sf /usr/share/zoneinfo/Europe/Athens /etc/localtime");
  280. break;
  281. case 3:
  282. sprintf(buf, "ln -sf /usr/share/zoneinfo/Europe/Moscow /etc/localtime");
  283. break;
  284. case 4:
  285. sprintf(buf, "ln -sf /usr/share/zoneinfo/Asia/Amman /etc/localtime");
  286. break;
  287. case 5:
  288. sprintf(buf, "ln -sf /usr/share/zoneinfo/Asia/Karachi /etc/localtime");
  289. break;
  290. case 6:
  291. sprintf(buf, "ln -sf /usr/share/zoneinfo/Asia/Dhaka /etc/localtime");
  292. break;
  293. case 7:
  294. sprintf(buf, "ln -sf /usr/share/zoneinfo/Asia/Bangkok /etc/localtime");
  295. break;
  296. case 8:
  297. sprintf(buf, "ln -sf /usr/share/zoneinfo/Asia/Beijing /etc/localtime");
  298. break;
  299. case 9:
  300. sprintf(buf, "ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime");
  301. break;
  302. case 10:
  303. sprintf(buf, "ln -sf /usr/share/zoneinfo/Australia/Sydney /etc/localtime");
  304. break;
  305. case 11:
  306. sprintf(buf, "ln -sf /usr/share/zoneinfo/Asia/Sakhalin /etc/localtime");
  307. break;
  308. case 12:
  309. sprintf(buf, "ln -sf /usr/share/zoneinfo/Pacific/Fiji /etc/localtime");
  310. break;
  311. }
  312. system(buf);
  313. //time_t now=time(NULL)+zone*3600;
  314. //struct tm* ptm = localtime(&t);
  315. //memset(buf, 0, sizeof(buf));
  316. sprintf(buf, "date -s \"%04d-%02d-%02d %02d:%02d:%02d\" && hwclock -w -f /dev/rtc0 ", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
  317. log_i("%s",buf);
  318. system(buf);
  319. return 0;
  320. }
  321. char* getUserNamebyToken(char* Token)
  322. {
  323. char* userName = NULL;
  324. if (Token==NULL)
  325. {
  326. return NULL;
  327. }
  328. _User_Log *_UserInfoTemp = NULL;
  329. list_for_each_entry(_UserInfoTemp, &_GlobalUserLoginInfo.list, list)
  330. {
  331. if (_UserInfoTemp == NULL)
  332. break;
  333. if (strcmp(_UserInfoTemp->user_token, Token) == 0)
  334. {
  335. userName=_UserInfoTemp->user_name;
  336. }
  337. }
  338. return userName;
  339. }
  340. int is_process_running(const char *process_name)
  341. {
  342. DIR *dir;
  343. struct dirent *entry;
  344. char path[1035]; // /proc/[pid]/cmdline 的最大路径长度(/proc/ + PID(最多5位) + /cmdline + \0)
  345. char buffer[4096]; // 假设cmdline不会超过这个长度
  346. FILE *file;
  347. dir = opendir("/proc");
  348. if (dir == NULL) {
  349. perror("opendir");
  350. return -1;
  351. }
  352. while ((entry = readdir(dir)) != NULL) {
  353. // 忽略非数字目录(即非进程目录)
  354. if (!isdigit(entry->d_name[0])) {
  355. continue;
  356. }
  357. // 构造cmdline文件的完整路径
  358. snprintf(path, sizeof(path), "/proc/%s/cmdline", entry->d_name);
  359. // 打开cmdline文件
  360. file = fopen(path, "r");
  361. if (file == NULL) {
  362. continue; // 忽略无法打开的文件
  363. }
  364. // 读取cmdline文件的内容
  365. if (fgets(buffer, sizeof(buffer), file) != NULL) {
  366. // 去除cmdline中的空字符(进程名与参数间用空字符分隔)
  367. size_t len = strlen(buffer);
  368. while (len > 0 && buffer[len - 1] == '\0') {
  369. buffer[--len] = '\0';
  370. }
  371. // 比较进程名(这里假设process_name是完整的命令行,但你可以修改逻辑来仅比较进程名)
  372. if (strstr(buffer, process_name) != NULL) {
  373. fclose(file);
  374. closedir(dir);
  375. return 1; // 进程已启动
  376. }
  377. }
  378. fclose(file);
  379. }
  380. closedir(dir);
  381. return 0; // 进程未启动
  382. }
  383. bool CheckLoginStatus(char* Token)
  384. {
  385. //return true;//先不处理401授权错误,待前端处理后再加 20240625 lyz
  386. // 没有用户登录
  387. int nLoginNum=0;
  388. _User_Log *_UserInfoTemp = NULL;
  389. list_for_each_entry(_UserInfoTemp, &_GlobalUserLoginInfo.list, list)
  390. {
  391. if (_UserInfoTemp == NULL)
  392. break;
  393. nLoginNum++;
  394. }
  395. if (nLoginNum==0)
  396. {
  397. return false;
  398. }
  399. // 根据Token查询不到登录的用户
  400. if (Token != NULL && strcmp(Token, "") != 0 && getUserNamebyToken(Token) == NULL)
  401. {
  402. return false;
  403. }
  404. return true;
  405. // return __globalDeviceManage._globalDevInfo.login_status;
  406. }
  407. // 辅助函数:判断是否是闰年
  408. int is_leap_year(int year) {
  409. return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
  410. }
  411. // 辅助函数:获取某月的天数
  412. int days_in_month(int year, int month) {
  413. int days_per_month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  414. if (month == 2 && is_leap_year(year)) return 29;
  415. return days_per_month[month];
  416. }
  417. // 函数:增加一天到日期
  418. void add_day_to_date(char *date_str, int *year, int *month, int *day) {
  419. (*day)++;
  420. if (*day > days_in_month(*year, *month)) {
  421. (*day) = 1;
  422. (*month)++;
  423. if (*month > 12) {
  424. (*month) = 1;
  425. (*year)++;
  426. }
  427. }
  428. sprintf(date_str, "%04d-%02d-%02d", *year, *month, *day);
  429. }
  430. void SetMenuAuthority(int RoleID)
  431. {
  432. //超级管理员
  433. if (RoleID == 1)
  434. {
  435. _GlobalMenuAuthority.PowerEnabled = true;
  436. _GlobalMenuAuthority.SensorEnabled = true;
  437. _GlobalMenuAuthority.AlarmEnabled = true;
  438. _GlobalMenuAuthority.LogEnabled = true;
  439. _GlobalMenuAuthority.UserInfoEnabled = true;
  440. _GlobalMenuAuthority.CommEnabled = true;
  441. _GlobalMenuAuthority.ServiceEnabled = true;
  442. _GlobalMenuAuthority.MaintenanceEnabled = true;
  443. // 1、电源监控菜单
  444. _GlobalMenuAuthority.MonitorallEnabled = true;
  445. _GlobalMenuAuthority.ChannelstatusEnabled = true;
  446. _GlobalMenuAuthority.SwitchtatusEnabled = true;
  447. _GlobalMenuAuthority.MonitorhistoryEnabled = true;
  448. // 2、传感器管理菜单
  449. _GlobalMenuAuthority.SensorStatusEnabled = true;
  450. _GlobalMenuAuthority.SensorHistorylEnabled = true;
  451. // 3、告警管理菜单
  452. _GlobalMenuAuthority.XtjgEnabled = true;
  453. _GlobalMenuAuthority.YzszEnabled = true;
  454. // 4、日志信息菜单
  455. _GlobalMenuAuthority.CzrzEnabled = true;
  456. _GlobalMenuAuthority.YxrzEnabled = true;
  457. // 5、用户管理菜单
  458. _GlobalMenuAuthority.UserEnabled = true;
  459. _GlobalMenuAuthority.RoleEnabled = false;
  460. _GlobalMenuAuthority.MenuEnabled = false;
  461. // 6、通信管理菜单
  462. _GlobalMenuAuthority.WkszEnabled = true;
  463. _GlobalMenuAuthority.RsszEnabled = true;
  464. // 7、服务管理菜单
  465. _GlobalMenuAuthority.SmtpszEnabled = true;
  466. _GlobalMenuAuthority.SnmpszEnabled = true;
  467. _GlobalMenuAuthority.MqszEnabled = true;
  468. _GlobalMenuAuthority.NtpszEnabled = true;
  469. _GlobalMenuAuthority.DsszEnabled = true;
  470. _GlobalMenuAuthority.SxszEnabled = true;
  471. _GlobalMenuAuthority.FzszEnabled = true;
  472. // 8、设备维护菜单
  473. _GlobalMenuAuthority.SbcqEnabled = true;
  474. _GlobalMenuAuthority.GjsjEnabled = true;
  475. _GlobalMenuAuthority.HhccszEnabled = true;
  476. _GlobalMenuAuthority.PzdrdcEnabled = true;
  477. _GlobalMenuAuthority.ShfwEnabled = true;
  478. _GlobalMenuAuthority.GysbEnabled = true;
  479. }
  480. // 管理员
  481. else if (RoleID == 2)
  482. {
  483. _GlobalMenuAuthority.PowerEnabled = true;
  484. _GlobalMenuAuthority.SensorEnabled = true;
  485. _GlobalMenuAuthority.AlarmEnabled = true;
  486. _GlobalMenuAuthority.LogEnabled = true;
  487. _GlobalMenuAuthority.UserInfoEnabled = true;
  488. _GlobalMenuAuthority.CommEnabled = true;
  489. _GlobalMenuAuthority.ServiceEnabled = true;
  490. _GlobalMenuAuthority.MaintenanceEnabled = true;
  491. // 1、电源监控菜单
  492. _GlobalMenuAuthority.MonitorallEnabled = true;
  493. _GlobalMenuAuthority.ChannelstatusEnabled = true;
  494. _GlobalMenuAuthority.SwitchtatusEnabled = false;
  495. _GlobalMenuAuthority.MonitorhistoryEnabled = true;
  496. // 2、传感器管理菜单
  497. _GlobalMenuAuthority.SensorStatusEnabled = true;
  498. _GlobalMenuAuthority.SensorHistorylEnabled = true;
  499. // 3、告警管理菜单
  500. _GlobalMenuAuthority.XtjgEnabled = true;
  501. _GlobalMenuAuthority.YzszEnabled = true;
  502. // 4、日志信息菜单
  503. _GlobalMenuAuthority.CzrzEnabled = false;
  504. _GlobalMenuAuthority.YxrzEnabled = true;
  505. // 5、用户管理菜单
  506. _GlobalMenuAuthority.UserEnabled = true;
  507. _GlobalMenuAuthority.RoleEnabled = false;
  508. _GlobalMenuAuthority.MenuEnabled = false;
  509. // 6、通信管理菜单
  510. _GlobalMenuAuthority.WkszEnabled = false;
  511. _GlobalMenuAuthority.RsszEnabled = true;
  512. // 7、服务管理菜单
  513. _GlobalMenuAuthority.SmtpszEnabled = false;
  514. _GlobalMenuAuthority.SnmpszEnabled = false;
  515. _GlobalMenuAuthority.MqszEnabled = false;
  516. _GlobalMenuAuthority.NtpszEnabled = true;
  517. _GlobalMenuAuthority.DsszEnabled = true;
  518. _GlobalMenuAuthority.SxszEnabled = true;
  519. _GlobalMenuAuthority.FzszEnabled = true;
  520. // 8、设备维护菜单
  521. _GlobalMenuAuthority.SbcqEnabled = true;
  522. _GlobalMenuAuthority.GjsjEnabled = true;
  523. _GlobalMenuAuthority.HhccszEnabled = false;
  524. _GlobalMenuAuthority.PzdrdcEnabled = true;
  525. _GlobalMenuAuthority.ShfwEnabled = false;
  526. _GlobalMenuAuthority.GysbEnabled = true;
  527. }
  528. //普通用户
  529. else
  530. {
  531. _GlobalMenuAuthority.PowerEnabled = true;
  532. _GlobalMenuAuthority.SensorEnabled = true;
  533. _GlobalMenuAuthority.AlarmEnabled = false;
  534. _GlobalMenuAuthority.LogEnabled = false;
  535. _GlobalMenuAuthority.UserInfoEnabled = false;
  536. _GlobalMenuAuthority.CommEnabled = false;
  537. _GlobalMenuAuthority.ServiceEnabled = false;
  538. _GlobalMenuAuthority.MaintenanceEnabled = false;
  539. // 1、电源监控菜单
  540. _GlobalMenuAuthority.MonitorallEnabled = true;
  541. _GlobalMenuAuthority.ChannelstatusEnabled = true;
  542. _GlobalMenuAuthority.SwitchtatusEnabled = false;
  543. _GlobalMenuAuthority.MonitorhistoryEnabled = false;
  544. // 2、传感器管理菜单
  545. _GlobalMenuAuthority.SensorStatusEnabled = true;
  546. _GlobalMenuAuthority.SensorHistorylEnabled = false;
  547. // 3、告警管理菜单
  548. _GlobalMenuAuthority.XtjgEnabled = false;
  549. _GlobalMenuAuthority.YzszEnabled = false;
  550. // 4、日志信息菜单
  551. _GlobalMenuAuthority.CzrzEnabled = false;
  552. _GlobalMenuAuthority.YxrzEnabled = false;
  553. // 5、用户管理菜单
  554. _GlobalMenuAuthority.UserEnabled = false;
  555. _GlobalMenuAuthority.RoleEnabled = false;
  556. _GlobalMenuAuthority.MenuEnabled = false;
  557. // 6、通信管理菜单
  558. _GlobalMenuAuthority.WkszEnabled = false;
  559. _GlobalMenuAuthority.RsszEnabled = false;
  560. // 7、服务管理菜单
  561. _GlobalMenuAuthority.SmtpszEnabled = false;
  562. _GlobalMenuAuthority.SnmpszEnabled = false;
  563. _GlobalMenuAuthority.MqszEnabled = false;
  564. _GlobalMenuAuthority.NtpszEnabled = false;
  565. _GlobalMenuAuthority.DsszEnabled = false;
  566. _GlobalMenuAuthority.SxszEnabled = false;
  567. _GlobalMenuAuthority.FzszEnabled = false;
  568. // 8、设备维护菜单
  569. _GlobalMenuAuthority.SbcqEnabled = false;
  570. _GlobalMenuAuthority.GjsjEnabled = false;
  571. _GlobalMenuAuthority.HhccszEnabled = false;
  572. _GlobalMenuAuthority.PzdrdcEnabled = false;
  573. _GlobalMenuAuthority.ShfwEnabled = false;
  574. _GlobalMenuAuthority.GysbEnabled = false;
  575. }
  576. }