wangrong
2025-09-23 f19a0e925da02a08b88784a534b16ec6d833df4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- coding: utf-8 -*-
 
#!/usr/bin/python
# -*- coding: utf-8 -*
 
from mysqlhelper import MySqLHelper
import json
 
db = MySqLHelper()
 
def bt_dt_save(data):
    try:
        obj = data[-1]
        sql2 = 'insert into dt_radar_boat_df_msg (object_id,lng,lat,height,minOfYear,second,direction,deviceTime,fusDevID,fps,cellid,msgCnt,nofobjects,dataSource,msgdata,isInside,serverTime,create_time) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,now(),now()) on duplicate key update msgdata=values(msgdata), lng=values(lng), lat=values(lat), direction=values(direction), height=values(height), isInside=values(isInside), update_time=now()'
        ret = db.insertone(sql2, (obj['object_id'],"{:.8f}".format(obj['lng']),"{:.8f}".format(obj['lat']),"{:.2f}".format(obj['height']),obj['minOfYear'],obj['second'],"{:.2f}".format(obj['direction']),obj['time'],obj['speed'],obj['fps'],obj['cellid'],obj['msgCnt'],obj['nofobjects'],obj['dataSource'],json.dumps(data),obj['isInside']))
        print(f"数据库保存成功 {ret}:!")
    except Exception as e:
        print(e)
        pass
 
def bt_old_dt_clean():
    try:
        sql2 = 'update dt_radar_boat_df_msg set isInside = -1 where isInside =1'
        ret = db.update(sql2)
        print(f"数据库保存成功 {ret}:!")
    except Exception as e:
        print(e)
        pass
 
def bt_cy_save(data):
    try:
        obj = data[-1]
        sql2 = 'insert into dt_radar_boat_cy_msg (object_id,lng,lat,height,minOfYear,second,direction,deviceTime,fusDevID,fps,cellid,msgCnt,nofobjects,dataSource,msgdata,isInside,serverTime,create_time) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,now(),now()) on duplicate key update msgdata=values(msgdata), lng=values(lng), lat=values(lat), direction=values(direction), height=values(height), isInside=values(isInside), update_time=now()'
        ret = db.insertone(sql2, (obj['object_id'],"{:.8f}".format(obj['lng']),"{:.8f}".format(obj['lat']),"{:.2f}".format(obj['height']),obj['minOfYear'],obj['second'],"{:.2f}".format(obj['direction']),obj['time'],obj['speed'],obj['fps'],obj['cellid'],obj['msgCnt'],obj['nofobjects'],obj['dataSource'],json.dumps(data),obj['isInside']))
        print(f"数据库保存成功 {ret}:!")
    except Exception as e:
        print(e)
        pass
 
def bt_old_cy_clean():
    try:
        sql2 = 'update dt_radar_boat_cy_msg set isInside = -1 where isInside =1'
        ret = db.update(sql2)
        print(f"数据库保存成功 {ret}:!")
    except Exception as e:
        print(e)
        pass
   
 
 
def uav_zte_dt_save(data):
    try:
        obj = data[-1]
        sql2 = 'insert into dt_radar_uav_zte_msg (object_id,lng,lat,height,minOfYear,second,direction,deviceTime,fusDevID,fps,cellid,msgCnt,nofobjects,dataSource,msgdata,isInside,serverTime,create_time) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,now(),now()) on duplicate key update msgdata=values(msgdata), lng=values(lng), lat=values(lat), direction=values(direction), height=values(height), isInside=values(isInside), update_time=now()'
        ret = db.insertone(sql2, (obj['object_id'],"{:.8f}".format(obj['lng']),"{:.8f}".format(obj['lat']),"{:.2f}".format(obj['height']),obj['minOfYear'],obj['second'],"{:.2f}".format(obj['direction']),obj['time'],obj['speed'],obj['fps'],obj['cellid'],obj['msgCnt'],obj['nofobjects'],obj['dataSource'],json.dumps(data),obj['isInside']))
        #print(sql2)
        #print(obj)
        print(f"数据库更新成功 {ret}:!")
    except Exception as e:
        print(e)
        pass
 
def uav_zte_old_dt_clean():
    try:
        sql2 = 'update dt_radar_uav_zte_msg set isInside = -1 where isInside =1'
        ret = db.update(sql2)
        print(f"数据库保存成功 {ret}:!")
    except Exception as e:
        print(e)
        pass
 
def uav_hw_dt_save(object_id, track):
    try:
        obj = track[-1]
        sql2 = 'insert into dt_radar_uav_hw_msg (object_id,lng,lat,isInside,msgCnt,height,fusDevID,direction,second,deviceTime,msgdata,serverTime,create_time) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,now(),now()) on duplicate key update msgdata=values(msgdata), lng=values(lng), lat=values(lat), height=values(height), fusDevID=values(fusDevID),direction=values(direction), msgCnt=values(msgCnt),update_time=now()'
        ret = db.insertone(sql2, (object_id,"{:.8f}".format(obj['lng']),"{:.8f}".format(obj['lat']),obj['isInside'],obj['batchSerial'],"{:.2f}".format(obj['height']),"{:.2f}".format(obj['velocityH']),obj['headH'],obj['second'],obj['deviceTime'],json.dumps(track)))
        print(f"数据库保存成功 {ret}:!")
    except Exception as e:
        print(e)
        pass
 
def uav_hw_old_dt_clean():
    try:
        sql2 = 'update dt_radar_uav_hw_msg set isInside = -1 where isInside =1'
        ret = db.update(sql2)
        print(f"数据库保存成功 {ret}:!")
    except Exception as e:
        print(e)
        pass
 
 
def main():
    print()    
 
if __name__ == '__main__':
    #print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(1712900732)))
    main()