Commit 2d47574f authored by wanli's avatar wanli

🌈 style(): 一些小更新

parent 0eb0a727
# -*- coding: utf-8 -*-
'''
Author: your name
Date: 2021-07-20 19:04:27
LastEditTime: 2021-07-21 20:01:56
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \evm-store\tools\database_migration.py
'''
import os
import sqlite3
import uuid
from datetime import datetime
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
print("####>>>", BASE_DIR)
start = datetime.now()
print("start at:", start.strftime("%Y-%m-%d %H:%M:%S"))
source_conn = sqlite3.connect(os.path.join(BASE_DIR, "app-store.db"))
source_cur = source_conn.cursor()
target_db = os.path.join(BASE_DIR, "evue-store.db")
target_conn = sqlite3.connect(target_db)
target_cur = source_conn.cursor()
with open("database_migration.sql", "w+") as fd:
# 更新user表
opts = [
[2, 39],
[3, 40],
[4, 41]
]
sqls = [
"update evm_store_apps set create_by = {a} where create_by = {b};",
"update evm_store_apps set update_by = {a} where update_by = {b};",
"update evm_store_annex set create_by = {a} where create_by = {b};",
"update evm_store_annex set update_by = {a} where update_by = {b};",
"update evm_store_app_logs set create_by = {a} where create_by = {b};",
"update evm_store_build_logs set create_by = {a} where create_by = {b};",
"update evm_store_build_logs set update_by = {a} where update_by = {b};",
"update evm_store_device set create_by = {a} where create_by = {b};",
"update evm_store_device set update_by = {a} where update_by = {b};",
"update evm_store_login_logs set create_by = {a} where create_by = {b};",
]
for s in sqls:
for o in opts:
sql_str = s.format(a=o[0], b=o[1])
source_cur.execute(sql_str)
source_conn.commit()
# 更新app logs 表
sql_str = "select create_at from evm_store_app_logs"
source_cur.execute(sql_str)
res = source_cur.fetchall()
for line in res:
sql_str = "select id from evm_store_apps where strftime('%s', evm_store_apps.create_at) - strftime('%s', '{b}') < 2".format(b=line[0])
source_cur.execute(sql_str)
tmp = source_cur.fetchone()
if tmp:
sql_str = "UPDATE evm_store_app_logs SET remarks = {a};".format(a=tmp[0])
source_cur.execute(sql_str)
source_conn.commit()
# 先插入user表
source_cur.execute('SELECT account, username, password, email, phone, create_at, create_by, update_at, update_by FROM evm_store_user')
sql = "insert into evm_user (id, uuid, account, username, password, email, phone, create_at, create_by, update_at, update_by, is_delete, role) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', '{h}', {i}, '{j}', {k}, 0, 0);"
res = source_cur.fetchall()
i = 0
for line in res:
i += 1
sql_str = sql.format(a=i, b=uuid.uuid1().hex, c=line[0], d=line[1], e=line[2], f=line[3], g=line[4], h=line[5], i=line[6], j=line[7], k=line[8])
print("sql:", sql_str)
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
target_conn.commit()
# login logs
source_cur.execute('SELECT id, username, ip, address, create_at, create_by, remarks FROM evm_store_login_logs')
res = source_cur.fetchall()
sql = "insert into evm_login (uuid, user, login_at, user_agent, ip, geo_location, operator, create_at, create_by, update_at, update_by, is_delete) values ('{b}', {c}, '{d}', '{e}', '{f}', '{g}', '{h}', '{i}', {j}, '{k}', {l}, 0);"
for line in res:
sql_str = sql.format(b=uuid.uuid1().hex, c=line[5], d=line[6], e="", f=line[2], g=line[3], h="", i=line[4], j=line[5], k=line[4], l=line[5])
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
target_conn.commit()
# 更新app_url字段
sql = "select app, app_path from evm_store_build_logs"
source_cur.execute(sql)
res = source_cur.fetchall()
for line in res:
sql_str = string = "update evm_store_apps set app_url = '{u}' where id = {a}".format(u=line[1], a=line[0])
source_cur.execute(sql_str)
# fd.write(sql_str + "\n")
target_conn.commit()
# annex
source_cur.execute('SELECT id, uuid, app, title, path, size, create_at, create_by, update_at, update_by, is_delete FROM evm_store_annex')
res = source_cur.fetchall()
sql = "insert into evm_annex (id, uuid, app, title, path, size, create_at, create_by, update_at, update_by, is_delete) values ({a}, '{b}', {c}, '{d}', '{e}', {f}, '{g}', {h}, '{i}', {j}, 0);"
for line in res:
if not line[2]:
continue
sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=line[2], d=line[3], e=line[4] or "", f=line[5], g=line[6], h=line[7], i=line[8], j=line[9])
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
target_conn.commit()
# app
source_cur.execute('SELECT id, app_name, app_icon, app_version, category, app_url, app_desc, create_at, create_by ,update_at, update_by, is_delete FROM evm_store_apps')
res = source_cur.fetchall()
sql = "insert into evm_app (id, uuid, app_name, app_icon, app_version, category, download_url, app_screen_size, app_arch, app_review, meta_data, remarks, create_at, create_by, update_at, update_by, is_delete, launcher, developer, app_file_size) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', '{h}', '{i}', '{j}', '{k}', '{l}', '{m}', {n}, '{o}', {p}, 0, `""`, `""`, 0);"
for line in res:
sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=line[1], d=line[2], e=line[3], f=line[4], g=line[5], h="240 * 240", i="ASR3601", j=0, k='{}', l=line[6], m=line[7], n=line[8], o=line[9], p=line[10])
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
target_conn.commit()
# device
source_cur.execute('SELECT id, name, imei, desc, type, create_at, create_by, update_at, update_by, is_delete FROM evm_store_device')
res = source_cur.fetchall()
sql = "insert into evm_device (id, uuid, name, imei, desc, type, create_at, create_by, update_at, update_by, is_delete) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', {h}, '{i}', {j}, {k});"
for line in res:
sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=line[1], d=line[2], e=line[3], f=line[4], g=line[5], h=line[6], i=line[7], j=line[8], k=line[9])
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
target_conn.commit()
# app log & build log
# 先插入app log
source_cur.execute('SELECT id, uuid, app_name, app_path, app_version, app_info, create_at, create_by, remarks FROM evm_store_app_logs')
res = source_cur.fetchall()
sql = "insert into evm_package (id, uuid, app, app_path, app_version, app_info, create_at, create_by, update_at, update_by, is_delete, source) values ({a}, '{b}', '{c}', '{d}', '{e}', `'{f}'`, '{g}', {h}, '{i}', {j}, {k}, {l});"
for line in res:
# 根据时间查找app
print(">>>>>>>>>>>>", line[6], line[8])
if not line[8] or (isinstance(line[8], str) and len(line[8]) == 0):
print("remarks is none")
continue
sql_str = "select id from evm_store_apps where id = {a}".format(a=int(line[8]))
source_cur.execute(sql_str)
tmp = source_cur.fetchone()
if not tmp:
print("app not found")
continue
s = 1 if line[5] and isinstance(line[5], str) and line[5].find("evueapps") > -1 else 0
sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=tmp[0], d=line[3], e=line[4], f=line[5], g=line[6], h=line[7], i=line[6], j=line[7], k=0, l=s)
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
target_conn.commit()
# 然后查询出所有build log记录,遍历这些记录
# 在循环里,查询这一条记录是否已经存在(根据app_path),不存在则插入
source_cur.execute('SELECT id, uuid, app, app_path, app_info, source, create_at, create_by, update_at, update_by, is_delete FROM evm_store_build_logs')
res = source_cur.fetchall()
sql = "insert into evm_package (id, uuid, app_name, app_path, app_version, app_info, source, create_at, create_by, update_at, update_by, is_delete) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', {g}, '{h}', {i}, '{j}', {k}, {l});"
for line in res:
sql_str = "select id, uuid, app_path from evm_store_app_logs where app_path = '{}'".format(line[3])
source_cur.execute(sql_str)
tmp = source_cur.fetchone()
print("=======>", line[0])
if tmp:
print("app_path not equal")
continue
print("===========>", line)
sql_str = "select app_name, app_version from evm_store_apps where id == {id}".format(id=line[2])
source_cur.execute(sql_str)
app = source_cur.fetchone()
print("app:", app)
if app:
s = 1 if line[5] and isinstance(line[5], str) and line[5].find("evueapps") > -1 else 0
sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=app[0], d=line[3], e=app[1], f=line[4], g=s, h=line[6], i=line[7], j=line[8], k=line[9], l=line[10])
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
target_conn.commit()
print("next >>>>>>>>>>>")
print("finished!!!")
target_conn.commit()
target_conn.close()
source_conn.commit()
source_conn.close()
print("spend time:", datetime.now() - start)
\ No newline at end of file
/*
* @Author: your name
* @Date: 2021-07-01 15:02:16
* @LastEditTime: 2021-07-20 23:30:33
* @LastEditTime: 2021-07-21 16:16:36
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \evm-store\frontend\src\utils\eventBus.js
......
......@@ -252,9 +252,8 @@
:data="imageList"
size="mini"
border
stripe
fit
highlight-current-row
:row-class-name="tableRowClassName"
>
<el-table-column
prop="uri"
......@@ -405,6 +404,9 @@ export default {
SystemChart,
},
methods: {
tableRowClassName({ row }) {
return row.highlight ? "success-row" : "";
},
moveEvent(i, newX, newY) {
const msg = "MOVE i=" + i + ", X=" + newX + ", Y=" + newY;
console.log(msg);
......@@ -536,7 +538,8 @@ export default {
this.deviceList.push(msg.imei);
}
if (!this.device) {
if (this.deviceList && this.deviceList.length) this.device = this.deviceList[0];
if (this.deviceList && this.deviceList.length)
this.device = this.deviceList[0];
else this.device = msg.imei;
}
......@@ -575,37 +578,57 @@ export default {
this.evmList = [{ ...this.globalData.evm }];
this.lvglList = [{ ...this.globalData.lvgl }];
this.systemList = [{ imei: this.globalData.imei, ...this.globalData.system, ...this.globalData.request }];
this.systemList = [
{
imei: this.globalData.imei,
...this.globalData.system,
...this.globalData.request,
},
];
// 这里需要特殊处理下,先判断uri是否存在,不存在则添加,存在则更新
let uris = [];
this.imageList.forEach((img) => {
uris.push(img.uri);
this.imageList.forEach((item) => {
item.highlight = false;
uris.push(item.uri);
});
this.globalData.image &&
this.globalData.image.forEach((item) => {
const target = this.imageList.find(img => img.uri === item.uri)
if (item.png_uncompressed_size > 0) {
item.highlight = true;
} else {
item.highlight = false;
}
const target = this.imageList.find((img) => img.uri === item.uri);
if (target) {
if (item.png_uncompressed_size && item.png_uncompressed_size !== target.png_uncompressed_size)
target.png_uncompressed_size = item.png_uncompressed_size
if (item.png_file_size && item.png_file_size !== target.png_file_size)
target.png_file_size = item.png_file_size
target.length = item.length
target.png_total_count = item.png_total_count
target.length = item.length;
target.png_total_count = item.png_total_count;
target.highlight = false;
if (
item.png_uncompressed_size &&
item.png_uncompressed_size !== target.png_uncompressed_size
)
{
target.highlight = true;
target.png_uncompressed_size = item.png_uncompressed_size;
}
if (
item.png_file_size &&
item.png_file_size !== target.png_file_size
)
target.png_file_size = item.png_file_size;
} else {
this.imageList.push(item)
this.imageList.push(item);
}
});
if (this.globalData) {
if (this.globalData.evm)
this.evm = this.globalData.evm;
if (this.globalData.lvgl)
this.lvgl = this.globalData.lvgl;
if (this.globalData.image)
this.image = this.globalData.image;
if (this.globalData.system)
this.system = this.globalData.system;
if (this.globalData.evm) this.evm = this.globalData.evm;
if (this.globalData.lvgl) this.lvgl = this.globalData.lvgl;
if (this.globalData.image) this.image = this.globalData.image;
if (this.globalData.system) this.system = this.globalData.system;
}
},
},
......@@ -633,6 +656,8 @@ export default {
};
</script>
<style lang="scss" scoped>
@import "./style.css";
.app-container {
& > div.page-wrapper {
margin: 10px 0px;
......
.el-table .warning-row {
background: red;
}
.el-table .success-row {
background: greenyellow;
}
'''
Author: your name
Date: 2021-06-29 19:24:32
LastEditTime: 2021-07-20 01:18:45
LastEditTime: 2021-07-21 18:37:59
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \evm-store\backend\controller\monitor.py
......@@ -20,7 +20,11 @@ class SystemResource(object):
return MonitorSystemModel.query.all()
def post(self, params):
result = MonitorSystemModel(**params)
data = dict()
for k in params:
if hasattr(MonitorSystemModel, k):
data[k] = params[k]
result = MonitorSystemModel(**data)
db.session.add(result)
db.session.commit()
return True
......@@ -30,7 +34,11 @@ class LvglResource(object):
return MonitorLvglModel.query.all()
def post(self, params):
result = MonitorLvglModel(**params)
data = dict()
for k in params:
if hasattr(MonitorLvglModel, k):
data[k] = params[k]
result = MonitorLvglModel(**data)
db.session.add(result)
db.session.commit()
return True
......@@ -50,7 +58,11 @@ class ImageResource(object):
return MonitorImageModel.query.all()
def post(self, params):
result = MonitorImageModel(**params)
data = dict()
for k in params:
if hasattr(MonitorImageModel, k):
data[k] = params[k]
result = MonitorImageModel(**data)
db.session.add(result)
db.session.commit()
return True
......@@ -58,8 +70,13 @@ class ImageResource(object):
def post_array(self, array, watch):
t = []
for a in array:
a.update({ "watch": watch })
t.append(a)
data = dict()
for k in a:
if hasattr(MonitorImageModel, k):
data[k] = a[k]
data.update({ "watch": watch })
t.append(data)
db.session.execute(MonitorImageModel.__table__.insert(), t)
db.session.commit()
......@@ -72,32 +89,33 @@ imageResource = ImageResource()
def insert_data(msg):
# 先判断手表imei是否存在,不存在则先注册手表IMEI
watch_id = -1
if msg.get("imei"):
result = DeviceModel.query.filter_by(imei=msg.get("imei")).one_or_none()
if result:
watch_id = result.id
else:
result = DeviceModel(imei=msg.get("imei"))
db.session.add(result)
db.session.commit()
watch_id = result.id
device_id = -1
if not msg.get("imei"):
return None
result = DeviceModel.query.filter(DeviceModel.imei==msg.get("imei")).one_or_none()
if not result:
return None
device_id = result.id
if msg.get("system") or msg.get("request"):
msg.get("system", {}).update({ "watch": watch_id })
msg.get("system", {}).update({ "watch": device_id })
msg.get("system").update(msg.get("request", {}))
systemResource.post(msg.get("system"))
if msg.get("lvgl"):
msg.get("lvgl").update({ "watch": watch_id })
msg.get("lvgl").update({ "watch": device_id })
lvglResource.post(msg.get("lvgl"))
if msg.get("evm"):
msg.get("evm").update({ "watch": watch_id })
msg.get("evm").update({ "watch": device_id })
evmResource.post(msg.get("evm"))
if msg.get("image"):
imageResource.post_array(msg.get("image"), watch_id)
imageResource.post_array(msg.get("image"), device_id)
return True
def get_watch_list():
result = DeviceModel.query.all()
......
'''
Author: your name
Date: 2021-07-15 09:33:39
LastEditTime: 2021-07-21 18:39:45
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \evm-store\tools\build_out\models\monitorSystem.py
'''
#!/usr/bin/env python
# -*- coding: utf_8 -*-
......@@ -10,6 +18,8 @@ class MonitorSystemModel(PrimaryModel):
watch = db.Column(db.Integer, nullable = False)
free_size = db.Column(db.Integer, nullable = True, default = 0)
free_space_size = db.Column(db.Integer, nullable = True, default = 0)
used_space_size = db.Column(db.Integer, nullable = True, default = 0)
host = db.Column(db.String(20), index = True, nullable = False, default = '')
path = db.Column(db.String(20), index = True, nullable = False, default = '')
protocol = db.Column(db.String(20), index = True, nullable = False, default = '')
......@@ -18,9 +28,11 @@ class MonitorSystemModel(PrimaryModel):
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
# )
def __init__(self, watch, free_size=0, host='', path='', protocol=''):
def __init__(self, watch, free_size=0, free_space_size=0, used_space_size=0, host='', path='', protocol=''):
self.watch = watch
self.free_size = free_size
self.free_space_size = free_space_size
self.used_space_size = used_space_size
self.host = host
self.path = path
self.protocol = protocol
......@@ -32,6 +44,8 @@ class MonitorSystemModel(PrimaryModel):
return {
'watch': self.watch,
'free_size': self.free_size,
'free_space_size': self.free_space_size,
'used_space_size': self.used_space_size,
'host': self.host,
'path': self.path,
'protocol': self.protocol,
......
'''
Author: your name
Date: 2021-06-29 19:33:41
LastEditTime: 2021-07-20 01:20:45
LastEditTime: 2021-07-21 19:30:55
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \evm-store\backend\view\monitor.py
......@@ -121,7 +121,7 @@ class BaseWebsocket(WebSocketHandler):
@classmethod
def broadcastMessage(cls, message):
# pprint.pprint(message)
pprint.pprint(message)
print("=======>", cls._clients)
if not message.get("imei"):
......@@ -155,10 +155,9 @@ class NotifyHandler(BaseWebsocket):
className = self.__class__.__name__
message = json.loads(message)
# 判断消息类型
if message.get("type"):
if message.get("type") and message.get("token"):
# 获取token值,检验正确与否,获取uuid
payload = jwt.decode(message.get("token"), config.JWT_SECRET_KEY, verify=True, algorithms=['HS256'])
logger.info(payload)
# 认证包,认证不通过,则剔除该连接
......@@ -176,7 +175,6 @@ class NotifyHandler(BaseWebsocket):
# 查询该用户可查看设备
devices = DeviceModel.query.filter(DeviceModel.create_by==user.id).all()
if len(devices):
logger.info("==========================================================>")
self._clients.append({
'uuid': payload.get("sub").get("uuid"),
'context': self,
......@@ -196,6 +194,9 @@ class NotifyHandler(BaseWebsocket):
else:
self.write_message(json.dumps({ 'code': 200, 'data': None, 'msg': 'unkonw message packet, disconnect by server' }))
self.handlers[className].remove(self)
except jwt.exceptions.ExpiredSignatureError as e:
logger.error(e)
self.write_message(json.dumps({ 'code': 401, 'data': None, 'msg': 'auth fail' }))
except Exception as e:
# 认证失败会导致触发异常,这里不能remove(self),否则会导致on_close方法报错
self.write_message(json.dumps({ 'code': 400, 'data': e.args, 'msg': "server error" }))
......@@ -230,13 +231,22 @@ class MainHandler(BaseHandler):
self.write(json.dumps({ "msg": "Hello, world" }))
def post(self):
data = tornado.escape.json_decode(self.request.body)
self.write(json.dumps({ 'code': 100, 'data': data, 'msg': 'success' }))
if not self.request.body:
return None
message = {'imei': '12345678900005', 'type': 'report', 'system': {'free_size': 0}, 'lvgl': {'total_size': 5242880, 'free_cnt': 31, 'free_size': 1279664, 'free_biggest_size': 1205448, 'used_cnt': 832, 'used_pct': 76, 'frag_pct': 6}, 'evm': {'total_size': 2097152, 'free_size': 0, 'gc_usage': 50}, 'image': [{'uri': 'evue_launcher', 'length': 1043, 'png_total_count': 0, 'png_uncompressed_size': 0, 'png_file_size': 0}, {'uri': 'kdgs_1_storyList', 'length': 9608, 'png_total_count': 193, 'png_uncompressed_size': 370884, 'png_file_size': 209807}]}
insert_data(message)
# 这里不能使用广播,得点对点发送,有此设备的账号才能看到调试信息
NotifyHandler.broadcastMessage(message)
try:
data = tornado.escape.json_decode(self.request.body)
logger.info(data)
self.write(json.dumps({ 'code': 100, 'data': data, 'msg': 'success' }))
message = {'imei': '12345678900005', 'type': 'report', 'system': {'free_size': 0}, 'lvgl': {'total_size': 5242880, 'free_cnt': 31, 'free_size': 1279664, 'free_biggest_size': 1205448, 'used_cnt': 832, 'used_pct': 76, 'frag_pct': 6}, 'evm': {'total_size': 2097152, 'free_size': 0, 'gc_usage': 50}, 'image': [{'uri': 'evue_launcher', 'length': 1043, 'png_total_count': 0, 'png_uncompressed_size': 0, 'png_file_size': 0}, {'uri': 'kdgs_1_storyList', 'length': 9608, 'png_total_count': 193, 'png_uncompressed_size': 370884, 'png_file_size': 209807}]}
insert_data(message)
# 这里不能使用广播,得点对点发送,有此设备的账号才能看到调试信息
NotifyHandler.broadcastMessage(message)
except Exception as e:
logger.info(self.request.body)
logger.error(e)
traceback.print_exc()
class WatchHandler(BaseHandler):
def get(self, *args, **kwargs):
......@@ -296,25 +306,31 @@ class DeviceMessageHandler(BaseHandler):
def post(self):
if not self.request.body:
self.write(json.dumps({ 'code': 304, 'data': None, 'msg': 'parmeters error' }))
return
logger.info(self.request.body)
return None
data = tornado.escape.json_decode(self.request.body)
data.update({ 'request': {
'host': self.request.remote_ip,
'path': self.request.path,
'protocol': self.request.protocol
} })
logger.info(data)
insert_data(data)
data['type'] = 'report'
data['request'].update({ 'timestamp': datetime.now().strftime("%Y-%m-%d %H:%M:%S") })
NotifyHandler.broadcastMessage(data)
self.write(json.dumps({ 'code': 100, 'message': 'success' }))
try:
# data = tornado.escape.json_decode(self.request.body)
data = str(self.request.body, encoding="ISO-8859-1")
data = json.loads(data)
logger.info(data)
data['system'].update({
'host': self.request.remote_ip,
'path': self.request.path,
'protocol': self.request.protocol
})
result = insert_data(data)
data['type'] = 'report'
data['system'].update({ 'timestamp': datetime.now().strftime("%Y-%m-%d %H:%M:%S") })
NotifyHandler.broadcastMessage(data)
self.write(json.dumps({ 'code': 100 if result else 400, 'message': 'success' if result else "fail" }))
except Exception as e:
logger.info(self.request.body)
logger.error(e)
traceback.print_exc()
def make_app():
return tornado.web.Application([
......
......@@ -3,7 +3,7 @@
'''
Author: your name
Date: 2021-07-20 19:04:27
LastEditTime: 2021-07-21 13:34:32
LastEditTime: 2021-07-21 20:01:56
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \evm-store\tools\database_migration.py
......@@ -12,15 +12,19 @@ FilePath: \evm-store\tools\database_migration.py
import os
import sqlite3
import uuid
from datetime import datetime
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
print("####>>>", BASE_DIR)
start = datetime.now()
print("start at:", start.strftime("%Y-%m-%d %H:%M:%S"))
source_conn = sqlite3.connect(os.path.join(BASE_DIR, "app-store.db"))
source_cur = source_conn.cursor()
target_db = os.path.join(BASE_DIR, "evue_store.db")
target_db = os.path.join(BASE_DIR, "evue-store.db")
target_conn = sqlite3.connect(target_db)
target_cur = source_conn.cursor()
......@@ -51,6 +55,19 @@ with open("database_migration.sql", "w+") as fd:
source_cur.execute(sql_str)
source_conn.commit()
# 更新app logs 表
sql_str = "select create_at from evm_store_app_logs"
source_cur.execute(sql_str)
res = source_cur.fetchall()
for line in res:
sql_str = "select id from evm_store_apps where strftime('%s', evm_store_apps.create_at) - strftime('%s', '{b}') < 2".format(b=line[0])
source_cur.execute(sql_str)
tmp = source_cur.fetchone()
if tmp:
sql_str = "UPDATE evm_store_app_logs SET remarks = {a};".format(a=tmp[0])
source_cur.execute(sql_str)
source_conn.commit()
# 先插入user表
source_cur.execute('SELECT account, username, password, email, phone, create_at, create_by, update_at, update_by FROM evm_store_user')
sql = "insert into evm_user (id, uuid, account, username, password, email, phone, create_at, create_by, update_at, update_by, is_delete, role) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', '{h}', {i}, '{j}', {k}, 0, 0);"
......@@ -89,7 +106,10 @@ with open("database_migration.sql", "w+") as fd:
res = source_cur.fetchall()
sql = "insert into evm_annex (id, uuid, app, title, path, size, create_at, create_by, update_at, update_by, is_delete) values ({a}, '{b}', {c}, '{d}', '{e}', {f}, '{g}', {h}, '{i}', {j}, 0);"
for line in res:
sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=line[2], d=line[3], e=line[4], f=line[5], g=line[6], h=line[7], i=line[8], j=line[9])
if not line[2]:
continue
sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=line[2], d=line[3], e=line[4] or "", f=line[5], g=line[6], h=line[7], i=line[8], j=line[9])
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
target_conn.commit()
......@@ -97,7 +117,7 @@ with open("database_migration.sql", "w+") as fd:
# app
source_cur.execute('SELECT id, app_name, app_icon, app_version, category, app_url, app_desc, create_at, create_by ,update_at, update_by, is_delete FROM evm_store_apps')
res = source_cur.fetchall()
sql = "insert into evm_app (id, uuid, app_name, app_icon, app_version, category, download_url, app_screen_size, app_arch, app_review, meta_data, remarks, create_at, create_by, update_at, update_by, is_delete) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', '{h}', '{i}', '{j}', '{k}', '{l}', '{m}', {n}, '{o}', {p} 0);"
sql = "insert into evm_app (id, uuid, app_name, app_icon, app_version, category, download_url, app_screen_size, app_arch, app_review, meta_data, remarks, create_at, create_by, update_at, update_by, is_delete, launcher, developer, app_file_size) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', '{h}', '{i}', '{j}', '{k}', '{l}', '{m}', {n}, '{o}', {p}, 0, `""`, `""`, 0);"
for line in res:
sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=line[1], d=line[2], e=line[3], f=line[4], g=line[5], h="240 * 240", i="ASR3601", j=0, k='{}', l=line[6], m=line[7], n=line[8], o=line[9], p=line[10])
# target_cur.execute(sql_str)
......@@ -116,12 +136,23 @@ with open("database_migration.sql", "w+") as fd:
# app log & build log
# 先插入app log
source_cur.execute('SELECT id, uuid, app_name, app_path, app_version, app_info, create_at, create_by FROM evm_store_app_logs')
source_cur.execute('SELECT id, uuid, app_name, app_path, app_version, app_info, create_at, create_by, remarks FROM evm_store_app_logs')
res = source_cur.fetchall()
sql = "insert into evm_package (id, uuid, app_name, app_path, app_version, app_info, create_at, create_by, update_at, update_by, is_delete, source) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', {h}, '{i}', {j}, {k}, {l});"
sql = "insert into evm_package (id, uuid, app, app_path, app_version, app_info, create_at, create_by, update_at, update_by, is_delete, source) values ({a}, '{b}', '{c}', '{d}', '{e}', `'{f}'`, '{g}', {h}, '{i}', {j}, {k}, {l});"
for line in res:
# 根据时间查找app
print(">>>>>>>>>>>>", line[6], line[8])
if not line[8] or (isinstance(line[8], str) and len(line[8]) == 0):
print("remarks is none")
continue
sql_str = "select id from evm_store_apps where id = {a}".format(a=int(line[8]))
source_cur.execute(sql_str)
tmp = source_cur.fetchone()
if not tmp:
print("app not found")
continue
s = 1 if line[5] and isinstance(line[5], str) and line[5].find("evueapps") > -1 else 0
sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=line[2], d=line[3], e=line[4], f=line[5], g=line[6], h=line[7], i=line[6], j=line[7], k=0, l=s)
sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=tmp[0], d=line[3], e=line[4], f=line[5], g=line[6], h=line[7], i=line[6], j=line[7], k=0, l=s)
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
target_conn.commit()
......@@ -137,6 +168,7 @@ with open("database_migration.sql", "w+") as fd:
tmp = source_cur.fetchone()
print("=======>", line[0])
if tmp:
print("app_path not equal")
continue
print("===========>", line)
......@@ -159,3 +191,6 @@ with open("database_migration.sql", "w+") as fd:
source_conn.commit()
source_conn.close()
print("spend time:", datetime.now() - start)
\ No newline at end of file
......@@ -208,7 +208,7 @@
@container-resized="containerResizedEvent"
@moved="movedEvent"
>
<EvmChart :chartData="evm"></EvmChart>
<SystemChart :chartData="system"></SystemChart>
</grid-item>
<grid-item
:x="0"
......@@ -221,6 +221,20 @@
@resized="resizedEvent"
@container-resized="containerResizedEvent"
@moved="movedEvent"
>
<EvmChart :chartData="evm"></EvmChart>
</grid-item>
<grid-item
:x="0"
:y="34"
:w="12"
:h="7"
i="8"
@resize="resizeEvent"
@move="moveEvent"
@resized="resizedEvent"
@container-resized="containerResizedEvent"
@moved="movedEvent"
>
<LvglChart :chartData="lvgl"></LvglChart>
</grid-item>
......@@ -245,6 +259,7 @@ import {
Input,
Select,
DatePicker,
message,
} from "ant-design-vue";
import PageHeaderWrapper from "@/components/PageHeaderWrapper";
import DescriptionItem from "@/components/DescriptionItem";
......@@ -252,6 +267,7 @@ import DescriptionItem from "@/components/DescriptionItem";
import { getWatchList, getMonitorData } from "@/api/openapi";
import EvmChart from "./components/EvmChart";
import LvglChart from "./components/LvglChart";
import SystemChart from "./components/SystemChart";
import { GridLayout, GridItem } from "vue-grid-layout";
import { wsNotify } from "@/utils/notify.js";
export default {
......@@ -259,9 +275,11 @@ export default {
data() {
return {
watchs: [],
globalData: null,
device: null,
devices: {},
deviceList: [],
systemList: [],
system: {
host: null,
imei: null,
......@@ -289,7 +307,7 @@ export default {
imageList: [],
socket: null,
form: {
system: ["free_size"],
system: ["free_size", "free_space_size", "used_space_size"],
lvgl: ["total_size", "free_size", "free_biggest_size"],
evm: [
"total_size",
......@@ -303,13 +321,14 @@ export default {
image: ["png_uncompressed_size", "png_file_size", "length"],
},
layout: [
{ x: 0, y: 0, w: 6, h: 5, i: "0", static: false },
{ x: 6, y: 0, w: 6, h: 5, i: "1", static: true },
{ x: 0, y: 5, w: 6, h: 5, i: "2", static: false },
{ x: 6, y: 5, w: 6, h: 5, i: "3", static: false },
{ x: 0, y: 10, w: 12, h: 10, i: "4", static: false },
{ x: 0, y: 20, w: 12, h: 7, i: "5", static: false },
{ x: 0, y: 27, w: 12, h: 7, i: "6", static: false },
{ x: 0, y: 0, w: 6, h: 5, i: "1", static: false },
{ x: 6, y: 0, w: 6, h: 5, i: "2", static: true },
{ x: 0, y: 5, w: 6, h: 5, i: "3", static: false },
{ x: 6, y: 5, w: 6, h: 5, i: "4", static: false },
{ x: 0, y: 10, w: 12, h: 10, i: "5", static: false },
{ x: 0, y: 20, w: 12, h: 7, i: "6", static: false },
{ x: 0, y: 27, w: 12, h: 7, i: "7", static: false },
{ x: 0, y: 34, w: 12, h: 7, i: "8", static: false },
],
draggable: true,
resizable: true,
......@@ -320,6 +339,7 @@ export default {
GridItem,
EvmChart,
LvglChart,
SystemChart,
APageHeaderWrapper: PageHeaderWrapper,
AAvatar: Avatar,
ARow: Row,
......@@ -461,7 +481,17 @@ export default {
this.socket.send(message);
},
handleMessage(msg) {
if (msg.type !== "report" || !msg.imei) return false;
if (msg.code == 401) {
window.sessionStorage.removeItem("Authorization")
this.$router.push({ path: "/user/login" })
message.error(msg.msg)
return null;
}
if (msg.type !== "report" || !msg.imei) return null;
// 如果接收到的数据不是当前选中的设备,那么则直接丢弃
// 这里可以优化,将所有数据,保存到indexed datebase中
if (this.device && msg.imei != this.device) return null;
if (!this.deviceList) {
this.deviceList = [];
......@@ -470,12 +500,15 @@ export default {
this.deviceList.push(msg.imei);
}
if (!this.device) {
if (this.deviceList && this.deviceList.length) this.device = this.deviceList[0];
if (this.deviceList && this.deviceList.length)
this.device = this.deviceList[0];
else this.device = msg.imei;
}
this.devices[msg.imei] = msg;
// 处理单位
this.processData(msg);
// this.devices[msg.imei] = msg;
this.globalData = msg;
this.resetData();
},
processData(msg) {
......@@ -498,37 +531,65 @@ export default {
},
onSelectChange(res) {
this.device = res;
this.processData(this.devices[this.device]);
this.resetData();
// this.processData(this.devices[this.device]);
// this.resetData();
console.log(res);
},
resetData() {
wsNotify.eventBus.$emit("resize");
this.evmList = [{ ...this.devices[this.device].evm }];
this.lvglList = [{ ...this.devices[this.device].lvgl }];
this.system = { imei: this.devices[this.device].imei, ...this.devices[this.device].system, ...this.devices[this.device].request };
this.evmList = [{ ...this.globalData.evm }];
this.lvglList = [{ ...this.globalData.lvgl }];
this.systemList = [
{
imei: this.globalData.imei,
...this.globalData.system,
},
];
// 这里需要特殊处理下,先判断uri是否存在,不存在则添加,存在则更新
let uris = [];
this.imageList.forEach((img) => {
uris.push(img.uri);
this.imageList.forEach((item) => {
item.highlight = false;
uris.push(item.uri);
});
this.devices[this.device].image &&
this.devices[this.device].image.forEach((item) => {
if (!uris.includes(item.uri)) {
this.globalData.image &&
this.globalData.image.forEach((item) => {
if (item.png_uncompressed_size > 0) {
item.highlight = true;
} else {
item.highlight = false;
}
const target = this.imageList.find((img) => img.uri === item.uri);
if (target) {
target.length = item.length;
target.png_total_count = item.png_total_count;
target.highlight = false;
if (
item.png_uncompressed_size &&
item.png_uncompressed_size !== target.png_uncompressed_size
)
{
target.highlight = true;
target.png_uncompressed_size = item.png_uncompressed_size;
}
if (
item.png_file_size &&
item.png_file_size !== target.png_file_size
)
target.png_file_size = item.png_file_size;
} else {
this.imageList.push(item);
}
});
// this.imageList = msg.image;
if (this.devices[this.device]) {
if (this.devices[this.device].evm)
this.evm = this.devices[this.device].evm;
if (this.devices[this.device].lvgl)
this.lvgl = this.devices[this.device].lvgl;
if (this.devices[this.device].image)
this.image = this.devices[this.device].image;
if (this.globalData) {
if (this.globalData.evm) this.evm = this.globalData.evm;
if (this.globalData.lvgl) this.lvgl = this.globalData.lvgl;
if (this.globalData.image) this.image = this.globalData.image;
if (this.globalData.system) this.system = this.globalData.system;
}
},
},
......@@ -548,6 +609,7 @@ export default {
});
});
wsNotify.eventBus.$on("message", (message) => {
console.log(message)
this.$nextTick(() => {
this.handleMessage(message);
});
......
<template>
<div :class="className" :style="{ height: height, width: width }" />
</template>
<script>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";
import { getDateTimeString } from "@/utils/utils";
import { wsNotify } from "@/utils/notify.js";
const seriesData = {
free_size: [],
free_space_size: [],
used_space_size: [],
};
export default {
mixins: [resize],
props: {
className: {
type: String,
default: "chart",
},
width: {
type: String,
default: "100%",
},
height: {
type: String,
default: "270px",
},
autoResize: {
type: Boolean,
default: true,
},
chartData: {
type: Object,
required: true,
},
dataList: {
type: Array,
required: false,
default: () => [],
},
},
data() {
return {
chart: null,
series: [
{
name: "free_size",
type: "line",
showSymbol: false,
emphasis: {
scale: false,
focus: "series",
blurScope: "coordinateSystem",
},
data: seriesData.free_size,
},
{
name: "free_space_size",
type: "line",
showSymbol: false,
emphasis: {
focus: "series",
blurScope: "coordinateSystem",
},
data: seriesData.free_space_size,
},
{
name: "used_space_size",
type: "line",
showSymbol: false,
emphasis: {
focus: "series",
blurScope: "coordinateSystem",
},
data: seriesData.used_space_size,
},
],
legendData: [
"free_size",
"free_space_size",
"used_space_size"
],
};
},
watch: {
chartData: {
deep: true,
handler(val) {
this.handleMessage(val);
},
},
dataList: {
deep: true,
handler(val) {
if (val.length > 0) this.handleData(val);
},
},
},
mounted() {
this.$nextTick(() => {
this.initChart();
});
wsNotify.eventBus.$on("resize", () => {
if (this.chart) this.chart.resize()
});
},
beforeDestroy() {
if (!this.chart) {
return;
}
this.chart.dispose();
this.chart = null;
},
methods: {
handleData(data) {
Object.keys(seriesData).forEach(key => {
seriesData[key] = []
});
this.series.forEach(item => {
item.data = []
});
this.chart.setOption({ series: this.series });
data.forEach((item) => {
this.handleMessage(item);
});
},
handleMessage(data) {
Object.keys(data).forEach((k) => {
var t = getDateTimeString(new Date());
if (k == "timestamp") t = data[k];
if (this.legendData.includes(k))
seriesData[k].push({
name: k,
value: [t, data[k]],
});
});
this.$nextTick(() => {
this.chart &&
this.chart.setOption({
series: this.series,
});
});
},
initChart() {
this.chart = echarts.init(this.$el, "macarons");
this.setOptions();
},
setOptions() {
this.chart.setOption({
title: {
text: "SYSTEM",
},
grid: {
left: 10,
right: 10,
bottom: 10,
top: 50,
containLabel: true,
},
xAxis: {
type: "time",
splitLine: {
},
axisLabel: {
formatter: "{HH}:{mm}:{ss}",
},
},
yAxis: {
type: "value",
// boundaryGap: [0, "100%"],
splitLine: {
},
},
tooltip: {
trigger: "axis",
axisPointer: {
type: "cross",
animation: false,
},
padding: [5, 10],
},
legend: {
data: this.legendData,
selected: {
free_size: true,
free_space_size: true,
used_space_size: false
},
},
series: this.series,
});
},
},
};
</script>
......@@ -163,11 +163,15 @@ export default {
doLogin() {
postLogin(this.post)
.then((res) => {
this.$store.commit("frontend/login/setToken", res.data.token);
this.$store.commit("frontend/login/setUserInfo", { uuid: res.data.uuid, name: res.data.name });
message.success(res.msg);
window.sessionStorage.setItem("Authorization", res.data.token)
this.$router.push({ path: "/" });
if (res.code == 200) {
this.$store.commit("frontend/login/setToken", res.data.token);
this.$store.commit("frontend/login/setUserInfo", { uuid: res.data.uuid, name: res.data.name });
message.success(res.msg);
window.sessionStorage.setItem("Authorization", res.data.token)
this.$router.push({ path: "/" });
} else {
message.error(res.msg)
}
})
.catch((err) => {
message.error(err.msg)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment