|
@@ -145,8 +145,8 @@ async def register(request: Request, form_data: OAuth2PasswordRequestForm = Depe
|
|
|
return templates.TemplateResponse(name='login.html', context={'request': request})
|
|
|
|
|
|
|
|
|
-@app.post('/record_tower/{tower_id}')
|
|
|
-async def record_tower(request: Request,tower_id:str,data : models.record_tower_data,key:str):
|
|
|
+@app.post('/record_tower')
|
|
|
+async def record_tower(request: Request,data : models.record_tower_data,key:str):
|
|
|
#data = models.tower_data(**await request.form())
|
|
|
if key!="21232f297a57a5a743894a0e4a801fc3":
|
|
|
return {'msg':'no access'}
|
|
@@ -156,26 +156,18 @@ async def record_tower(request: Request,tower_id:str,data : models.record_tower_
|
|
|
cmd ="SELECT * FROM device"
|
|
|
cmd2={}
|
|
|
check = False
|
|
|
- for row in db.query(cmd):
|
|
|
- if row['id']== tower_id:
|
|
|
- check = True
|
|
|
+ # for row in db.query(cmd):
|
|
|
+ # if row['id']== tower_id:
|
|
|
+ # check = True
|
|
|
if check :
|
|
|
- record_tower_dict = data.__dict__
|
|
|
- keys = []
|
|
|
- for key in record_tower_dict.keys():
|
|
|
- keys.append(key)
|
|
|
- for row in keys:
|
|
|
- cmd = "cmd2['cmd'] = \"UPDATE `record_tower` SET `value` = \"+str(data.{}) +\",`time_stamp` = '\"+loc_dt_format +\"' WHERE `device_id` = '\"+tower_id+\"' AND `key` = '{}'\"".format(row,row)
|
|
|
- exec(cmd)
|
|
|
- print(cmd)
|
|
|
- db.query(cmd2['cmd'])
|
|
|
+
|
|
|
result={'msg':"success"}
|
|
|
else:
|
|
|
result = {'msg':"no device"}
|
|
|
return json.dumps(result,ensure_ascii=False)
|
|
|
|
|
|
-@app.post('/record_dcs/{tower_id}')
|
|
|
-async def record_dcs(request: Request,tower_id:str,data : models.record_dcs_data,key:str):
|
|
|
+@app.post('/record_dcs')
|
|
|
+async def record_dcs(request: Request,data : models.record_tower_data,key:str):
|
|
|
#data = models.tower_data(**await request.form())
|
|
|
if key!="21232f297a57a5a743894a0e4a801fc3":
|
|
|
return {'msg':'no access'}
|
|
@@ -185,19 +177,9 @@ async def record_dcs(request: Request,tower_id:str,data : models.record_dcs_data
|
|
|
cmd ="SELECT * FROM device"
|
|
|
cmd2={}
|
|
|
check = False
|
|
|
- for row in db.query(cmd):
|
|
|
- if row['id']== tower_id:
|
|
|
- check = True
|
|
|
+
|
|
|
if check :
|
|
|
- record_tower_dict = data.__dict__
|
|
|
- keys = []
|
|
|
- for key in record_tower_dict.keys():
|
|
|
- keys.append(key)
|
|
|
- for row in keys:
|
|
|
- cmd = "cmd2['cmd'] = \"UPDATE `record_dcs` SET `value` = \"+str(data.{}) +\",`time_stamp` = '\"+loc_dt_format +\"' WHERE `device_id` = '\"+tower_id+\"' AND `key` = '{}'\"".format(row,row)
|
|
|
- exec(cmd)
|
|
|
- print(cmd)
|
|
|
- db.query(cmd2['cmd'])
|
|
|
+
|
|
|
result={'msg':"success"}
|
|
|
else:
|
|
|
result = {'msg':"no device"}
|
|
@@ -621,7 +603,6 @@ async def history(request: Request, Authorize: AuthJWT = Depends()):
|
|
|
|
|
|
@app.get('/device', response_class=HTMLResponse)
|
|
|
async def device(request: Request, Authorize: AuthJWT = Depends()):
|
|
|
-
|
|
|
try:
|
|
|
Authorize.jwt_required()
|
|
|
except Exception as e:
|
|
@@ -633,13 +614,14 @@ async def device(request: Request, Authorize: AuthJWT = Depends()):
|
|
|
print("start")
|
|
|
for row in db.query(statement):
|
|
|
print(row['id'],row['deviceName'],row['hostIP'],row['CompanyCode'],row['FactoryCode'],row['DepartmentCode'])
|
|
|
- a.append((row['id'],row['deviceName'],row['hostIP'],row['CompanyCode'],row['FactoryCode'],row['DepartmentCode']))
|
|
|
+ a.append({row['id'],row['deviceName'],row['hostIP']})
|
|
|
+ a.append({row['CompanyCode'],row['FactoryCode'],row['DepartmentCode']})
|
|
|
print(a)
|
|
|
print("over3")
|
|
|
#result = json.dumps(b,ensure_ascii=False)
|
|
|
# current_user = Authorize.get_jwt_subject()
|
|
|
return templates.TemplateResponse(name='device.html', context={'request': request,'a':a})
|
|
|
- return result
|
|
|
+
|
|
|
|
|
|
|
|
|
@app.get('/system', response_class=HTMLResponse)
|
|
@@ -1356,4 +1338,4 @@ def add_tower():
|
|
|
loc_dt_format = loc_dt.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
for device in ['dev005','dev006','dev007','dev008','dev009']:
|
|
|
for key in ['hotTemp','waterFlow','coldTemp','fanMotorCur','fanMotorSpeedFreq']:
|
|
|
- db['record_dcs'].insert(dict(time_stamp=loc_dt_format, MFValue=uniform(0,0.12),vibration_id = 1))
|
|
|
+ db['record_dcs'].insert(dict(time_stamp=loc_dt_format, MFValue=uniform(0,0.12),vibration_id = 1))
|