Commit baa16069 authored by wanli's avatar wanli

update

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