Commit baa16069 authored by wanli's avatar wanli

update

parent a58b140d
'''
Author: your name
Date: 2021-06-29 19:24:32
LastEditTime: 2021-07-01 10:01:48
LastEditTime: 2021-07-05 20:41:32
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \evm-store\backend\controller\monitor.py
'''
from model.monitor import session, System, Lvgl, Evm, Image, Watch, Request
from model.monitor import session, System, Lvgl, Evm, Image, Device, Request, User
class SystemResource(object):
def get(self):
......@@ -93,16 +93,17 @@ def insert_data(msg):
# 先判断手表imei是否存在,不存在则先注册手表IMEI
watch_id = -1
if msg.get("imei"):
result = session.query(Watch).filter_by(imei=msg.get("imei")).first()
result = session.query(Device).filter_by(imei=msg.get("imei")).first()
if result:
watch_id = result.id
else:
result = Watch(imei=msg.get("imei"))
user = session.query(User).filter(User.account=="evm").first()
result = Device(imei=msg.get("imei"), name="watch_{}".format(msg.get("imei")), type="watch", create_by=user.id, update_by=user.id)
session.add(result)
session.flush()
session.commit()
result = session.query(Watch).filter_by(imei=msg.get("imei")).first()
result = session.query(Device).filter_by(imei=msg.get("imei")).first()
if result:
watch_id = result.id
......@@ -129,7 +130,7 @@ def insert_data(msg):
imageResource.post_array(msg.get("image"), watch_id)
def get_watch_list():
result = session.query(Watch).all()
result = session.query(Device).all()
tmp = []
for item in result:
tmp.append({
......@@ -188,7 +189,7 @@ def image_data(watch, start, end):
def get_monitor_list(watch, category, start, end):
# 判断watch是否存在
w = session.query(Watch).filter(Watch.id==watch).first()
w = session.query(Device).filter(Device.id==watch).first()
if not w:
return []
......
......@@ -17,6 +17,9 @@ Base = declarative_base()
def get_current_datetime():
return datetime.now()
def gen_id():
return uuid.uuid4().hex
def object_to_dict(obj):
columns = [column.key for column in class_mapper(obj.__class__).columns]
get_key_value = lambda c: (c, getattr(obj, c).isoformat()) if isinstance(getattr(obj, c), datetime) else (c, getattr(obj, c))
......@@ -132,26 +135,27 @@ class Image(Base):
class User(Base):
__tablename__ = "{}".format(config['TABLE_PREFIX']) + "user"
id = Column(Integer, primary_key=True, autoincrement=True)
uuid = Column(String(64), default=uuid.uuid1, index=True)
uuid = Column(String(64), default=gen_id, index=True)
account = Column(String(256))
class Device(Base):
__tablename__ = "{}".format(config['TABLE_PREFIX']) + "device"
id = Column(Integer, primary_key=True, autoincrement=True)
uuid = Column(String(64), default=uuid.uuid1, index=True)
name = Column(String)
uuid = Column(String(64), default=gen_id, index=True)
name = Column(String, default="")
imei = Column(String)
desc = Column(String)
type = Column(String)
desc = Column(String, default="")
type = Column(String, default="watch")
create_at = Column(DateTime(timezone=True), default=get_current_datetime, onupdate=func.now())
create_by = Column(Integer)
create_by = Column(Integer, default=None, nullable=True)
update_at = Column(DateTime(timezone=True), default=get_current_datetime, onupdate=func.now())
update_by = Column(Integer)
update_by = Column(Integer, default=None)
delete_at = Column(DateTime(timezone=True), default=get_current_datetime, onupdate=func.now())
delete_by = Column(Integer)
delete_by = Column(Integer, default=None)
is_delete = Column(Boolean, default=False)
sort = Column(Integer)
remarks = Column(String)
sort = Column(Integer, default=1)
remarks = Column(String, default="")
def to_dict(self):
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
......
......@@ -237,7 +237,7 @@
:x="0"
:y="10"
:w="12"
:h="7"
:h="10"
i="5"
@resize="resizeEvent"
@move="moveEvent"
......@@ -245,6 +245,7 @@
@container-resized="containerResizedEvent"
@moved="movedEvent"
>
<div style="width: 100%; height: 100%; overflow-y: auto">
<p class="item-title">APP</p>
<el-table
element-loading-text="Loading"
......@@ -266,7 +267,9 @@
min-width="150"
show-overflow-tooltip
>
<template slot-scope="scope">{{ scope.row.length }}(KB)</template>
<template slot-scope="scope"
>{{ scope.row.length }}(KB)</template
>
</el-table-column>
<el-table-column
label="png_file_size"
......@@ -293,10 +296,11 @@
>
</el-table-column>
</el-table>
</div>
</grid-item>
<grid-item
:x="0"
:y="17"
:y="20"
:w="12"
:h="7"
i="6"
......@@ -310,7 +314,7 @@
</grid-item>
<grid-item
:x="0"
:y="24"
:y="27"
:w="12"
:h="7"
i="7"
......@@ -367,9 +371,9 @@ export default {
{ 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: 7, i: "4", static: false },
{ x: 0, y: 17, w: 12, h: 7, i: "4", static: false },
{ x: 0, y: 24, w: 12, h: 7, i: "4", 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 },
],
draggable: true,
resizable: true,
......@@ -382,15 +386,15 @@ export default {
LvglChart,
},
methods: {
moveEvent (i, newX, newY) {
moveEvent(i, newX, newY) {
const msg = "MOVE i=" + i + ", X=" + newX + ", Y=" + newY;
console.log(msg);
},
movedEvent (i, newX, newY) {
movedEvent(i, newX, newY) {
const msg = "MOVED i=" + i + ", X=" + newX + ", Y=" + newY;
console.log(msg);
},
resizeEvent (i, newH, newW, newHPx, newWPx) {
resizeEvent(i, newH, newW, newHPx, newWPx) {
const msg =
"RESIZE i=" +
i +
......@@ -404,7 +408,7 @@ export default {
newWPx;
console.log(msg);
},
resizedEvent (i, newX, newY, newHPx, newWPx) {
resizedEvent(i, newX, newY, newHPx, newWPx) {
const msg =
"RESIZED i=" +
i +
......@@ -418,7 +422,7 @@ export default {
newWPx;
console.log(msg);
},
containerResizedEvent (i, newH, newW, newHPx, newWPx) {
containerResizedEvent(i, newH, newW, newHPx, newWPx) {
const msg =
"CONTAINER RESIZED i=" +
i +
......@@ -432,19 +436,19 @@ export default {
newWPx;
console.log(msg);
},
layoutCreatedEvent (newLayout) {
layoutCreatedEvent(newLayout) {
console.log("Created layout: ", newLayout);
},
layoutBeforeMountEvent (newLayout) {
layoutBeforeMountEvent(newLayout) {
console.log("beforeMount layout: ", newLayout);
},
layoutMountedEvent (newLayout) {
layoutMountedEvent(newLayout) {
console.log("Mounted layout: ", newLayout);
},
layoutReadyEvent (newLayout) {
layoutReadyEvent(newLayout) {
console.log("Ready layout: ", newLayout);
},
layoutUpdatedEvent (newLayout) {
layoutUpdatedEvent(newLayout) {
console.log("Updated layout: ", newLayout);
},
fetchData() {
......@@ -504,15 +508,14 @@ export default {
if (msg.type !== "report" || !msg.imei) return false;
if (!this.deviceList) {
this.deviceList = []
this.deviceList = [];
}
if (!this.deviceList.includes(msg.imei)) {
this.deviceList.push(msg.imei)
this.deviceList.push(msg.imei);
}
if (!this.device && this.deviceList) {
this.device = this.deviceList[0]
} else {
this.device = msg.imei
if (!this.device) {
if (this.deviceList && this.deviceList.length) this.device = this.deviceList[0];
else this.device = msg.imei;
}
this.devices[msg.imei] = msg;
......@@ -536,31 +539,32 @@ export default {
}
}
});
},
onSelectChange(res) {
this.device = res;
this.processData(this.devices[this.device]);
this.resetData();
console.log(res);
},
resetData() {
wsNotify.eventBus.$emit("resize");
this.evmList = [{ ...msg.evm }];
this.lvglList = [{ ...msg.lvgl }];
this.system = [{ imei: msg.imei, ...msg.system, ...msg.request }];
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 }];
// 这里需要特殊处理下,先判断uri是否存在,不存在则添加,存在则更新
let uris = [];
this.imageList.forEach((img) => {
uris.push(img.uri);
});
msg.image &&
msg.image.forEach((item) => {
this.devices[this.device].image &&
this.devices[this.device].image.forEach((item) => {
if (!uris.includes(item.uri)) {
this.imageList.push(item);
}
});
// this.imageList = msg.image;
},
onSelectChange(res) {
this.device = res;
this.processData(this.devices[this.device]);
console.log(res);
},
resetData() {
wsNotify.eventBus.$emit("resize");
if (this.devices[this.device]) {
if (this.devices[this.device].evm)
......@@ -570,7 +574,7 @@ export default {
if (this.devices[this.device].image)
this.image = this.devices[this.device].image;
}
}
},
},
mounted() {},
created() {
......@@ -589,7 +593,6 @@ export default {
});
wsNotify.eventBus.$on("message", (message) => {
this.$nextTick(() => {
console.log(message);
this.handleMessage(message);
});
});
......
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