|
|
@@ -24,8 +24,10 @@ from apps.AppInfo.models import (
|
|
|
Hotel_Info, Hotel_Photo, JKdata, MyUser, Pick_Pub, Product, QXZdata,
|
|
|
QXZdata_New, QXZstatus, QXZstatus_New, QXZswitchdata, QXZswitchstatus,
|
|
|
Video_data,GardenArea,Store_Manage,Areacrop,Sell_Manage,Person_Pick,QXZAutoswitch,Sightsee_Info,Pic_Info,
|
|
|
- QXZ_Alarm_Log,Experts,Relations)
|
|
|
+ QXZ_Alarm_Log,Experts,Relations,QXZ_Alarm,QXZ_Conf,QXZ_Base_Info,QXZ_Default_Conf,QXZ_Info_Record)
|
|
|
from apps.Equipment.all_dict import qxz_dict
|
|
|
+import xlwt
|
|
|
+from io import BytesIO
|
|
|
|
|
|
|
|
|
# 地图
|
|
|
@@ -63,7 +65,8 @@ class Equip_Test(View):
|
|
|
class JKview(ListView):
|
|
|
def get(self,request):
|
|
|
equip_id = request.GET.get('equip_id')
|
|
|
- return render(request, 'backstageNet/jk/equipmanage_jk.html', context={"equip_id":equip_id})
|
|
|
+ token = "at.0izp4b188fna8vvk8j28o2l4a980qqex-1otrmuqf8l-1k26cbi-cletdiwkp"
|
|
|
+ return render(request, 'backstageNet/jk/equipmanage_jk.html', context={"equip_id":equip_id,"token":token})
|
|
|
def post(self,request):
|
|
|
pass
|
|
|
|
|
|
@@ -267,6 +270,9 @@ class Equip_Show_Detail(ListView):
|
|
|
def get(self,request):
|
|
|
e_id = request.GET.get("id")
|
|
|
product = Product.objects.get(id=e_id)
|
|
|
+ e_name = request.GET.get("name")
|
|
|
+ if e_name:
|
|
|
+ product = Product.objects.get(title=e_name)
|
|
|
return render(request, 'outerNet/exhibitionDetail.html', context={"product":product})
|
|
|
def post(self,request):
|
|
|
pass
|
|
|
@@ -301,6 +307,9 @@ class Garden_Intro(ListView):
|
|
|
def get(self,request):
|
|
|
pid = request.GET.get("id")
|
|
|
pick = Pick_Pub.objects.get(id=pid)
|
|
|
+ pname = request.GET.get("name")
|
|
|
+ if pname:
|
|
|
+ pick = Pick_Pub.objects.get(name=pname)
|
|
|
return render(request, 'outerNet/pickIntro.html', context={"pick":pick})
|
|
|
def post(self,request):
|
|
|
pass
|
|
|
@@ -329,6 +338,9 @@ class Tourist(ListView):
|
|
|
def get(self,request):
|
|
|
sid = request.GET.get("id")
|
|
|
sightsee = Sightsee_Info.objects.get(id=sid)
|
|
|
+ sname = request.GET.get("name")
|
|
|
+ if sname:
|
|
|
+ sightsee = Sightsee_Info.objects.get(name=sname)
|
|
|
return render(request, 'outerNet/tourist.html', context={"sightsee":sightsee})
|
|
|
def post(self,request):
|
|
|
pass
|
|
|
@@ -370,6 +382,9 @@ class Dorm_Detail(ListView):
|
|
|
hotel_id = request.GET.get("id")
|
|
|
hotel = Hotel_Info.objects.get(id=hotel_id)
|
|
|
photos = Hotel_Photo.objects.filter(hotel=hotel)
|
|
|
+ hotel_name = request.GET.get("name")
|
|
|
+ if hotel_name:
|
|
|
+ hotel = Hotel_Info.objects.get(name=hotel_name)
|
|
|
return render(request, 'outerNet/hotelDetail.html', context={"hotel":hotel,"photos":photos})
|
|
|
def post(self,request):
|
|
|
pass
|
|
|
@@ -410,6 +425,9 @@ class Video_Detail(ListView):
|
|
|
def get(self,request):
|
|
|
v_id = request.GET.get("id")
|
|
|
video = Video_data.objects.get(id=v_id)
|
|
|
+ v_name = request.GET.get("name")
|
|
|
+ if v_name:
|
|
|
+ video = Video_data.objects.get(title=v_name)
|
|
|
return render(request, 'outerNet/videoDetail.html', context={"video":video})
|
|
|
def post(self,request):
|
|
|
pass
|
|
|
@@ -701,12 +719,27 @@ class QXZ_Report_Detail2(ListView):
|
|
|
pass
|
|
|
def post(self,request):
|
|
|
e_id = request.POST.get("e_id")
|
|
|
+ page = int(request.POST.get("page"))
|
|
|
qxz_list = QXZdata_New.objects.filter(equip_id=e_id)
|
|
|
+ f_tbegin = request.POST.get('begin')
|
|
|
+ f_tend = request.POST.get('end')
|
|
|
+ if f_tbegin:
|
|
|
+ print("f_tbegin:", f_tbegin)
|
|
|
+ print("f_tend:", f_tend)
|
|
|
+ begindate = re.findall(r"\d+\.?\d*", f_tbegin)
|
|
|
+ enddate = re.findall(r"\d+\.?\d*", f_tend)
|
|
|
+ start_date = datetime.date(int(begindate[0]), int(begindate[1]), int(begindate[2]))
|
|
|
+ end_date = datetime.date(int(enddate[0]), int(enddate[1]), int(enddate[2]))
|
|
|
+ print("start_date:", start_date)
|
|
|
+ print("end_date:", end_date)
|
|
|
+ qxz_list = QXZdata_New.objects.filter(equip_id=e_id, upl_time__range=(start_date, end_date))
|
|
|
+
|
|
|
data = []
|
|
|
for i in qxz_list:
|
|
|
dat = {"e1":i.e1,"e2":i.e2,"e3":i.e3,"e4":i.e4,"e5":i.e5,"e6":i.e6,"e7":i.e7,"e8":i.e8,"e9":i.e9,"e10":i.e10,"e11":i.e11,"e12":i.e12,"e13":i.e13,"e14":i.e14}
|
|
|
data.append({"upl_time":i.upl_time.strftime('%Y-%m-%d %H:%M:%S'),"dat":dat})
|
|
|
nums = len(data)
|
|
|
+ data = data[(10*(page-1)):(page*10)]
|
|
|
datas = {"data":data,"nums":nums}
|
|
|
datas = json.dumps(datas)
|
|
|
return HttpResponse(datas)
|
|
|
@@ -968,8 +1001,8 @@ class Video_Pub(ListView):
|
|
|
print("-------错误信息为----------")
|
|
|
print(e)
|
|
|
data = "0"
|
|
|
- else:
|
|
|
- data = "0"
|
|
|
+ # else:
|
|
|
+ # data = "0"
|
|
|
|
|
|
return HttpResponse(data)
|
|
|
|
|
|
@@ -1553,6 +1586,9 @@ class Video_Check_List(ListView):
|
|
|
#保存
|
|
|
elif req == "check":
|
|
|
art_obj = Video_data.objects.get(id=art_id)
|
|
|
+ ckobj = CKArticle.objects.get(title=art_obj.title)
|
|
|
+ ckobj.hidden = True
|
|
|
+ ckobj.save()
|
|
|
art_obj.hidden = True
|
|
|
art_obj.save()
|
|
|
data = "1"
|
|
|
@@ -1630,6 +1666,9 @@ class Equip_Check_List(ListView):
|
|
|
#审核通过
|
|
|
elif req == "check":
|
|
|
art_obj = Product.objects.get(id=art_id)
|
|
|
+ ckobj = CKArticle.objects.get(title=art_obj.title)
|
|
|
+ ckobj.hidden = True
|
|
|
+ ckobj.save()
|
|
|
art_obj.hidden = True
|
|
|
art_obj.save()
|
|
|
data = "1"
|
|
|
@@ -1708,6 +1747,9 @@ class Garden_Check_List(ListView):
|
|
|
elif req == "check":
|
|
|
art_obj = Pick_Pub.objects.get(id=art_id)
|
|
|
art_obj.hidden = True
|
|
|
+ ckobj = CKArticle.objects.get(title=art_obj.title)
|
|
|
+ ckobj.hidden = True
|
|
|
+ ckobj.save()
|
|
|
art_obj.save()
|
|
|
data = "1"
|
|
|
data = json.dumps(data,ensure_ascii=False)
|
|
|
@@ -3035,9 +3077,26 @@ class QXZ_Warning_View(ListView):
|
|
|
print('user_name=', user_name)
|
|
|
current_user = MyUser.objects.get(username=user_name)
|
|
|
equip_list = Equip.objects.filter(equip_user=current_user,equip_type=5)
|
|
|
+ if current_user.is_staff:
|
|
|
+ equip_list = Equip.objects.filter(equip_type=5)
|
|
|
return render(request, 'backstageNet/warn/warnSet.html', context={"equip_list":equip_list})
|
|
|
def post(self,request):
|
|
|
- pass
|
|
|
+ equip_id = request.POST.get('equip_id')
|
|
|
+ try:
|
|
|
+ alarm = QXZ_Alarm.objects.get(equip_id=equip_id).conf
|
|
|
+ except:
|
|
|
+ alarm = ""
|
|
|
+ x = QXZ_Conf.objects.get(equip_id=equip_id)
|
|
|
+ conf = {"e1":x.e1,"e2":x.e2,"e3":x.e3,"e4":x.e4,"e5":x.e5,
|
|
|
+ "e6":x.e6,"e7":x.e7,"e8":x.e8,"e9":x.e9,"e10":x.e10,
|
|
|
+ "e11":x.e11,"e12":x.e12,"e13":x.e13,"e14":x.e14,
|
|
|
+ "e15":x.e15,"e16":x.e16,"e17":x.e17,"e18":x.e18,
|
|
|
+ "e19":x.e19,"e20":x.e20,"e21":x.e21,"e22":x.e22,
|
|
|
+ "e23":x.e23,"e24":x.e24,"e25":x.e25,"e26":x.e26,
|
|
|
+ "e27":x.e27,"e28":x.e28,"e29":x.e29,"e30":x.e30}
|
|
|
+ data = {"alarm":alarm,"conf":conf}
|
|
|
+ data = json.dumps(data)
|
|
|
+ return HttpResponse(data)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -3046,7 +3105,22 @@ class QXZ_Warning_List(ListView):
|
|
|
def get(self,request):
|
|
|
return render(request, 'backstageNet/warn/warnRecord.html', context={})
|
|
|
def post(self,request):
|
|
|
- pass
|
|
|
+ alarm = request.POST.get('alarm')
|
|
|
+ print(alarm)
|
|
|
+ print(eval(alarm)["equip_id"])
|
|
|
+ e_id = eval(alarm)["equip_id"]
|
|
|
+ tel = eval(alarm)["tel"]
|
|
|
+ equip_obj = Equip.objects.get(equip_id=e_id)
|
|
|
+ if QXZ_Alarm.objects.filter(equip_id=e_id).exists():
|
|
|
+ alarm_obj = QXZ_Alarm.objects.get(equip_id=equip_obj)
|
|
|
+ alarm_obj.conf = alarm
|
|
|
+ alarm_obj.tel = tel
|
|
|
+ alarm_obj.save()
|
|
|
+ print("修改成功")
|
|
|
+ else:
|
|
|
+ QXZ_Alarm.objects.create(equip_id=equip_obj,conf=alarm,tel=tel)
|
|
|
+ return HttpResponse("0")
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
@@ -3058,6 +3132,8 @@ class Production_Set(ListView):
|
|
|
print('user_name=', user_name)
|
|
|
current_user = MyUser.objects.get(username=user_name)
|
|
|
equip_list = Equip.objects.filter(equip_user=current_user,equip_type=5)
|
|
|
+ if current_user.is_staff:
|
|
|
+ equip_list = Equip.objects.filter(equip_type=5)
|
|
|
return render(request, 'backstageNet/warn/productionset.html', context={"equip_list":equip_list})
|
|
|
def post(self,request):
|
|
|
pass
|
|
|
@@ -3924,5 +4000,551 @@ class Equip_Addr(ListView):
|
|
|
equip_list = Equip.objects.filter(equip_user=user)
|
|
|
data = []
|
|
|
for i in equip_list:
|
|
|
- pass
|
|
|
-
|
|
|
+ data.append({"equip_id":i.equip_id,"lng":i.lng,"lat":i.lat,"equip_type":i.equip_type.type_id})
|
|
|
+ data = json.dumps(data)
|
|
|
+ return HttpResponse(data)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+class Equip_Location(ListView):
|
|
|
+ def get(self,request):
|
|
|
+ pass
|
|
|
+ def post(self, request):
|
|
|
+ eid = request.POST.get("e_id")
|
|
|
+ ename = request.POST.get("ename")
|
|
|
+ lng = request.POST.get("lng")
|
|
|
+ lat = request.POST.get("lat")
|
|
|
+ if ename:
|
|
|
+ if Equip.objects.filter(equip_name=ename).exists():
|
|
|
+ return HttpResponse("0")
|
|
|
+ equip_obj = Equip.objects.get(equip_id=eid)
|
|
|
+ equip_obj.equip_name = ename
|
|
|
+ equip_obj.save()
|
|
|
+ if lat:
|
|
|
+ equip_obj = Equip.objects.get(equip_id=eid)
|
|
|
+ equip_obj.lng = lng
|
|
|
+ equip_obj.lat = lat
|
|
|
+ equip_obj.save()
|
|
|
+ return HttpResponse("1")
|
|
|
+
|
|
|
+
|
|
|
+import json
|
|
|
+class Add_Qxz_Test(ListView):
|
|
|
+ def get(self,request):
|
|
|
+ pass
|
|
|
+ def post(self, request):
|
|
|
+ payload = request.body
|
|
|
+ payload = json.loads(payload.decode())
|
|
|
+ print("payload",payload)
|
|
|
+ print("type",type(payload))
|
|
|
+ if payload.get("cmd") == "terminalData":
|
|
|
+ print("<-----uploading data!----->")
|
|
|
+ extdata = payload.get("ext")
|
|
|
+ print(type(extdata))
|
|
|
+ qxzdata = extdata['data']
|
|
|
+ print(qxzdata)
|
|
|
+ device_id = extdata['StationID']
|
|
|
+ print(device_id)
|
|
|
+ e1 = ''
|
|
|
+ e2 = ''
|
|
|
+ e3 = ''
|
|
|
+ e4 = ''
|
|
|
+ e5 = ''
|
|
|
+ e6 = ''
|
|
|
+ e7 = ''
|
|
|
+ e8 = ''
|
|
|
+ e9 = ''
|
|
|
+ e10 = ''
|
|
|
+ e11 = ''
|
|
|
+ e12 = ''
|
|
|
+ e13 = ''
|
|
|
+ e14 = ''
|
|
|
+ e15 = ''
|
|
|
+ e16 = ''
|
|
|
+ e17 = ''
|
|
|
+ e18 = ''
|
|
|
+ e19 = ''
|
|
|
+ e20 = ''
|
|
|
+ e21 = ''
|
|
|
+ e22 = ''
|
|
|
+ e23 = ''
|
|
|
+ e24 = ''
|
|
|
+ e25 = ''
|
|
|
+ e26 = ''
|
|
|
+ e27 = ''
|
|
|
+ e28 = ''
|
|
|
+ e29 = ''
|
|
|
+ e30 = ''
|
|
|
+
|
|
|
+
|
|
|
+ conf1 = ''
|
|
|
+ conf2 = ''
|
|
|
+ conf3 = ''
|
|
|
+ conf4 = ''
|
|
|
+ conf5 = ''
|
|
|
+ conf6 = ''
|
|
|
+ conf7 = ''
|
|
|
+ conf8 = ''
|
|
|
+ conf9 = ''
|
|
|
+ conf10 = ''
|
|
|
+ conf11 = ''
|
|
|
+ conf12 = ''
|
|
|
+ conf13 = ''
|
|
|
+ conf14 = ''
|
|
|
+ conf15 = ''
|
|
|
+ conf16 = ''
|
|
|
+ conf17 = ''
|
|
|
+ conf18 = ''
|
|
|
+ conf19 = ''
|
|
|
+ conf20 = ''
|
|
|
+ conf21 = ''
|
|
|
+ conf22 = ''
|
|
|
+ conf23 = ''
|
|
|
+ conf24 = ''
|
|
|
+ conf25 = ''
|
|
|
+ conf26 = ''
|
|
|
+ conf27 = ''
|
|
|
+ conf28 = ''
|
|
|
+ conf29 = ''
|
|
|
+ conf30 = ''
|
|
|
+ for i in qxzdata:
|
|
|
+ if i['eKey'] == 'e1':
|
|
|
+ e1 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf1 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e1[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e2':
|
|
|
+ e2 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf2 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e2[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e3':
|
|
|
+ e3 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf3 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e3[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e4':
|
|
|
+ e4 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf4 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e4[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e5':
|
|
|
+ e5 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf5 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e5[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e6':
|
|
|
+ e6 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf6 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e6[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e7':
|
|
|
+ e7 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf7 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e7[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e8':
|
|
|
+ e8 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf8 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e8[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e9':
|
|
|
+ e9 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf9 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e9[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e10':
|
|
|
+ e10 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf10 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e10[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e11':
|
|
|
+ e11 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf11 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e11[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e12':
|
|
|
+ e12 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf12 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e12[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e13':
|
|
|
+ e13 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf13 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e13[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e14':
|
|
|
+ e14 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf14 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e14[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e15':
|
|
|
+ e15 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf15 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e15[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e16':
|
|
|
+ e16 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf16 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e16[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e17':
|
|
|
+ e17 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf17 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e17[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e18':
|
|
|
+ e18 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf18 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e18[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e19':
|
|
|
+ e19 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf19 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e19[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e20':
|
|
|
+ e20 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf20 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e20[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e21':
|
|
|
+ e21 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf21 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e21[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e22':
|
|
|
+ e22 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf22 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e22[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e23':
|
|
|
+ e23 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf23 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e23[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e24':
|
|
|
+ e24 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf24 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e24[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e25':
|
|
|
+ e25 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf25 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e25[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e26':
|
|
|
+ e26 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf26 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e26[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e27':
|
|
|
+ e27 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf27 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e27[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e28':
|
|
|
+ e28 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf28 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e28[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e29':
|
|
|
+ e29 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf29 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e29[0] == "#":
|
|
|
+ continue
|
|
|
+ elif i['eKey'] == 'e30':
|
|
|
+ e30 = str(i['eValue']) + '#' + str(i['eNum']) + '#' + str(i['eKey'])
|
|
|
+ conf30 = qxz_dict[i['eNum']][1] + '#' + qxz_dict[i['eNum']][2]
|
|
|
+ if e30[0] == "#":
|
|
|
+ continue
|
|
|
+ qxz_exist = Equip.objects.filter(equip_id=device_id)
|
|
|
+ # print("extdata:", extdata)
|
|
|
+ # 设备存在,进一步判断状态表是否存在:
|
|
|
+ times = datetime.datetime.now()
|
|
|
+ if qxz_exist.exists():
|
|
|
+ print("<-----this equip is existed!----->")
|
|
|
+ try:
|
|
|
+ e_id = Equip.objects.get(equip_id=device_id)
|
|
|
+ except:
|
|
|
+ print("<-----this equip didn't exist!----->")
|
|
|
+ try:
|
|
|
+ # 设备数据表直接储存数据
|
|
|
+ # QXZdata.objects.create(equip_id=e_id, qxz_data=extdata)
|
|
|
+ QXZdata_New.objects.create(equip_id=e_id,
|
|
|
+ e1=e1,e2=e2,e3=e3,e4=e4,e5=e5,e6=e6,e7=e7,e8=e8,e9=e9,e10=e10,
|
|
|
+ e11=e11,e12=e12,e13=e13,e14=e14,e15=e15,e16=e16,e17=e17,e18=e18,e19=e19,e20=e20,
|
|
|
+ e21=e21,e22=e22,e23=e23,e24=e24,e25=e25,e26=e26,e27=e27,e28=e28,e29=e29,e30=e30)
|
|
|
+
|
|
|
+ print("<-----data update success!----->")
|
|
|
+ except:
|
|
|
+ print("<-----data update failed!----->")
|
|
|
+
|
|
|
+ if QXZstatus_New.objects.filter(equip_id=e_id).exists():
|
|
|
+ print("<-----this equip's status is existed!----->")
|
|
|
+ try:
|
|
|
+ sta = QXZstatus_New.objects.get(equip_id=e_id)
|
|
|
+
|
|
|
+ sta.e1 = e1
|
|
|
+ sta.e2 = e2
|
|
|
+ sta.e3 = e3
|
|
|
+ sta.e4 = e4
|
|
|
+ sta.e5 = e5
|
|
|
+ sta.e6 = e6
|
|
|
+ sta.e7 = e7
|
|
|
+ sta.e8 = e8
|
|
|
+ sta.e9 = e9
|
|
|
+ sta.e10 = e10
|
|
|
+ sta.e11 = e11
|
|
|
+ sta.e12 = e12
|
|
|
+ sta.e13 = e13
|
|
|
+ sta.e14 = e14
|
|
|
+ sta.e15 = e15
|
|
|
+ sta.e16 = e16
|
|
|
+ sta.e17 = e17
|
|
|
+ sta.e18 = e18
|
|
|
+ sta.e19 = e19
|
|
|
+ sta.e20 = e20
|
|
|
+ sta.e21 = e21
|
|
|
+ sta.e22 = e22
|
|
|
+ sta.e23 = e23
|
|
|
+ sta.e24 = e24
|
|
|
+ sta.e25 = e25
|
|
|
+ sta.e26 = e26
|
|
|
+ sta.e27 = e27
|
|
|
+ sta.e28 = e28
|
|
|
+ sta.e29 = e29
|
|
|
+ sta.e30 = e30
|
|
|
+ sta.is_online = "1"
|
|
|
+ sta.save()
|
|
|
+ print("<-----status update success!----->")
|
|
|
+ except:
|
|
|
+ print("<-----status update failed!----->")
|
|
|
+ else:
|
|
|
+ # 设备状态表不存在、创建状态表:
|
|
|
+ print("<-----this equip's status is not existed!----->")
|
|
|
+ try:
|
|
|
+ QXZstatus_New.objects.create(equip_id=e_id,
|
|
|
+ e1=e1,e2=e2,e3=e3,e4=e4,e5=e5,e6=e6,e7=e7,e8=e8,e9=e9,e10=e10,
|
|
|
+ e11=e11,e12=e12,e13=e13,e14=e14,e15=e15,e16=e16,e17=e17,e18=e18,e19=e19,e20=e20,
|
|
|
+ e21=e21,e22=e22,e23=e23,e24=e24,e25=e25,e26=e26,e27=e27,e28=e28,e29=e29,e30=e30,is_online="1")
|
|
|
+
|
|
|
+ # QXZstatus.objects.create(equip_id=e_id, qxz_status=extdata)
|
|
|
+ print("<-----this equip's status table re-create successed!----->")
|
|
|
+ except:
|
|
|
+ print("<-----this equip's status table re-create failed!----->")
|
|
|
+ # 判断标题配置表
|
|
|
+ if QXZ_Conf.objects.filter(equip_id=e_id).exists():
|
|
|
+ print("------conf create default-------")
|
|
|
+ else:
|
|
|
+ QXZ_Conf.objects.create(equip_id=e_id,
|
|
|
+ e1=conf1,e2=conf2,e3=conf3,e4=conf4,e5=conf5,e6=conf6,e7=conf7,e8=conf8,e9=conf9,e10=conf10,
|
|
|
+ e11=conf11,e12=conf12,e13=conf13,e14=conf14,e15=conf15,e16=conf16,e17=conf17,e18=conf18,e19=conf19,e20=conf20,
|
|
|
+ e21=conf21,e22=conf22,e23=conf23,e24=conf24,e25=conf25,e26=conf26,e27=conf27,e28=conf28,e29=conf29,e30=conf30)
|
|
|
+ QXZ_Default_Conf.objects.create(equip_id=e_id,
|
|
|
+ e1=conf1,e2=conf2,e3=conf3,e4=conf4,e5=conf5,e6=conf6,e7=conf7,e8=conf8,e9=conf9,e10=conf10,
|
|
|
+ e11=conf11,e12=conf12,e13=conf13,e14=conf14,e15=conf15,e16=conf16,e17=conf17,e18=conf18,e19=conf19,e20=conf20,
|
|
|
+ e21=conf21,e22=conf22,e23=conf23,e24=conf24,e25=conf25,e26=conf26,e27=conf27,e28=conf28,e29=conf29,e30=conf30)
|
|
|
+ print("------conf create success-------")
|
|
|
+ # 设备状态表存在、刷新状态表:
|
|
|
+ print("2222222")
|
|
|
+
|
|
|
+
|
|
|
+ else:
|
|
|
+ print("<-----this equip not existed!----->")
|
|
|
+ # 设备不存在,在设备列表中创建:
|
|
|
+ try:
|
|
|
+ e_type = Equip_type.objects.get(type_id="5")
|
|
|
+ e_id = Equip.objects.create(equip_id=device_id, equip_type=e_type)
|
|
|
+ print("<-----this imei add successed!----->")
|
|
|
+ try:
|
|
|
+ # 设备数据表直接储存数据
|
|
|
+ QXZdata_New.objects.create(equip_id=e_id,
|
|
|
+ e1=e1,e2=e2,e3=e3,e4=e4,e5=e5,e6=e6,e7=e7,e8=e8,e9=e9,e10=e10,
|
|
|
+ e11=e11,e12=e12,e13=e13,e14=e14,e15=e15,e16=e16,e17=e17,e18=e18,e19=e19,e20=e20,
|
|
|
+ e21=e21,e22=e22,e23=e23,e24=e24,e25=e25,e26=e26,e27=e27,e28=e28,e29=e29,e30=e30)
|
|
|
+ # QXZdata.objects.create(equip_id=e_id, qxz_data=extdata)
|
|
|
+ print("<-----data update success!----->")
|
|
|
+ except:
|
|
|
+ print("<-----data update failed!----->")
|
|
|
+ try:
|
|
|
+ QXZstatus_New.objects.create(equip_id=e_id,
|
|
|
+ e1=e1,e2=e2,e3=e3,e4=e4,e5=e5,e6=e6,e7=e7,e8=e8,e9=e9,e10=e10,
|
|
|
+ e11=e11,e12=e12,e13=e13,e14=e14,e15=e15,e16=e16,e17=e17,e18=e18,e19=e19,e20=e20,
|
|
|
+ e21=e21,e22=e22,e23=e23,e24=e24,e25=e25,e26=e26,e27=e27,e28=e28,e29=e29,e30=e30,is_online="1")
|
|
|
+ # QXZstatus.objects.create(equip_id=e_id, qxz_status=extdata)
|
|
|
+ print("<-----this imei register successed!----->")
|
|
|
+ except:
|
|
|
+ print("<-----this imei register failed!----->")
|
|
|
+
|
|
|
+ # 判断标题配置表
|
|
|
+ if QXZ_Conf.objects.filter(equip_id=e_id).exists():
|
|
|
+ print("------conf create default-------")
|
|
|
+ else:
|
|
|
+ QXZ_Conf.objects.create(equip_id=e_id,
|
|
|
+ e1=conf1,e2=conf2,e3=conf3,e4=conf4,e5=conf5,e6=conf6,e7=conf7,e8=conf8,e9=conf9,e10=conf10,
|
|
|
+ e11=conf11,e12=conf12,e13=conf13,e14=conf14,e15=conf15,e16=conf16,e17=conf17,e18=conf18,e19=conf19,e20=conf20,
|
|
|
+ e21=conf21,e22=conf22,e23=conf23,e24=conf24,e25=conf25,e26=conf26,e27=conf27,e28=conf28,e29=conf29,e30=conf30)
|
|
|
+ QXZ_Default_Conf.objects.create(equip_id=e_id,
|
|
|
+ e1=conf1,e2=conf2,e3=conf3,e4=conf4,e5=conf5,e6=conf6,e7=conf7,e8=conf8,e9=conf9,e10=conf10,
|
|
|
+ e11=conf11,e12=conf12,e13=conf13,e14=conf14,e15=conf15,e16=conf16,e17=conf17,e18=conf18,e19=conf19,e20=conf20,
|
|
|
+ e21=conf21,e22=conf22,e23=conf23,e24=conf24,e25=conf25,e26=conf26,e27=conf27,e28=conf28,e29=conf29,e30=conf30)
|
|
|
+ print("------conf create success-------")
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ print("<-----this imei add failed!----->")
|
|
|
+
|
|
|
+ if payload.get("cmd") == "Status":
|
|
|
+ extdata = payload.get("ext")['terminalStatus']
|
|
|
+ print(extdata)
|
|
|
+ try:
|
|
|
+ volt = extdata["VOLT"]
|
|
|
+ rssi = extdata["RSSI"]
|
|
|
+ iccid = extdata["ICCID"]
|
|
|
+ lng = extdata["longitude"]
|
|
|
+ lat = extdata["latitude"]
|
|
|
+ led = extdata["Dotled"]
|
|
|
+
|
|
|
+ except:
|
|
|
+ pass
|
|
|
+ try:
|
|
|
+ dver = extdata["Version"]
|
|
|
+ except:
|
|
|
+ dver = ""
|
|
|
+ if qxz_exist.exists():
|
|
|
+ print("<-----this equip is existed!----->")
|
|
|
+ try:
|
|
|
+ e_id = Equip.objects.get(equip_id=device_id)
|
|
|
+ except:
|
|
|
+ print("<-----this equip didn't exist!----->")
|
|
|
+ QXZ_Info_Record.objects.create(equip_id=e_id, volt=volt,rssi=rssi)
|
|
|
+ if QXZ_Base_Info.objects.filter(equip_id=e_id).exists():
|
|
|
+ print("<-----this qxz_base_info is existed!----->")
|
|
|
+ try:
|
|
|
+ sta = QXZ_Base_Info.objects.get(equip_id=device_id)
|
|
|
+ sta.volt = volt
|
|
|
+ sta.rssi = rssi
|
|
|
+ sta.iccid = iccid
|
|
|
+ sta.lng = lng
|
|
|
+ sta.lat = lat
|
|
|
+ sta.led = led
|
|
|
+ sta.dver = dver
|
|
|
+ sta.save()
|
|
|
+ sta1 = Equip.objects.get(equip_id=device_id)
|
|
|
+ sta1.lng = lng
|
|
|
+ sta1.lat = lat
|
|
|
+ sta1.save()
|
|
|
+ print("<-----qxz_base_info update success!----->")
|
|
|
+ except:
|
|
|
+ print("<-----qxz_base_info update failed!----->")
|
|
|
+ try:
|
|
|
+ sta = QXZ_Base_Info.objects.get(equip_id=device_id)
|
|
|
+ sta.volt = volt
|
|
|
+ sta.rssi = rssi
|
|
|
+ sta.save()
|
|
|
+ print("<-----qxz_base_info update success!!!----->")
|
|
|
+ except:
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ # 设备阈值表不存在、创建阈值表:
|
|
|
+ print("<-----this qxz_base_info is not existed!----->")
|
|
|
+ try:
|
|
|
+ QXZ_Base_Info.objects.create(equip_id=device_id, volt=volt,rssi=rssi,iccid=iccid,lng=lng,lat=lat,led=led)
|
|
|
+ print("<-----this qxz_base_info table re-create successed!----->")
|
|
|
+ except:
|
|
|
+ print("<-----this qxz_base_info table re-create failed!----->")
|
|
|
+
|
|
|
+
|
|
|
+ return HttpResponse("1")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+# 气象站数据导出接口
|
|
|
+class QXZ_Data_Export(ListView):
|
|
|
+ def get(self,request):
|
|
|
+ equip_id = request.GET.get('id')
|
|
|
+ print("请求数据的设备id:",equip_id)
|
|
|
+ f_tbegin = request.GET.get('begin')
|
|
|
+ f_tend = request.GET.get('end')
|
|
|
+ filename = request.GET.get('filename')
|
|
|
+ print("f_tbegin:", f_tbegin)
|
|
|
+ print("f_tend:", f_tend)
|
|
|
+ print("f_tbegin:", type(f_tbegin))
|
|
|
+ print("f_tend:", type(f_tend))
|
|
|
+ # 查询时间段
|
|
|
+ if f_tbegin:
|
|
|
+ begindate = re.findall(r"\d+\.?\d*", f_tbegin)
|
|
|
+ enddate = re.findall(r"\d+\.?\d*", f_tend)
|
|
|
+ start_date = datetime.date(int(begindate[0]), int(begindate[1]), int(begindate[2]))
|
|
|
+ end_date = datetime.date(int(enddate[0]), int(enddate[1]), int(enddate[2]))
|
|
|
+ print("start_date:", start_date)
|
|
|
+ print("end_date:", end_date)
|
|
|
+ sta1 = QXZdata.objects.filter(equip_id=equip_id, upl_time__range=(start_date, end_date))
|
|
|
+ print("sta1:", sta1)
|
|
|
+ sta2 = [{"equip_name": x.equip_id.equip_name,
|
|
|
+ "qxz_data": eval(x.qxz_data)["data"],
|
|
|
+ "upl_time": x.upl_time.strftime("%Y-%m-%d %H:%M:%S")} for x in sta1]
|
|
|
+ # 查询全部
|
|
|
+ else:
|
|
|
+ sta1 = QXZdata.objects.filter(equip_id=equip_id)
|
|
|
+ print("sta1:",sta1)
|
|
|
+ sta2 = [{"equip_name": x.equip_id.equip_name,
|
|
|
+ "qxz_data": eval(x.qxz_data)["data"],
|
|
|
+ "upl_time": x.upl_time.strftime("%Y-%m-%d %H:%M:%S")} for x in sta1]
|
|
|
+ # print(sta2)
|
|
|
+ try:
|
|
|
+ # 遍历标题
|
|
|
+ title = []
|
|
|
+ for aaa in sta2[0]['qxz_data']:
|
|
|
+ # print(qxz_dict[aaa['eNum']][1])
|
|
|
+ title.append(qxz_dict[aaa['eNum']][1]+aaa['eKey'])
|
|
|
+ title.append("上报时间")
|
|
|
+ print(title)
|
|
|
+ # print(sta2[0]['qxz_data'])
|
|
|
+ except:
|
|
|
+ book = xlwt.Workbook() # 创建一个excel对象
|
|
|
+ sheet = book.add_sheet('Sheet1',cell_overwrite_ok=True) # 添加一个sheet页
|
|
|
+ sheet.write(0,0,"错误的时间段") # 将title数组中的字段写入到0行i列中
|
|
|
+ # 写出到IO
|
|
|
+ output = BytesIO()
|
|
|
+ book.save(output)
|
|
|
+ # 重新定位到开始
|
|
|
+ output.seek(0)
|
|
|
+ response = HttpResponse(content_type='application/vnd.ms-excel')
|
|
|
+ response['Content-Disposition'] = 'attachment;filename=%s.xls'%filename
|
|
|
+ response.write(output.getvalue())
|
|
|
+ return response
|
|
|
+
|
|
|
+
|
|
|
+ book = xlwt.Workbook() # 创建一个excel对象
|
|
|
+ sheet = book.add_sheet('Sheet1',cell_overwrite_ok=True) # 添加一个sheet页
|
|
|
+ for i in range(len(title)): # 遍历列
|
|
|
+ sheet.write(0,i,title[i]) # 将title数组中的字段写入到0行i列中
|
|
|
+
|
|
|
+ for x in range(len(sta2)): # 遍历列表
|
|
|
+ # print("行",x)
|
|
|
+ for xx in range(len(title)):
|
|
|
+ print("行",x+1,"列",xx)
|
|
|
+ # print(sta2[x]["qxz_data"][xx-1])
|
|
|
+ if xx+1 == len(title):
|
|
|
+ # print(x+1,xx,sta2[x]["upl_time"])
|
|
|
+ sheet.write(x+1,xx,sta2[x]["upl_time"])
|
|
|
+ break
|
|
|
+ # print(x+1,xx,sta2[x]["qxz_data"][xx]["eValue"]+" "+qxz_dict[sta2[x]["qxz_data"][xx]["eNum"]][2])
|
|
|
+ sheet.write(x+1,xx,sta2[x]["qxz_data"][xx]["eValue"]+" "+qxz_dict[sta2[x]["qxz_data"][xx]["eNum"]][2])
|
|
|
+
|
|
|
+ # 写出到IO
|
|
|
+ output = BytesIO()
|
|
|
+ book.save(output)
|
|
|
+ # 重新定位到开始
|
|
|
+ output.seek(0)
|
|
|
+ response = HttpResponse(content_type='application/vnd.ms-excel')
|
|
|
+ response['Content-Disposition'] = 'attachment;filename=%s.xls'%filename
|
|
|
+ response.write(output.getvalue())
|
|
|
+ return response
|
|
|
+
|
|
|
+
|
|
|
+ def post(self,request):
|
|
|
+ pass
|