safesite/safesite/datashowview.py

54 lines
2.4 KiB
Python

from django.shortcuts import render,redirect,render_to_response
from django.http import HttpResponse, HttpResponseRedirect,JsonResponse
from .models import User,Trouble,Dickey,Partment,Dicclass,Train,Drill,TroubleAccess,Group,Yjyc,Trainuser,Drilluser,Yjsetup,Menu,Observe,Observeto,Unsafes,Miss,Socertificate,Userprofile,Suggest,Notice,Noticeto,Operation,Operzyry,Fxcs,Operationspjd,Operspxq,Question,ExamPaper,ExamTest,ExamPaperDetail,ExamTestDetail,Questioncat,Safecert,Map,Area,Missto,Suggestflow,Equipment,Inspect,Risk,RiskAct
from django.template import RequestContext
from django.views.decorators.csrf import csrf_exempt
from django.core import serializers
import json
from uuid import UUID
import os
import time
from datetime import datetime,date,timedelta
from django.db.models import F,Count,Sum
import requests
from .tasks import send_wechatmsgs,send_wechatmsg,yjjs,gettime,yjjs_px,yjjs_yl,updateTzzs,updateAqzs
from .export import exportdoc,exportxlsx,exportyjdoc,exportsimplexlsx,exportdoc2
from .daoru import drusers,drequipments,drrisks
from django.forms.models import model_to_dict
from .safespider import getTzzs,getAqzs
# from duibiao import calsim
from django.db.models import Q
from django.core.serializers.json import DjangoJSONEncoder
from io import StringIO
import operator
import jwt
def area(req):
userid = req.session['userid']
companyid = getcompany(userid)
first_day,first_day_of_next_month=gettime()
#隐患排查列表
troubles = Trouble.objects.filter(usecomp__partid=companyid).exclude(deletemark=0).order_by('-xgsj')[:7]
#本月线下培训数量
b = Train.objects.filter(usecomp__partid=companyid,deletemark=1)
pxnum = b.filter(state=0,submituser__userid=userid).count()
totalpx = b.count()
monthpx = b.filter(starttime__range=(first_day, first_day_of_next_month)).count()
#本月行为观察数量
gcobjs = Observe.objects.filter(deletemark=1,usecomp__partid=companyid)
gcnum = gcobjs.filter(looktime__range=(first_day,first_day_of_next_month)).count()
monthgc = gcobjs.filter(submittime__range=(first_day, first_day_of_next_month)).count()
return render(req,'datashow.html', {'troubles':troubles, 'px':monthpx, 'xw':monthgc})
#获取user所在公司
def getcompany(x):
a = User.objects.get(userid = x)
if a.ubelongpart.iscompany == 1:
return str(a.ubelongpart.partid)
else:
return a.ubelongpart.partlink.split(',')[1]