|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
@Date:2022/07/13 17:03:20
|
|
|
|
'''
|
|
|
|
from django.views.decorators.http import require_http_methods
|
|
|
|
from django.shortcuts import HttpResponse, render, redirect
|
|
|
|
|
|
|
|
|
|
|
|
from Business.Warning import BllWarning
|
|
|
|
from Common.utils import Utils, logger
|
|
|
|
from Business.User import BllUser
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Utils.log_exception
|
|
|
|
@require_http_methods(['GET'])
|
|
|
|
def home(request):
|
|
|
|
# 获取预警数量
|
|
|
|
visitType = ''
|
|
|
|
try:
|
|
|
|
|
|
|
|
user_ = request.session['login_user']
|
|
|
|
user_id = user_["UserId"]
|
|
|
|
user = BllUser().findEntity(user_id)
|
|
|
|
role_id = user.RoleId
|
|
|
|
SQL = """
|
|
|
|
|
|
|
|
SELECT c.module_id, c.module_code, c.sort_index, c.module_name from(SELECT a.module_id, b.module_code,
|
|
|
|
b.sort_index, b.module_name FROM `rms_module_relation` as a LEFT JOIN rms_module as b on a.module_id =
|
|
|
|
b.module_id WHERE object_id = :user_id and object_type = 2 and a.module_type=2 UNION
|
|
|
|
SELECT a.module_id, b.module_code, b.sort_index, b.module_name FROM `rms_module_relation` as a
|
|
|
|
LEFT JOIN rms_module as b on a.module_id = b.module_id WHERE object_id = :role_id and object_type = 1 and a.module_type=2)
|
|
|
|
as c ORDER BY c.sort_index asc;
|
|
|
|
"""
|
|
|
|
module_relation_obj_list = BllUser().execute(
|
|
|
|
SQL, {'user_id': user_id, 'role_id': role_id}).fetchall()
|
|
|
|
module_relation_obj_list = Utils.mysqlTable2Model(
|
|
|
|
module_relation_obj_list)
|
|
|
|
|
|
|
|
# 用列表推导式生成一个ModuleCode列表
|
|
|
|
object_id_list = [x['module_code']
|
|
|
|
for x in module_relation_obj_list]
|
|
|
|
|
|
|
|
print(object_id_list)
|
|
|
|
#SQL = 'SELECT count(*) as number_ FROM `RMS_Warning` WHERE IsSolve = 0 and now() > WarningDate;'
|
|
|
|
SQL = 'SELECT count(*) as number_ FROM `rms_warning` WHERE is_solve = 0'
|
|
|
|
warning_obj = BllWarning().execute(SQL).fetchone()
|
|
|
|
warning_nb = warning_obj.number_
|
|
|
|
try:
|
|
|
|
user = request.session['login_user']
|
|
|
|
roleName = user['RoleName']
|
|
|
|
visitType = request.GET.get('visitType')
|
|
|
|
request.session['visitType'] = visitType
|
|
|
|
# if(((visitType=='1') or (visitType=='2'))):
|
|
|
|
# request.session['visitType']='1'
|
|
|
|
# else:
|
|
|
|
# request.session['visitType']=''
|
|
|
|
request.session.set_expiry(0)
|
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
|
|
|
roleName = ''
|
|
|
|
return render(request, 'home.html', locals())
|
|
|
|
except Exception as e:
|
|
|
|
BllWarning().session.rollback()
|
|
|
|
logger.debug('数据为空', e)
|
|
|
|
return render(request, 'home.html', locals())
|
|
|
|
finally:
|
|
|
|
BllWarning().session.close()
|
|
|
|
|
|
|
|
|
|
|
|
# 404页面处理方案
|
|
|
|
def page_not_found(request, exception):
|
|
|
|
logger.debug('页面没有找到')
|
|
|
|
return HttpResponse('地址错误')
|