From b132a3ba1304156d8e0c1bd8337b8021de615794 Mon Sep 17 00:00:00 2001 From: tianlinzhong <673359306@qq.com> Date: Mon, 14 Feb 2022 17:06:46 +0800 Subject: [PATCH 1/5] fixed Web UI Notification bug --- myems-api/core/webmessage.py | 112 +++++++++++++++ .../MyEMS/Notification/Notification.js | 128 +++++++++++++++++- .../components/navbar/NotificationDropdown.js | 53 +++++++- 3 files changed, 287 insertions(+), 6 deletions(-) diff --git a/myems-api/core/webmessage.py b/myems-api/core/webmessage.py index a24b2961..ac75d902 100644 --- a/myems-api/core/webmessage.py +++ b/myems-api/core/webmessage.py @@ -245,6 +245,118 @@ class WebMessageStatusNewCollection: resp.text = json.dumps(result) + @staticmethod + @user_logger + def on_put(req, resp): + """Handles PUT requests""" + try: + raw_json = req.stream.read().decode('utf-8') + except Exception as ex: + raise falcon.HTTPError(falcon.HTTP_400, title='API.EXCEPTION', description=ex) + + new_values = json.loads(raw_json) + + if 'status' not in new_values['data'].keys() or \ + not isinstance(new_values['data']['status'], str) or \ + len(str.strip(new_values['data']['status'])) == 0 or \ + str.strip(new_values['data']['status']) not in ('new', 'acknowledged', 'read'): + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', + description='API.INVALID_STATUS') + status = str.strip(new_values['data']['status']) + + # reply is required for 'acknowledged' status + if status == 'acknowledged' and \ + ('reply' not in new_values['data'].keys() or + not isinstance(new_values['data']['reply'], str) or + len(str.strip(new_values['data']['reply'])) == 0): + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', + description='API.INVALID_REPLY') + reply = str.strip(new_values['data']['reply']) + else: + reply = None + + # Verify User Session + token = req.headers.get('TOKEN') + user_uuid = req.headers.get('USER-UUID') + if token is None: + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', + description='API.TOKEN_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN') + if user_uuid is None: + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', + description='API.USER_UUID_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN') + + cnx = mysql.connector.connect(**config.myems_user_db) + cursor = cnx.cursor(dictionary=True) + + query = (" SELECT utc_expires " + " FROM tbl_sessions " + " WHERE user_uuid = %s AND token = %s") + cursor.execute(query, (user_uuid, token,)) + row = cursor.fetchone() + + if row is None: + if cursor: + cursor.close() + if cnx: + cnx.disconnect() + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', + description='API.INVALID_SESSION_PLEASE_RE_LOGIN') + else: + utc_expires = row['utc_expires'] + if datetime.utcnow() > utc_expires: + if cursor: + cursor.close() + if cnx: + cnx.disconnect() + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', + description='API.USER_SESSION_TIMEOUT') + + cursor.execute(" SELECT id " + " FROM tbl_users " + " WHERE uuid = %s ", + (user_uuid,)) + row = cursor.fetchone() + if row is None: + if cursor: + cursor.close() + if cnx: + cnx.disconnect() + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', + description='API.INVALID_USER_PLEASE_RE_LOGIN') + else: + user_id = row['id'] + + if cursor: + cursor.close() + if cnx: + cnx.disconnect() + + cnx = mysql.connector.connect(**config.myems_fdd_db) + cursor = cnx.cursor() + + cursor.execute(" SELECT user_id " + " FROM tbl_web_messages " + " WHERE status = %s AND user_id = %s ", ('new', user_id)) + if cursor.fetchall() is None: + cursor.close() + cnx.disconnect() + raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', + description='API.WEB_MESSAGE_NOT_FOUND') + + update_row = (" UPDATE tbl_web_messages " + " SET status = %s, reply = %s " + " WHERE status = %s AND user_id = %s ") + cursor.execute(update_row, (status, + reply, + 'new', + user_id,)) + cnx.commit() + + cursor.close() + cnx.disconnect() + + resp.status = falcon.HTTP_200 + class WebMessageItem: @staticmethod diff --git a/web/src/components/MyEMS/Notification/Notification.js b/web/src/components/MyEMS/Notification/Notification.js index c5de3b4b..377610b5 100644 --- a/web/src/components/MyEMS/Notification/Notification.js +++ b/web/src/components/MyEMS/Notification/Notification.js @@ -273,7 +273,49 @@ const Notification = ({ setRedirect, setRedirectUrl, t }) => { }).then(json => { console.log(isResponseOK); if (isResponseOK) { - + let isResponseOK = false; + fetch(APIBaseURL + '/webmessages?' + + 'startdatetime=' + startDatetime.format('YYYY-MM-DDTHH:mm:ss') + + '&enddatetime=' + endDatetime.format('YYYY-MM-DDTHH:mm:ss'), { + method: 'GET', + headers: { + "Content-type": "application/json", + "User-UUID": getCookieValue('user_uuid'), + "Token": getCookieValue('token') + }, + body: null, + + }).then(response => { + if (response.ok) { + isResponseOK = true; + } + return response.json(); + }).then(json => { + if (isResponseOK) { + console.log(json); + setFetchSuccess(true); + + let notificationList = [] + + if (json.length > 0) { + json.forEach((currentValue, index) => { + let notification = {} + notification['id'] = json[index]['id']; + notification['subject'] = json[index]['subject']; + notification['created_datetime'] = moment(parseInt(json[index]['created_datetime'])) + .format("YYYY-MM-DD HH:mm:ss"); + notification['message'] = json[index]['message']; + notification['status'] = json[index]['status']; + notification['url'] = json[index]['url']; + + notificationList.push(notification); + }); + } + + setNotifications(notificationList); + setSpinnerHidden(true); + } + }); } else { toast.error(json.description) } @@ -308,7 +350,49 @@ const Notification = ({ setRedirect, setRedirectUrl, t }) => { }).then(json => { console.log(isResponseOK); if (isResponseOK) { + let isResponseOK = false; + fetch(APIBaseURL + '/webmessages?' + + 'startdatetime=' + startDatetime.format('YYYY-MM-DDTHH:mm:ss') + + '&enddatetime=' + endDatetime.format('YYYY-MM-DDTHH:mm:ss'), { + method: 'GET', + headers: { + "Content-type": "application/json", + "User-UUID": getCookieValue('user_uuid'), + "Token": getCookieValue('token') + }, + body: null, + }).then(response => { + if (response.ok) { + isResponseOK = true; + } + return response.json(); + }).then(json => { + if (isResponseOK) { + console.log(json); + setFetchSuccess(true); + + let notificationList = [] + + if (json.length > 0) { + json.forEach((currentValue, index) => { + let notification = {} + notification['id'] = json[index]['id']; + notification['subject'] = json[index]['subject']; + notification['created_datetime'] = moment(parseInt(json[index]['created_datetime'])) + .format("YYYY-MM-DD HH:mm:ss"); + notification['message'] = json[index]['message']; + notification['status'] = json[index]['status']; + notification['url'] = json[index]['url']; + + notificationList.push(notification); + }); + } + + setNotifications(notificationList); + setSpinnerHidden(true); + } + }); } else { toast.error(json.description) } @@ -338,7 +422,49 @@ const Notification = ({ setRedirect, setRedirectUrl, t }) => { }).then(json => { console.log(isResponseOK); if (isResponseOK) { + let isResponseOK = false; + fetch(APIBaseURL + '/webmessages?' + + 'startdatetime=' + startDatetime.format('YYYY-MM-DDTHH:mm:ss') + + '&enddatetime=' + endDatetime.format('YYYY-MM-DDTHH:mm:ss'), { + method: 'GET', + headers: { + "Content-type": "application/json", + "User-UUID": getCookieValue('user_uuid'), + "Token": getCookieValue('token') + }, + body: null, + }).then(response => { + if (response.ok) { + isResponseOK = true; + } + return response.json(); + }).then(json => { + if (isResponseOK) { + console.log(json); + setFetchSuccess(true); + + let notificationList = [] + + if (json.length > 0) { + json.forEach((currentValue, index) => { + let notification = {} + notification['id'] = json[index]['id']; + notification['subject'] = json[index]['subject']; + notification['created_datetime'] = moment(parseInt(json[index]['created_datetime'])) + .format("YYYY-MM-DD HH:mm:ss"); + notification['message'] = json[index]['message']; + notification['status'] = json[index]['status']; + notification['url'] = json[index]['url']; + + notificationList.push(notification); + }); + } + + setNotifications(notificationList); + setSpinnerHidden(true); + } + }); } else { toast.error(json.description) } diff --git a/web/src/components/navbar/NotificationDropdown.js b/web/src/components/navbar/NotificationDropdown.js index 002a0f89..ff718680 100644 --- a/web/src/components/navbar/NotificationDropdown.js +++ b/web/src/components/navbar/NotificationDropdown.js @@ -83,10 +83,9 @@ const NotificationDropdown = ({ t }) => { const markAsRead = e => { e.preventDefault(); - rawNewNotificationschild.map((notification,index) => { - console.log('Mark As Read: ', notification["id"]) - let isResponseOK = false; - fetch(APIBaseURL + '/webmessages/' + notification["id"], { + + let isResponseOK = false; + fetch(APIBaseURL + '/webmessagesnew', { method: 'PUT', headers: { "Content-type": "application/json", @@ -108,14 +107,58 @@ const NotificationDropdown = ({ t }) => { }).then(json => { console.log(isResponseOK); if (isResponseOK) { + let isResponseOK = false; + fetch(APIBaseURL + '/webmessagesnew', { + method: 'GET', + headers: { + "Content-type": "application/json", + "User-UUID": getCookieValue('user_uuid'), + "Token": getCookieValue('token') + }, + body: null, + }).then(response => { + console.log(response); + if (response.ok) { + isResponseOK = true; + } + return response.json(); + }).then(json => { + console.log(json) + if (isResponseOK) { + let NewnotificationList = [] + if (json.length > 0) { + json.forEach((currentValue, index) => { + let notification = {} + notification['id'] = json[index]['id']; + notification['status'] = json[index]['status']; + notification['subject'] = json[index]['subject'] + notification['message'] = json[index]['message']; + notification['created_datetime'] = moment(parseInt(json[index]['created_datetime'])) + .format("YYYY-MM-DD HH:mm:ss"); + if (NewnotificationList.length > 3 ){ + return true + } + if (notification['message'].length > 40){ + notification['message'] = notification['message'].substring(0,30) + "..."; + } + if (notification["status"] === "new"){ + NewnotificationList.push(notification); + } + + }); + } + setRawNewNotificationschild(NewnotificationList); + } + }).catch(err => { + console.log(err); + }); } else { toast.error(json.description) } }).catch(err => { console.log(err); }); - }); }; From 93f9641d8b693c2e4be9db55c683cc94f5c2eb23 Mon Sep 17 00:00:00 2001 From: "13621160019@163.com" <13621160019@163.com> Date: Thu, 17 Feb 2022 18:54:54 +0800 Subject: [PATCH 2/5] added Mark All As Read action to notification --- myems-api/MyEMS.postman_collection.json | 68 +++++++++++++++++++++++++ myems-api/core/webmessage.py | 28 +++++----- 2 files changed, 82 insertions(+), 14 deletions(-) diff --git a/myems-api/MyEMS.postman_collection.json b/myems-api/MyEMS.postman_collection.json index ffabe142..3fa925ce 100644 --- a/myems-api/MyEMS.postman_collection.json +++ b/myems-api/MyEMS.postman_collection.json @@ -9655,6 +9655,74 @@ }, "response": [] }, + { + "name": "PUT Update All New Web Messages (Mark All As Read)", + "request": { + "method": "PUT", + "header": [ + { + "key": "User-UUID", + "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", + "type": "text", + "description": "Any admin users' UUID" + }, + { + "key": "Token", + "value": "597881540b33791a032b95aa48e0de098dc95ec0b813edd8a92cee87ee5eed1b8db7856a047ed06324c333bf2c98f0c7613e346ae25d1bcae3994f30b4562dfb", + "type": "text", + "description": "Login to get a valid token" + } + ], + "body": { + "mode": "raw", + "raw": "{\"data\":{\"status\":\"read\"}}" + }, + "url": { + "raw": "{{base_url}}/webmessagesnew", + "host": [ + "{{base_url}}" + ], + "path": [ + "webmessagesnew" + ] + } + }, + "response": [] + }, + { + "name": "PUT Update All New Web Messages (Acknowledge All)", + "request": { + "method": "PUT", + "header": [ + { + "key": "User-UUID", + "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", + "type": "text", + "description": "Any admin users' UUID" + }, + { + "key": "Token", + "value": "597881540b33791a032b95aa48e0de098dc95ec0b813edd8a92cee87ee5eed1b8db7856a047ed06324c333bf2c98f0c7613e346ae25d1bcae3994f30b4562dfb", + "type": "text", + "description": "Login to get a valid token" + } + ], + "body": { + "mode": "raw", + "raw": "{\"data\":{\"status\":\"acknowledged\", \"reply\":\"OK\"}}" + }, + "url": { + "raw": "{{base_url}}/webmessagesnew", + "host": [ + "{{base_url}}" + ], + "path": [ + "webmessagesnew" + ] + } + }, + "response": [] + }, { "name": "GET a Web Message by ID", "request": { diff --git a/myems-api/core/webmessage.py b/myems-api/core/webmessage.py index ac75d902..6475495a 100644 --- a/myems-api/core/webmessage.py +++ b/myems-api/core/webmessage.py @@ -265,13 +265,13 @@ class WebMessageStatusNewCollection: status = str.strip(new_values['data']['status']) # reply is required for 'acknowledged' status - if status == 'acknowledged' and \ - ('reply' not in new_values['data'].keys() or - not isinstance(new_values['data']['reply'], str) or - len(str.strip(new_values['data']['reply'])) == 0): - raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', - description='API.INVALID_REPLY') - reply = str.strip(new_values['data']['reply']) + if status == 'acknowledged': + if 'reply' not in new_values['data'].keys() or \ + not isinstance(new_values['data']['reply'], str) or \ + len(str.strip(new_values['data']['reply'])) == 0: + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_REPLY') + else: + reply = str.strip(new_values['data']['reply']) else: reply = None @@ -485,13 +485,13 @@ class WebMessageItem: status = str.strip(new_values['data']['status']) # reply is required for 'acknowledged' status - if status == 'acknowledged' and \ - ('reply' not in new_values['data'].keys() or - not isinstance(new_values['data']['reply'], str) or - len(str.strip(new_values['data']['reply'])) == 0): - raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', - description='API.INVALID_REPLY') - reply = str.strip(new_values['data']['reply']) + if status == 'acknowledged': + if 'reply' not in new_values['data'].keys() or \ + not isinstance(new_values['data']['reply'], str) or \ + len(str.strip(new_values['data']['reply'])) == 0: + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_REPLY') + else: + reply = str.strip(new_values['data']['reply']) else: reply = None From 8ac293d4b300912a20197dc7a1e6f6a7a6111fb7 Mon Sep 17 00:00:00 2001 From: "13621160019@163.com" <13621160019@163.com> Date: Thu, 17 Feb 2022 18:55:31 +0800 Subject: [PATCH 3/5] added Mark All As Read action to notification --- .../components/navbar/NotificationDropdown.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/web/src/components/navbar/NotificationDropdown.js b/web/src/components/navbar/NotificationDropdown.js index ff718680..2b300d02 100644 --- a/web/src/components/navbar/NotificationDropdown.js +++ b/web/src/components/navbar/NotificationDropdown.js @@ -42,7 +42,7 @@ const NotificationDropdown = ({ t }) => { }).then(json => { console.log(json) if (isResponseOK) { - let NewnotificationList = [] + let NewNotificationList = [] if (json.length > 0) { json.forEach((currentValue, index) => { let notification = {} @@ -52,19 +52,19 @@ const NotificationDropdown = ({ t }) => { notification['message'] = json[index]['message']; notification['created_datetime'] = moment(parseInt(json[index]['created_datetime'])) .format("YYYY-MM-DD HH:mm:ss"); - if (NewnotificationList.length > 3 ){ + if (NewNotificationList.length > 3 ){ return true } if (notification['message'].length > 40){ notification['message'] = notification['message'].substring(0,30) + "..."; } if (notification["status"] === "new"){ - NewnotificationList.push(notification); + NewNotificationList.push(notification); } }); } - setRawNewNotificationschild(NewnotificationList); + setRawNewNotificationschild(NewNotificationList); } }).catch(err => { console.log(err); @@ -126,7 +126,7 @@ const NotificationDropdown = ({ t }) => { }).then(json => { console.log(json) if (isResponseOK) { - let NewnotificationList = [] + let NewNotificationList = [] if (json.length > 0) { json.forEach((currentValue, index) => { let notification = {} @@ -136,19 +136,19 @@ const NotificationDropdown = ({ t }) => { notification['message'] = json[index]['message']; notification['created_datetime'] = moment(parseInt(json[index]['created_datetime'])) .format("YYYY-MM-DD HH:mm:ss"); - if (NewnotificationList.length > 3 ){ + if (NewNotificationList.length > 3 ){ return true } if (notification['message'].length > 40){ notification['message'] = notification['message'].substring(0,30) + "..."; } if (notification["status"] === "new"){ - NewnotificationList.push(notification); + NewNotificationList.push(notification); } }); } - setRawNewNotificationschild(NewnotificationList); + setRawNewNotificationschild(NewNotificationList); } }).catch(err => { console.log(err); From ab4bb773f05eb4cd929b16be7c490bda25b50ae8 Mon Sep 17 00:00:00 2001 From: "13621160019@163.com" <13621160019@163.com> Date: Fri, 18 Feb 2022 11:56:50 +0800 Subject: [PATCH 4/5] updated docker-compose guide --- docker-compose-cn.md | 35 ++++++++++------------- docker-compose-de.md | 67 ++++++++++++++++++++------------------------ docker-compose-en.md | 43 +++++++++++++--------------- 3 files changed, 65 insertions(+), 80 deletions(-) diff --git a/docker-compose-cn.md b/docker-compose-cn.md index 3a6633ad..0549b34b 100644 --- a/docker-compose-cn.md +++ b/docker-compose-cn.md @@ -9,16 +9,14 @@ ### 配置 -注一:这里的主机指的是**安装Docker的主机**, 这里的IP和账号密码都为假定的,用来展示说明,实际情况中用户需要根据自己的配置改为自己的,具体的修改步骤会在“安装”中讲述。 +**注**:这里的主机指的是安装Docker的主机, 这里的IP和账号密码都为假定的,用来展示说明,请酌情修改。 -注二:这里如果**安装数据库和安装Docker的主机为同一个主机,那么数据库IP和主机IP修改为一个实际IP**即可,这里是以数据库,和安装Docker的主机不在同一个上举例的。 - -| -- | -- | -| ---------- | ----------- | -| 主机IP | 192.168.0.1 | -| 数据库IP | 192.168.0.2 | -| 数据库账号 | root | -| 数据库密码 | !MyEMS1 | +| -- | -- | +| ---------- | ----------- | +| Host IP | 192.168.0.1 | +| Database IP | 192.168.0.2 | +| Database User | root | +| Database Password | !MyEMS1 | ### 安装 @@ -33,8 +31,10 @@ git clone https://gitee.com/myems/myems.git cd myems/database/install mysql -u root -p < myems_billing_baseline_db.sql mysql -u root -p < myems_billing_db.sql +mysql -u root -p < myems_carbon_db.sql mysql -u root -p < myems_energy_baseline_db.sql mysql -u root -p < myems_energy_db.sql +mysql -u root -p < myems_energy_model_db.sql mysql -u root -p < myems_fdd_db.sql mysql -u root -p < myems_historical_db.sql mysql -u root -p < myems_reporting_db.sql @@ -57,12 +57,11 @@ sed -i 's/127.0.0.1:8000/192.168.0.1:8000/g' web/nginx.conf 3.2 复制example.env为.env并修改.env里的数据库IP,账号,密码 ``` -# 这里以修改数据库IP为例,如果数据库账号密码也不同,请根据自己需求替换.env里的账号密码 cd myems -cp myems-api/example.env myems-api/.env -sed -i 's/127.0.0.1/192.168.0.2/g' myems-api/.env cp myems-aggregation/example.env myems-aggregation/.env sed -i 's/127.0.0.1/192.168.0.2/g' myems-aggregation/.env +cp myems-api/example.env myems-api/.env +sed -i 's/127.0.0.1/192.168.0.2/g' myems-api/.env cp myems-cleaning/example.env myems-cleaning/.env sed -i 's/127.0.0.1/192.168.0.2/g' myems-cleaning/.env cp myems-modbus-tcp/example.env myems-modbus-tcp/.env @@ -76,12 +75,6 @@ sed -i 's/127.0.0.1/192.168.0.2/g' myems-normalization/.env 如果是Linux主机,在api和admin服务中,volumes/source使用 /upload 应确保api和admin共享同一主机文件夹。 -3.4 验证数据库连接 -``` -cd myems -python3 myems-api/test_mysql.py -``` - 4. 编译Web UI ``` @@ -99,12 +92,14 @@ docker-compose up -d 6. 验证 -| | 网址 | 结果 | +| | 网址 | 期望结果 | | ----- | ----------------------- | ---------------- | | web | 192.168.0.1:80 | 输入账号密码登录成功 | | admin | 192.168.0.1:8001 | 输入账号密码登录成功 | | api | 192.168.0.1:8000/version| 返回版本信息 | -注:如果api报错,请确认.env里的数据库IP,数据库账号,数据库密码是否正确,如果不正确,请修改.env后执行: + +**注**:如果api报错,请确认.env里的数据库IP,数据库账号,数据库密码是否正确,如果不正确,请修改后执行: + ``` docker-compose up --build -d ``` diff --git a/docker-compose-de.md b/docker-compose-de.md index 041d7617..1dec6388 100644 --- a/docker-compose-de.md +++ b/docker-compose-de.md @@ -1,67 +1,67 @@ ## Docker Compose -Create and start all the services with a single command +Erstellen und starten Sie alle Dienste mit einem einzigen Befehl -### Prerequisite +### Voraussetzung -- Installed docker、docker-compose、npm on a host. +- Installed docker, docker-compose, npm on a host. - Installed MySQL database with username 'root' and password '!MyEMS1'. - The MySQL database can be connected from the host where Docker is installed. -### Configuration +### Konfiguration -Note 1: 这里的主机指的是**安装Docker的主机**, 这里的IP和账号密码都为假定的,用来展示说明,实际情况中用户需要根据自己的配置改为自己的,具体的修改步骤会在“安装”中讲述。 +**Anmerkung**: Der Host hier bezieht sich auf den Host, auf dem Docker installiert ist. Die IP und das Account-Passwort werden hier angenommen und verwendet, um Anweisungen anzuzeigen. Bitte ändern Sie sie entsprechend. -Note 2: 这里如果**安装数据库和安装Docker的主机为同一个主机,那么数据库IP和主机IP修改为一个实际IP**即可,这里是以数据库,和安装Docker的主机不在同一个上举例的。 - -| -- | -- | -| ---------- | ----------- | -| Host IP | 192.168.0.1 | -| Database IP | 192.168.0.2 | -| Database User | root | -| Database Password | !MyEMS1 | +| -- | -- | +| ---------- | ----------- | +| Host IP | 192.168.0.1 | +| Database IP | 192.168.0.2 | +| Database User | root | +| Database Password | !MyEMS1 | ### Installation -1. Clone repository +1. Repository klonen ``` git clone https://gitee.com/myems/myems.git ``` -2. Import database schema +2. Datenbankschema importieren ``` cd myems/database/install mysql -u root -p < myems_billing_baseline_db.sql mysql -u root -p < myems_billing_db.sql +mysql -u root -p < myems_carbon_db.sql mysql -u root -p < myems_energy_baseline_db.sql mysql -u root -p < myems_energy_db.sql +mysql -u root -p < myems_energy_model_db.sql mysql -u root -p < myems_fdd_db.sql mysql -u root -p < myems_historical_db.sql mysql -u root -p < myems_reporting_db.sql mysql -u root -p < myems_system_db.sql mysql -u root -p < myems_user_db.sql ``` -Note: Refer to [database/README.md](./database/README.md) +Anmerkung: Siehe unter [database/README.md](./database/README.md) -3. Modify Config +3. Konfiguration ändern -注:如“配置”所述,这里假定的**主机IP为 192.168.0.1,数据库IP为 192.168.0.2,数据库账号为:root,数据库密码:!MyEMS1,用户应该修改为自己对应的主机IP,数据库IP,数据库账号,数据库密码** +**Anmerkungen**:Die Host-IP hier angenommen ist 192.168.0.1, die Datenbank-IP ist 192.168.0.2, das Datenbank-Konto ist: root und das Datenbank-Passwort ist: !MyEMS1, bitte ändern Sie dies entsprechend -3.1 Modify api address in nginx.conf +3.1 API-Adresse ändern in nginx.conf ``` cd myems sed -i 's/127.0.0.1:8000/192.168.0.1:8000/g' admin/nginx.conf sed -i 's/127.0.0.1:8000/192.168.0.1:8000/g' web/nginx.conf ``` -3.2 Copy example.env to .env and modify database IP, username and password in .env +3.2 Beispiel example.env bis .env und Datenbank-IP, Benutzername und Passwort in .env ``` cd myems -cp myems-api/example.env myems-api/.env -sed -i 's/127.0.0.1/192.168.0.2/g' myems-api/.env cp myems-aggregation/example.env myems-aggregation/.env sed -i 's/127.0.0.1/192.168.0.2/g' myems-aggregation/.env +cp myems-api/example.env myems-api/.env +sed -i 's/127.0.0.1/192.168.0.2/g' myems-api/.env cp myems-cleaning/example.env myems-cleaning/.env sed -i 's/127.0.0.1/192.168.0.2/g' myems-cleaning/.env cp myems-modbus-tcp/example.env myems-modbus-tcp/.env @@ -70,18 +70,12 @@ cp myems-normalization/example.env myems-normalization/.env sed -i 's/127.0.0.1/192.168.0.2/g' myems-normalization/.env ``` -3.3 Modify upload folder in docker-compose.yml +3.3 Upload-Ordner ändern in docker-compose.yml If Windows host, use c:\upload for volumes/source in api and admin services. If Linux host, use /upload for volumes/source in api and admin services. Make sure the upload folders in api and admin are same folder on host. -3.4 Validate database connection -``` -cd myems -python3 myems-api/test_mysql.py -``` - -4. Build Web UI +4. Web UI erstellen ``` cd myems/web @@ -89,7 +83,7 @@ npm i --unsafe-perm=true --allow-root --legacy-peer-deps npm run build ``` -5. Run docker-compose command +5. Befehl Docker-compose ausführen ``` cd myems @@ -98,12 +92,13 @@ docker-compose up -d 6. Verification -| | Address | Result | +| | Address | Erwartetes Ergebnis | | ----- | ----------------------- | ---------------- | -| web | 192.168.0.1:80 | 输入账号密码登录成功 | -| admin | 192.168.0.1:8001 | 输入账号密码登录成功 | -| api | 192.168.0.1:8000/version| 返回版本信息 | -注:如果api报错,请确认.env里的数据库IP,数据库账号,数据库密码是否正确,如果不正确,请修改.env后执行: +| web | 192.168.0.1:80 | Login erfolgreich durch Eingabe von Konto und Passwort | +| admin | 192.168.0.1:8001 | Login erfolgreich durch Eingabe von Konto und Passwort | +| api | 192.168.0.1:8000/version| Versionsinformationen zurückgeben | + +**注**:Wenn die API einen Fehler meldet, bestätigen Sie bitte, ob die Datenbank-IP, das Datenbankkonto und das Datenbankkennwort in .env sind korrekt. Wenn nicht, ändern Sie sie bitte und führen Sie: ``` docker-compose up --build -d ``` diff --git a/docker-compose-en.md b/docker-compose-en.md index 041d7617..e80863d1 100644 --- a/docker-compose-en.md +++ b/docker-compose-en.md @@ -3,22 +3,20 @@ Create and start all the services with a single command ### Prerequisite -- Installed docker、docker-compose、npm on a host. +- Installed docker, docker-compose, npm on a host. - Installed MySQL database with username 'root' and password '!MyEMS1'. - The MySQL database can be connected from the host where Docker is installed. ### Configuration -Note 1: 这里的主机指的是**安装Docker的主机**, 这里的IP和账号密码都为假定的,用来展示说明,实际情况中用户需要根据自己的配置改为自己的,具体的修改步骤会在“安装”中讲述。 +**Note**: The host here refers to the host where docker is installed. The IP and account password here are assumed and used to show instructions. Please modify them as appropriate. -Note 2: 这里如果**安装数据库和安装Docker的主机为同一个主机,那么数据库IP和主机IP修改为一个实际IP**即可,这里是以数据库,和安装Docker的主机不在同一个上举例的。 - -| -- | -- | -| ---------- | ----------- | -| Host IP | 192.168.0.1 | -| Database IP | 192.168.0.2 | -| Database User | root | -| Database Password | !MyEMS1 | +| -- | -- | +| ---------- | ----------- | +| Host IP | 192.168.0.1 | +| Database IP | 192.168.0.2 | +| Database User | root | +| Database Password | !MyEMS1 | ### Installation @@ -33,8 +31,10 @@ git clone https://gitee.com/myems/myems.git cd myems/database/install mysql -u root -p < myems_billing_baseline_db.sql mysql -u root -p < myems_billing_db.sql +mysql -u root -p < myems_carbon_db.sql mysql -u root -p < myems_energy_baseline_db.sql mysql -u root -p < myems_energy_db.sql +mysql -u root -p < myems_energy_model_db.sql mysql -u root -p < myems_fdd_db.sql mysql -u root -p < myems_historical_db.sql mysql -u root -p < myems_reporting_db.sql @@ -46,7 +46,7 @@ Note: Refer to [database/README.md](./database/README.md) 3. Modify Config -注:如“配置”所述,这里假定的**主机IP为 192.168.0.1,数据库IP为 192.168.0.2,数据库账号为:root,数据库密码:!MyEMS1,用户应该修改为自己对应的主机IP,数据库IP,数据库账号,数据库密码** +**Note**:The host IP assumed here is 192.168.0.1, the database IP is 192.168.0.2, the database account is: root, and the database password is: !MyEMS1, please modify as appropriate 3.1 Modify api address in nginx.conf ``` @@ -58,10 +58,10 @@ sed -i 's/127.0.0.1:8000/192.168.0.1:8000/g' web/nginx.conf 3.2 Copy example.env to .env and modify database IP, username and password in .env ``` cd myems -cp myems-api/example.env myems-api/.env -sed -i 's/127.0.0.1/192.168.0.2/g' myems-api/.env cp myems-aggregation/example.env myems-aggregation/.env sed -i 's/127.0.0.1/192.168.0.2/g' myems-aggregation/.env +cp myems-api/example.env myems-api/.env +sed -i 's/127.0.0.1/192.168.0.2/g' myems-api/.env cp myems-cleaning/example.env myems-cleaning/.env sed -i 's/127.0.0.1/192.168.0.2/g' myems-cleaning/.env cp myems-modbus-tcp/example.env myems-modbus-tcp/.env @@ -75,12 +75,6 @@ If Windows host, use c:\upload for volumes/source in api and admin services. If Linux host, use /upload for volumes/source in api and admin services. Make sure the upload folders in api and admin are same folder on host. -3.4 Validate database connection -``` -cd myems -python3 myems-api/test_mysql.py -``` - 4. Build Web UI ``` @@ -98,12 +92,13 @@ docker-compose up -d 6. Verification -| | Address | Result | +| | Address | Expected Result | | ----- | ----------------------- | ---------------- | -| web | 192.168.0.1:80 | 输入账号密码登录成功 | -| admin | 192.168.0.1:8001 | 输入账号密码登录成功 | -| api | 192.168.0.1:8000/version| 返回版本信息 | -注:如果api报错,请确认.env里的数据库IP,数据库账号,数据库密码是否正确,如果不正确,请修改.env后执行: +| web | 192.168.0.1:80 | Login succeeded by entering account and password | +| admin | 192.168.0.1:8001 | Login succeeded by entering account and password | +| api | 192.168.0.1:8000/version| Return version information | + +**Note**:If the API reports an error, please confirm Whether the database IP, database account and database password in .env are correct. If not, please modify them then execute: ``` docker-compose up --build -d ``` From 46167e18391bb7f2e497d25dc7f891d1df27c857 Mon Sep 17 00:00:00 2001 From: tianlinzhong <673359306@qq.com> Date: Fri, 18 Feb 2022 14:28:27 +0800 Subject: [PATCH 5/5] fixed Web UI NotificationDown bug --- web/src/components/navbar/NotificationDropdown.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/web/src/components/navbar/NotificationDropdown.js b/web/src/components/navbar/NotificationDropdown.js index 2b300d02..0b52b8f8 100644 --- a/web/src/components/navbar/NotificationDropdown.js +++ b/web/src/components/navbar/NotificationDropdown.js @@ -63,7 +63,9 @@ const NotificationDropdown = ({ t }) => { } }); - } + }else { + setIsAllRead(true); + } setRawNewNotificationschild(NewNotificationList); } }).catch(err => { @@ -147,7 +149,9 @@ const NotificationDropdown = ({ t }) => { } }); - } + }else { + setIsAllRead(true); + } setRawNewNotificationschild(NewNotificationList); } }).catch(err => {