# usr/bin/python3
# conding:utf-8
# 吕康宁,20201216
# RFID定位系统业务逻辑
# Create your views here.
from django.shortcuts import render
from .models import Device,Building,Scanner,Efence,Alarm,Myuser,Map_Data,Sys_Log,Command_Log,Person,Asset,Asset_Kind,Tag,Warehouse
from django.contrib.auth.models import User
from django.apps import apps
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponseRedirect,Http404,HttpResponse,FileResponse
from django.urls import reverse
from django.forms.models import model_to_dict
from django.contrib.auth import login,logout,authenticate
from django.contrib.auth.decorators import login_required
import redis
import numpy as np
import pandas as pd
from rest_framework import viewsets
from rest_framework.views import APIView
from rest_framework.views import Response
from data_handle.create_device_table import *
# from data_handle.compute.report_compute import start_cacu
import datetime,json,random,time,uuid,requests,math
from math import pi,sin,cos
import base64,threading,sys,os
# from .phone_app_api import *
from dwebsocket.decorators import accept_websocket,require_websocket
from sqlalchemy import desc
# ffmpeg的python封装,转换音视频,目前用途为转换小程序过来的aac为amr,下发给设备
import ffmpy3
from data_handle.change_lnglat import *
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
Device_Base = automap_base()
Device_Base.prepare(engine, reflect=True)
pool_redis= redis.ConnectionPool(host='localhost',port=6379,decode_responses=True)
mesg_redis=redis.Redis(connection_pool=pool_redis)
def base_respone():
return {'code':1000,'data':'','error':'','msg':'操作成功'}
# 系统初次步数之后登陆,创建超级管理员账号
def init_superuser():
admin_user=Myuser.objects.filter(username='admin').first()
# Myuser.objects.filter(username='admin').update(kind='superuser')
if admin_user==None:
superuser={'username':'admin','visible_name':'超级管理员','phone':'0','leader':'0','subordinate':'0','kind':'superuser','character':{'kind':'superuser','user_icon':'/static/img/default.png','refresh_time':'60','alarm_audio':'on','alarm_show':'on','contact':'admin'},
'status':'on','remark':'0'}
Myuser.objects.create(**(superuser))
init_superuser()
# 登录
@csrf_exempt
def logins(request):
what=request.GET.get('what')
if request.method=='GET':
if what=='demo':
user=authenticate(username='demo',password='123456')
if user is not None:
if user.is_active:
login(request,user)
errors=0
# 记录操作日志
system_log(request,'登录')
all_data=get_index_page_data(request)
return render(request,'tag_app/index.html',all_data)
if request.method=='POST':
name=request.POST.get('username')
pwd=request.POST.get('password')
request.data={'username':name,'password':pwd}
print(request.data)
result=login_func(request)
if result['code']==1000:
user=authenticate(username=name,password=pwd)
login(request,user)
print(result)
return HttpResponse(json.dumps(result))
return render(request,'tag_app/login.html')
# ----首页start---- #
def get_index_page_data(request):
username=str(request.user)
user_self=Myuser.objects.filter(username=username).first()
user_self=vars(user_self)
user_self.pop('_state')
character=user_self['character']
character=eval(character)
sub_user_result=get_subordinate_user(username,Myuser)
sub_user=sub_user_result[0]
user_tree=sub_user_result[1]
all_user=sub_user.copy()
all_user.append(username)
device=get_device_detail(all_user)
alarm_data=get_alarm_data(all_user)
building=list(Building.objects.filter(owner__in=all_user).values())
scanner=list(Scanner.objects.filter(owner__in=all_user).values())
map_data=list(Map_Data.objects.filter(owner__in=all_user).values())
sub_user_detail=list(Myuser.objects.filter(username__in=sub_user).values())
dev_model=get_device_model()
# 数据汇总
all_data={'device':device,'alarm_data':alarm_data,'building':building,'scanner':scanner,'dev_model':dev_model,
'map_data':map_data,'sub_user_detail':sub_user_detail,'user_tree':user_tree,'user_self':user_self,'character':character}
return all_data
@login_required
@csrf_exempt
def index(request):
res=base_respone()
username=str(request.user)
subordinate_user=get_subordinate_user(username,Myuser)[0]
subordinate_user.append(str(request.user))
what=request.GET.get('what')
if request.method=='GET':
if what=='get_alarm':
alarm_data=get_alarm_data(subordinate_user)
# 报警模拟数据
if len(alarm_data)==0:
dev=Device.objects.filter(owner__in=subordinate_user).first()
if dev!=None:
pt=simulate_point(dev.device_id)
# ln=str({'satelite':[pt['lng'],pt['lat']]})
ln={'wifi': "[{'ssid': 'a', 'mac': '78:f5:57:0a:ef:44', 'rssi': '61'}, {'ssid': 'a', 'mac': '78:f5:57:0a:ef:44', 'rssi': '61'}, {'ssid': 'a', 'mac': '78:58:60:99:ac:6c', 'rssi': '57'}]"}
alarm_data=[{'name':'circleefence001',
'device_id':dev.device_id,
'location':str(ln),
'content':'模拟数据',
'kind':'circle',
's_time':'0',
'e_time':'0',
'handle':'no',
'remark':'0',
'owner':'demo',
'id':1}]
res['data']=alarm_data
return HttpResponse(json.dumps(res))
if request.method=='POST':
# 报警信息处理
if what=='handle_alarm':
handle_data=eval(request.POST.get('base_info'))
handle_result=handle_alarm(request,handle_data)
return HttpResponse(json.dumps(handle_result))
# 修改密码
elif what=='handle_password':
handle_data=eval(request.POST.get('base_info'))
handle_result=handle_password(request,handle_data)
return HttpResponse(json.dumps(handle_result))
elif what=='get_wifi_lbs_addr':
handle_data=eval(request.POST.get('base_info'))
track_type=handle_data.get('track_type')
device_id=handle_data.get('device_id')
track_data=handle_data.get('track_data')
address_result=eval('get_'+track_type+'_address('+track_data+','+device_id+')')
# print('address=====',address_result)
address='0'
if address_result!='':
loca=address_result[2]
if isinstance(loca,dict):
loca=loca['desc']
else:
loca=eval(loca)
loca=loca['desc']
lnglat=wgs84_to_bd09(float(address_result[0]),float(address_result[1]))
# if map_kind=='bd':
# lnglat=wgs84_to_bd09(float(address_result[0]),float(address_result[1]))
# elif map_kind=='gd':
# lnglat=wgs84_to_gcj02(float(address_result[0]),float(address_result[1]))
address={'lng':lnglat['lng'],'lat':lnglat['lat'],'location':loca}
res['data']=address
return HttpResponse(json.dumps(res))
all_data=get_index_page_data(request)
return render(request,'tag_app/index.html',all_data)
def handle_alarm(request,handle_data):
res=base_respone()
# 参数校验
param_list=['alarm_name_list','alarm_handle_mark']
handle_data=post_param_check(param_list,handle_data)
if handle_data.get('param_error')!=None:
res['error']=handle_data.get('param_error')
res['code']=1234
return res
alarm_name=handle_data.get('alarm_name_list')
handle=handle_data.get('alarm_handle_mark')
res['error']=[]
for x in alarm_name:
if Alarm.objects.filter(name=x).first()!=None:
Alarm.objects.filter(name=x).update(handle=handle)
else:
res['code']=1234
res['error'].append(x)
sys_re=''
if res['code']==1000:
sys_re='成功'
alarm_data=get_alarm_data(subordinate_user)
res['data']=alarm_data
else:
sys_re='失败'
res['error']=str(res['error'])+'不存在'
res['msg']='报警信息处理成功'
system_log(request,'处理-'+str(alarm_name)+'-报警',sys_re)
return res
# 实时监控页面渲染
@login_required
@csrf_exempt
def dynamic(request):
subordinate_user=get_subordinate_user(str(request.user),Myuser)[0]
subordinate_user.append(str(request.user))
what=request.GET.get('what')
res=base_respone()
if request.method=='GET':
if what=='get
lsx202406
- 粉丝: 2587
- 资源: 5607
最新资源
- Vue相关开源项目库汇总.zip
- YouTube 上的“VueJS 2 - Vuex 基础知识”系列的源代码.zip
- LibGD 是一个开源的图像处理库,支持 PNG/JPEG/GIF以及其他格式的图像,涵盖了广泛的编程语言,包括 C、Perl 和 PHP 等 核心功能是提供了一套丰富的 API,使得开发者能够轻松地
- 适用于 Vue.js 的极简主义深色设计系统 基于专为像我们一样喜欢深色界面的失眠症患者设计的组件 .zip
- “Vue.js 的奇妙世界”教程背后的截屏代码、脚本和纸杯蛋糕.zip
- Java安卓开发 简易表白软件开发 -第1期
- Java安卓开发 简易表白软件开发(安装包) -第1期
- 断言学习文档,如何使用
- 【vue2项目模块版】基于vue和element-ui的神奇vue管理模板.zip
- 停止维护网易云音乐网页版,支持PC端常用功能,localStorage保存播放列表.zip
- 我便笺electron11+vue3ts开发,所见所得的markdown创作,多开窗口本地储存 (我笔记采用 Electron11+vue3ts 开发,所见即所得的 markdown .zip
- 一个 repo,展示了单独的 Vue 应用作为微前端与 Single-spa 共存.zip
- 一个Vue+Cnavas酷炫背景线条线条.zip
- 一个专注于前端视觉效果的集合应用,包含CSS动效、Canvas动画、Three.js3D、人工智能应用等上百个案例(Vue版本).zip
- 一个基于 vue+vue-cli+vue-router+axios+ scss 的简单项目(Vue Community SPA) .zip
- 一个基于 Weex 的丰富交互、轻量级、高性能的 UI 库 .zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈