From 6d9939b585626214e21e2ab76dce6bc719461f8a Mon Sep 17 00:00:00 2001 From: hyh123a Date: Sat, 23 Apr 2022 10:36:01 +0800 Subject: [PATCH] modify the svg --- database/upgrade/upgrade_svg.sql | 27 --- myems-api/app.py | 22 +- myems-api/pro/svg.py | 172 ---------------- .../MyEMS/AuxiliarySystem/SvgSystem.js | 192 ------------------ myems-web/src/layouts/MyEMSRoutes.js | 5 +- myems-web/src/routes.js | 2 +- 6 files changed, 21 insertions(+), 399 deletions(-) delete mode 100644 database/upgrade/upgrade_svg.sql delete mode 100644 myems-api/pro/svg.py delete mode 100644 myems-web/src/components/MyEMS/AuxiliarySystem/SvgSystem.js diff --git a/database/upgrade/upgrade_svg.sql b/database/upgrade/upgrade_svg.sql deleted file mode 100644 index fb39e9d2..00000000 --- a/database/upgrade/upgrade_svg.sql +++ /dev/null @@ -1,27 +0,0 @@ -/* - Source Schema : myems_system_db - Date: 22/04/2022 20:12:20 -*/ - --- --------------------------------------------------------------------------------------------------------------------- --- Table `myems_system_db`.`tbl_svgs` --- --------------------------------------------------------------------------------------------------------------------- -DROP TABLE IF EXISTS `myems_system_db`.`tbl_svgs` ; -CREATE TABLE `myems_system_db`.`tbl_svgs` ( - `id` BIGINT NOT NULL AUTO_INCREMENT, - `name` VARCHAR(128) NOT NULL, - `content` LONGTEXT NOT NULL, - PRIMARY KEY (`id`) -); - --- --------------------------------------------------------------------------------------------------------------------- --- Records of `myems_system_db`.`tbl_svgs` --- --------------------------------------------------------------------------------------------------------------------- -INSERT INTO `myems_system_db`.`tbl_svgs` VALUES (1, 'SVG01', '\r\n\r\n\r\n\r\n\r\n \r\n 1WT603\r\n \r\n \r\n 603变温度控制器\r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n \r\n 1WT604\r\n \r\n \r\n 604变温度控制器\r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n888888\r\n888888\r\n888888\r\n888888\r\n888888\r\n888888\r\n\r\n'); -INSERT INTO `myems_system_db`.`tbl_svgs` VALUES (2, 'SVG02', '\r\n\r\n\r\n888888\r\n\r\n888888\r\n\r\n'); - - --- --------------------------------------------------------------------------------------------------------------------- --- Records of `myems_system_db`.`tbl_menus` --- --------------------------------------------------------------------------------------------------------------------- -INSERT INTO `myems_system_db`.`tbl_menus`(`id`, `name`, `route`, `parent_menu_id`, `is_hidden`) VALUES (803, 'Svg System', '/auxiliarysystem/svgsystem', 800, 0); diff --git a/myems-api/app.py b/myems-api/app.py index 8b3343b3..7e21259b 100644 --- a/myems-api/app.py +++ b/myems-api/app.py @@ -85,7 +85,7 @@ from reports import virtualmetercost ######################################################################################################################## # BEGIN imports for Enterprise Version ######################################################################################################################## -from pro import svg +# from pro import svg ######################################################################################################################## # END imports for Enterprise Version @@ -650,10 +650,22 @@ api.add_route('/reports/virtualmetercost', ######################################################################################################################## # BEGIN Routes for Enterprise Edition ######################################################################################################################## -api.add_route('/svgs', - svg.Collection()) -api.add_route('/svgs/{id_}', - svg.Item()) + +######################################################################################################################## +# Routes for Svg System +######################################################################################################################## + +""" +# Name: Svg System +# Web UI Router: auxiliarysystem/svgsystem +# API File: myems-api/pro/svg.py +""" +# api.add_route('/svgs', +# svg.Collection()) +# api.add_route('/svgs/{id_}', +# svg.Item()) + + ######################################################################################################################## # END Routes for Enterprise Edition ######################################################################################################################## diff --git a/myems-api/pro/svg.py b/myems-api/pro/svg.py deleted file mode 100644 index 3f67ccaa..00000000 --- a/myems-api/pro/svg.py +++ /dev/null @@ -1,172 +0,0 @@ -import re - -import falcon -import simplejson as json -import mysql.connector -import config -from core.useractivity import user_logger, access_control - - -class Collection: - @staticmethod - def __init__(): - """"Initializes svgCollection""" - pass - - @staticmethod - def on_options(req, resp): - resp.status = falcon.HTTP_200 - - @staticmethod - def on_get(req, resp): - cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) - - query = (" SELECT id, name " - " FROM tbl_svgs " - " ORDER BY id ") - cursor.execute(query) - rows_svgs = cursor.fetchall() - - result = list() - if rows_svgs is not None and len(rows_svgs) > 0: - for row in rows_svgs: - temp = {"id": row['id'], - "name": row['name']} - - result.append(temp) - - cursor.close() - cnx.disconnect() - resp.text = json.dumps(result) - - -class Item: - @staticmethod - def __init__(): - """"Initializes svgItem""" - pass - - @staticmethod - def on_options(req, resp, id_): - resp.status = falcon.HTTP_200 - - @staticmethod - def on_get(req, resp, id_): - if not id_.isdigit() or int(id_) <= 0: - raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', - description='API.INVALID_svg_ID') - - cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) - - query = (" SELECT id, name, content " - " FROM tbl_svgs " - " WHERE id=%s ") - cursor.execute(query, (id_,)) - rows_svg = cursor.fetchone() - - result = None - if rows_svg is not None and len(rows_svg) > 0: - result = {"id": rows_svg['id'], - "name": rows_svg['name'], - "content": rows_svg['content']} - else: - cursor.close() - cnx.disconnect() - resp.text = json.dumps(result) - - tmp_content = result['content'] - # Get all ids - ids = re.findall(r'8*', tmp_content) # # ['PT100', 'PT101'] - # Get All Data - """ - 数据点 Point 代码 PT - 计量表 Meter 代号 MT - 虚拟表 VirtualMeter 代号 VM - 离线表 OfflineMeter 代码 OM - 空间 Space 代号 SP - 传感器 Sensor 代号 SS - 设备 Equipment 代号 EQ - 组合设备 CombinedEquipment 代码 CE - 车间 Shopfloor代码 SF - """ - _dict = { - 'PT': {}, - 'MT': {}, - 'VM': {}, - 'OM': {}, - 'SP': {}, - 'SS': {}, - 'EQ': {}, - 'CE': {}, - 'SF': {}, - } - - # Group the tag - for item in ids: - _type = item[0:2] - _number = item[2:] - if _type not in _dict.keys(): - print("Error Type", item) - continue - if _number not in _dict[_type].keys(): - _dict[_type][_number] = 111 - - # Todo: Get data from database - - # Replace - for item in ids: - r_type = item[0:2] - r_id = item[2:] - tmp_content = re.sub(r'.*?)>8*', - r' >' + str(_dict[r_type][r_id]) + '', - tmp_content) - - result['content'] = tmp_content - cursor.close() - cnx.disconnect() - resp.text = json.dumps(result) - - @staticmethod - @user_logger - def on_put(req, resp, id_): - """Handles PUT requests""" - access_control(req) - try: - raw_json = req.stream.read().decode('utf-8') - except Exception as ex: - raise falcon.HTTPError(falcon.HTTP_400, title='API.EXCEPTION', description=ex) - - if not id_.isdigit() or int(id_) <= 0: - raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', - description='API.INVALID_svg_ID') - - new_values = json.loads(raw_json) - - if 'name' not in new_values['data'].keys() or \ - not isinstance(new_values['data']['name'], str): - raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', - description='API.INVALID_NAME') - if 'content' not in new_values['data'].keys() or \ - not isinstance(new_values['data']['content'], str): - raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', - description='API.INVALID_CONTENT') - - name = new_values['data']['name'] - content = new_values['data']['content'] - - cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor() - update_row = (" UPDATE tbl_svgs " - " SET name = %s, content = %s " - " WHERE id = %s ") - cursor.execute(update_row, (name, - content, - id_)) - cnx.commit() - - cursor.close() - cnx.disconnect() - - resp.status = falcon.HTTP_200 diff --git a/myems-web/src/components/MyEMS/AuxiliarySystem/SvgSystem.js b/myems-web/src/components/MyEMS/AuxiliarySystem/SvgSystem.js deleted file mode 100644 index a94ccd66..00000000 --- a/myems-web/src/components/MyEMS/AuxiliarySystem/SvgSystem.js +++ /dev/null @@ -1,192 +0,0 @@ -import React, { createRef, Fragment, useState, useEffect } from 'react'; -import { - Breadcrumb, - BreadcrumbItem, - Card, - CardBody, - Col, - CustomInput, - Form, - FormGroup, - Label, - Modal, - ModalBody, - ModalFooter, - ModalHeader, - Row, - Spinner -} from 'reactstrap'; -import RealtimeChart from './RealtimeChart'; -import { getCookieValue, createCookie } from '../../../helpers/utils'; -import withRedirect from '../../../hoc/withRedirect'; -import { withTranslation } from 'react-i18next'; -import { toast } from 'react-toastify'; -import { APIBaseURL } from '../../../config'; - -const SvgSystem = ({ setRedirect, setRedirectUrl, t }) => { - useEffect(() => { - let is_logged_in = getCookieValue('is_logged_in'); - let user_name = getCookieValue('user_name'); - let user_display_name = getCookieValue('user_display_name'); - let user_uuid = getCookieValue('user_uuid'); - let token = getCookieValue('token'); - if (is_logged_in === null || !is_logged_in) { - setRedirectUrl(`/authentication/basic/login`); - setRedirect(true); - } else { - //update expires time of cookies - createCookie('is_logged_in', true, 1000 * 60 * 60 * 8); - createCookie('user_name', user_name, 1000 * 60 * 60 * 8); - createCookie('user_display_name', user_display_name, 1000 * 60 * 60 * 8); - createCookie('user_uuid', user_uuid, 1000 * 60 * 60 * 8); - createCookie('token', token, 1000 * 60 * 60 * 8); - } - }); - - // Svg List - const [svgSystemList, setSvgSystemList] = useState([]); - - // Query Parameters - const [selectedSvgSystemID, setSelectedSvgSystemID] = useState(undefined); - - // Results - const [svgSystemContent, setSvgSystemContent] = useState(undefined); - const [svgSystemContentDict, setSvgSystemContentDict] = useState(undefined); - - // Init: Get svgs and set the first svg - useEffect(() => { - let isResponseOK = false; - fetch(APIBaseURL + '/svgs', { - 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) { - setSvgSystemList(json); - setSelectedSvgSystemID(json[0].id); - getSvgContent(json[0].id); - } else { - toast.error(json.description); - } - }) - .catch(err => { - console.log(err); - }); - }, []); - - const labelClasses = 'ls text-uppercase text-600 font-weight-semi-bold mb-0'; - - // Select: Choose Svg - const onSvgSystemChange = event => { - setSelectedSvgSystemID(event.target.value); - console.log('You Change the Svg ID', event.target.value); - // Get Svg Content - getSvgContent(event.target.value); - }; - - // Fcuntion: Get Svg Content - const getSvgContent = svgId => { - let isResponseOK = false; - fetch(APIBaseURL + '/svgs/' + svgId, { - 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) { - setSvgSystemContent(json.content); - setSvgSystemContentDict({ __html: json.content }); - } else { - toast.error(json.description); - } - }) - .catch(err => { - console.log(err); - }); - }; - - useEffect(() => { - console.log('svgSystemList', svgSystemList); - }, [svgSystemList]); - - useEffect(() => { - console.log('svgSystemContent', svgSystemContent); - }, [svgSystemContent]); - - useEffect(() => { - console.log('selectedSvgSystemID', selectedSvgSystemID); - }, [selectedSvgSystemID]); - - useEffect(() => { - console.log('svgSystemContentDict', svgSystemContentDict); - }, [svgSystemContentDict]); - - return ( - -
- - {t('Auxiliary System')} - {t('Svg System')} - -
- - -
- - - - - - {svgSystemList.map((svgSystem, index) => ( - - ))} - - - - -
-
-
- -
- - - ); -}; - -export default withTranslation()(withRedirect(SvgSystem)); diff --git a/myems-web/src/layouts/MyEMSRoutes.js b/myems-web/src/layouts/MyEMSRoutes.js index 6ab4fa13..5c3193c0 100644 --- a/myems-web/src/layouts/MyEMSRoutes.js +++ b/myems-web/src/layouts/MyEMSRoutes.js @@ -177,6 +177,7 @@ import CombinedEquipmentStatistics from '../components/MyEMS/CombinedEquipment/C // Auxiliary System import EnergyFlowDiagram from '../components/MyEMS/AuxiliarySystem/EnergyFlowDiagram'; import DistributionSystem from '../components/MyEMS/AuxiliarySystem/DistributionSystem'; +// import SvgSystem from '../components/MyEMS/AuxiliarySystem/SvgSystem'; // FDD import FDDCombinedEquipmentFault from '../components/MyEMS/FDD/CombinedEquipmentFault'; import FDDEquipmentFault from '../components/MyEMS/FDD/EquipmentFault'; @@ -196,7 +197,7 @@ import AdvancedReporting from '../components/MyEMS/AdvancedReporting/AdvancedRep import KnowledgeBase from '../components/MyEMS/KnowledgeBase/KnowledgeBase'; // Notification import Notification from '../components/MyEMS/Notification/Notification'; -import SvgSystem from '../components/MyEMS/AuxiliarySystem/SvgSystem'; + // const InboxRoutes = ({ match: { url } }) => ( // @@ -423,7 +424,7 @@ const MyEMSRoutes = () => ( {/*Auxiliary System*/} - + {/* */} {/*FDD*/} diff --git a/myems-web/src/routes.js b/myems-web/src/routes.js index ee8e238b..a77111c4 100644 --- a/myems-web/src/routes.js +++ b/myems-web/src/routes.js @@ -444,7 +444,7 @@ export const auxiliarySystemRoutes = { children: [ { to: '/auxiliarysystem/energyflowdiagram', name: 'Energy Flow Diagram' }, { to: '/auxiliarysystem/distributionsystem', name: 'Distribution System' }, - { to: '/auxiliarysystem/svgsystem', name: 'Svg System' } + // { to: '/auxiliarysystem/svgsystem', name: 'Svg System' } ] };