Skip to content

Commit

Permalink
允许dba自己申请和执行语句
Browse files Browse the repository at this point in the history
SQL审核和工单详情改成分页模式
工作流审核列表修改为代办列表,改为图标展示
update readme
  • Loading branch information
hhyo authored and 李环焕 committed Jun 7, 2018
1 parent e73cd6b commit 2380613
Show file tree
Hide file tree
Showing 15 changed files with 245 additions and 567 deletions.
257 changes: 86 additions & 171 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion archer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'Asia/Shanghai'

Expand Down
1 change: 1 addition & 0 deletions sql/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class DataMaskingColumnsAdmin(admin.ModelAdmin):
list_display = (
'column_id', 'rule_type', 'active', 'cluster_name', 'table_schema', 'table_name', 'column_name',
'create_time',)
search_fields = ['cluster_name', 'table_schema', 'table_name', 'column_name']


# 脱敏规则页面定义
Expand Down
12 changes: 10 additions & 2 deletions sql/data_masking.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,16 @@ def query_table_ref(self, sqlContent, cluster_name, dbName):
result['status'] = 2
result['msg'] = 'inception返回异常:\n' + print_info['errmsg']
else:
table_ref = json.loads(print_info['query_tree'])['table_ref']
result['data'] = table_ref
try:
table_ref = json.loads(print_info['query_tree'])['table_ref']
except Exception:
# 处理JSONDecodeError: Expecting property name enclosed in double quotes
# json出现{"a":1,}、["a":1,]、{'a':1}
query_tree_str = re.sub(r"(,?)(\w+?)\s*?:", r"\1'\2':", print_info['query_tree'])
query_tree_str = re.sub(r",\s*?]", "]", query_tree_str)
query_tree_str = re.sub(r",\s*?}", "}", query_tree_str)
query_tree_str = query_tree_str.replace("'", "\"")
table_ref = json.loads(query_tree_str)['table_ref']
return result

# 解析query_tree,获取语句信息,并返回命中脱敏规则的列信息
Expand Down
16 changes: 11 additions & 5 deletions sql/processor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: UTF-8 -*-
# -*- coding: UTF-8 -*-
from sql.workflow import Workflow
from .models import users
from django.conf import settings

Expand All @@ -12,9 +13,7 @@
{'key': 'sqladvisor', 'name': 'SQL优化工具', 'url': '/sqladvisor/', 'class': 'glyphicon glyphicon-wrench',
'display': settings.SQLADVISOR},
{'key': 'queryapply', 'name': '查询权限管理', 'url': '/queryapplylist/', 'class': 'glyphicon glyphicon-eye-open',
'display': settings.QUERY},
{'key': 'workflow', 'name': '工单审核管理', 'url': '/workflow/', 'class': 'glyphicon glyphicon-shopping-cart',
'display': settings.QUERY},
'display': settings.QUERY}
)

leftMenuBtnsSuper = (
Expand Down Expand Up @@ -42,12 +41,19 @@ def global_info(request):
leftMenuBtns = leftMenuBtnsCommon + leftMenuBtnsSuper + leftMenuBtnsDoc
else:
leftMenuBtns = leftMenuBtnsCommon + leftMenuBtnsDoc
# 获取代办数量
try:
todo = Workflow().auditlist(user, 0, 0, 1)['data']['auditlistCount']
except Exception:
todo = 0
else:
leftMenuBtns = ()
UserDisplay = ''
todo = 0

return {
'loginUser': loginUser,
'leftMenuBtns': leftMenuBtns,
'UserDisplay': UserDisplay
'UserDisplay': UserDisplay,
'todo': todo
}
6 changes: 4 additions & 2 deletions sql/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
from django.db.models import Q, Min, F, Sum
from django.db import connection
from django.conf import settings
from django.db.models.functions import Concat
from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse, HttpResponseRedirect
from django.core import serializers
from django.db import transaction
from datetime import date
from django.db.models import Value as V
import datetime
import time

Expand Down Expand Up @@ -939,7 +941,7 @@ def slowquery_review_history(request):
ts_min__range=(StartTime, EndTime)
).annotate(ExecutionStartTime=F('ts_min'), # 执行开始时间
DBName=F('db_max'), # 数据库名
HostAddress=F('user_max'), # 用户名
HostAddress=Concat('client_max', V('@'), 'user_max'), # 用户名
SQLText=F('sample'), # SQL语句
QueryTimes=F('query_time_sum'), # 执行时长(秒)
LockTimes=F('lock_time_sum'), # 锁定时长(秒)
Expand All @@ -964,7 +966,7 @@ def slowquery_review_history(request):
ts_min__range=(StartTime, EndTime)
).annotate(ExecutionStartTime=F('ts_min'), # 执行开始时间
DBName=F('db_max'), # 数据库名
HostAddress=F('user_max'), # 用户名
HostAddress=Concat('client_max', V('@'), 'user_max'), # 用户名
SQLText=F('sample'), # SQL语句
QueryTimes=F('query_time_sum'), # 执行时长(秒)
LockTimes=F('lock_time_sum'), # 锁定时长(秒)
Expand Down
170 changes: 92 additions & 78 deletions sql/static/base.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>自动化运维平台</title>
<title>自动化运维平台</title>
{% load staticfiles %}
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 引入 Bootstrap -->
<link href="{% static 'bootstrap-3.3.7-dist/css/bootstrap.min.css' %}" rel="stylesheet">
<link href="{% static 'user/css/user1.css' %}" rel="stylesheet">
<link href="{% static 'dist/css/bootstrap-select.css' %}" rel="stylesheet">
<link href="{% static 'bootstrap-table/css/bootstrap-table.min.css' %}" rel="stylesheet" type="text/css">
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 引入 Bootstrap -->
<link href="{% static 'bootstrap-3.3.7-dist/css/bootstrap.min.css' %}" rel="stylesheet">
<link href="{% static 'user/css/user1.css' %}" rel="stylesheet">
<link href="{% static 'dist/css/bootstrap-select.css' %}" rel="stylesheet">
<link href="{% static 'bootstrap-table/css/bootstrap-table.min.css' %}" rel="stylesheet" type="text/css">

<!-- HTML5 Shim 和 Respond.js 用于让 IE8 支持 HTML5元素和媒体查询 -->
<!-- 注意: 如果通过 file:// 引入 Respond.js 文件,则该文件无法起效果 -->
<!--[if lt IE 9]>
<!-- HTML5 Shim 和 Respond.js 用于让 IE8 支持 HTML5元素和媒体查询 -->
<!-- 注意: 如果通过 file:// 引入 Respond.js 文件,则该文件无法起效果 -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
Expand All @@ -23,81 +23,95 @@

<div class="container-fluid">

<!--最顶部导航栏 -->
<div class="row clearfix">
<div class="col-md-12 column">
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button> <a class="navbar-brand" href="/allworkflow/"><strong>自动化运维平台</strong></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
<a href="#">你好,{{UserDisplay}}</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">个人设置<strong class="caret"></strong></a>
<ul class="dropdown-menu">
<li>
<a href="/admin/password_change/">修改密码</a>
</li>
<li>
<a href="/logout/">退出</a>
</li>
</ul>
</li>
</ul>
</div>
</nav>
</div>
</div>
<!--最顶部导航栏 -->
<div class="row clearfix">
<div class="col-md-12 column">
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse"
data-target="#bs-example-navbar-collapse-1"><span
class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span
class="icon-bar"></span><span class="icon-bar"></span></button>
<a class="navbar-brand" href="/allworkflow/"><strong>自动化运维平台</strong></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
{% if todo == 0 %}
<li>
<a href="/workflow/"><span class="glyphicon glyphicon-shopping-cart"></span></a>
</li>
{% else %}
<li>
<a href="/workflow/"><span class="glyphicon glyphicon-envelope"></span></a>
</li>
{% endif %}
<li>
<a href="#">你好,{{ UserDisplay }}</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">个人设置<strong
class="caret"></strong></a>
<ul class="dropdown-menu">
<li>
<a href="/admin/password_change/">修改密码</a>
</li>
<li>
<a href="/logout/">退出</a>
</li>
</ul>
</li>
</ul>
</div>
</nav>
</div>
</div>

<!--中间左侧菜单栏和右侧主要内容区,网格分别为2和10 -->
<div class="row clearfix">
<div class="col-md-2 column">
<div class="list-group">
{% for menu in leftMenuBtns %}
<!--中间左侧菜单栏和右侧主要内容区,网格分别为2和10 -->
<div class="row clearfix">
<div class="col-md-2 column">
<div class="list-group">
{% for menu in leftMenuBtns %}
{% if menu.display %}
{% if menu.key == currentMenu %}
<a href="{{menu.url}}" class="list-group-item active"
{% else %}
<a href="{{menu.url}}" class="list-group-item"
{% endif %}
{% if menu.key == currentMenu %}
<a href="{{ menu.url }}" class="list-group-item active"
{% else %}
<a href="{{ menu.url }}" class="list-group-item"
{% endif %}

{% if menu.key == 'admin' %}
target="_blank"><span class="{{menu.class}}">&nbsp;{{menu.name}}</span></a>
{% else %}
><span class="{{menu.class}}">&nbsp;{{menu.name}}</span></a>
{% endif %}
{% if menu.key == 'admin' %}
target="_blank"><span class="{{ menu.class }}">&nbsp;{{ menu.name }}</span></a>
{% else %}
><span class="{{ menu.class }}">&nbsp;{{ menu.name }}</span></a>
{% endif %}
{% endfor %}
<!-- <a href="#" class="list-group-item"><span class="glyphicon glyphicon glyphicon-cog">&nbsp;审批人权限</span></a>
<a href="#" class="list-group-item"><span class="glyphicon glyphicon glyphicon glyphicon-file">&nbsp;功能模块6</span></a>
<a href="#" class="list-group-item"><span class="glyphicon glyphicon glyphicon glyphicon-list-alt">&nbsp;功能模块7</span></a>
<a href="#" class="list-group-item"><span class="glyphicon glyphicon glyphicon glyphicon-align-right">&nbsp;功能模块8</span></a>-->
</div>
{% endif %}
{% endfor %}
<!-- <a href="#" class="list-group-item"><span class="glyphicon glyphicon glyphicon-cog">&nbsp;审批人权限</span></a>
<a href="#" class="list-group-item"><span class="glyphicon glyphicon glyphicon glyphicon-file">&nbsp;功能模块6</span></a>
<a href="#" class="list-group-item"><span class="glyphicon glyphicon glyphicon glyphicon-list-alt">&nbsp;功能模块7</span></a>
<a href="#" class="list-group-item"><span class="glyphicon glyphicon glyphicon glyphicon-align-right">&nbsp;功能模块8</span></a>-->
</div>

</div>
</div>

<div class="col-md-10 column user-center-div-col-md-10">
{% block content %}
{% endblock content %}
</div>
</div>
<div class="col-md-10 column user-center-div-col-md-10">
{% block content %}
{% endblock content %}
</div>
</div>

<!--底部部分 -->
<div class="row clearfix user-bottom-div">
<p><strong>自动化运维平台.</strong>&nbsp; Developed by OP.</p>
</div>
<!--底部部分 -->
<div class="row clearfix user-bottom-div">
<p><strong>自动化运维平台.</strong>&nbsp; Developed by OP.</p>
</div>
</div>
<!-- jQuery (Bootstrap 的 JavaScript 插件需要引入 jQuery,务必先引入jquery js再引入bootstrap js) -->
<script src="{% static 'jquery/jquery.min.js' %}"></script>
<!-- 包括所有已编译的插件 -->
<script src="{% static 'bootstrap-3.3.7-dist/js/bootstrap.min.js' %}"></script>
<script src="{% static 'dist/js/bootstrap-select.js' %}"></script>
<script src="{% static 'bootstrap-table/js/bootstrap-table.min.js' %}"></script>
<script src="{% static 'bootstrap-table/js/bootstrap-table-zh-CN.min.js' %}"></script>
<script src="{% static 'user/js/formatter.js' %}"></script>
<!-- jQuery (Bootstrap 的 JavaScript 插件需要引入 jQuery,务必先引入jquery js再引入bootstrap js) -->
<script src="{% static 'jquery/jquery.min.js' %}"></script>
<!-- 包括所有已编译的插件 -->
<script src="{% static 'bootstrap-3.3.7-dist/js/bootstrap.min.js' %}"></script>
<script src="{% static 'dist/js/bootstrap-select.js' %}"></script>
<script src="{% static 'bootstrap-table/js/bootstrap-table.min.js' %}"></script>
<script src="{% static 'bootstrap-table/js/bootstrap-table-zh-CN.min.js' %}"></script>
<script src="{% static 'user/js/formatter.js' %}"></script>
</body>
{% block js %}
{% endblock %}
Expand Down
32 changes: 16 additions & 16 deletions sql/static/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,7 @@ <h4 style="display: inline;">单子名称:<span id="editWorkflowNname">{{ work
{% endif %}

{% elif workflowDetail.status == '审核通过' %}
{% if loginUser == workflowDetail.engineer %}
<form id="form-cancel" action="/cancel/" method="post" style="display:inline-block;">
{% csrf_token %}
<input type="hidden" name="workflowid" value="{{ workflowDetail.id }}">
<input type="hidden" id="audit_remark" name="audit_remark" value="">
<input type="submit" onclick="loading(this)" class="btn btn-default" value="终止流程"/>
</form>

{% elif loginUserOb.role == 'DBA' %}
{% if loginUserOb.role == 'DBA' %}
<textarea id="remark" name="remark" class="form-control" data-name="审核备注"
placeholder="请填写驳回原因" rows=3></textarea>
<br>
Expand All @@ -166,18 +158,18 @@ <h4 style="display: inline;">单子名称:<span id="editWorkflowNname">{{ work
<input type="hidden" id="audit_remark" name="audit_remark" value="">
<input type="button" id="btnCancel" class="btn btn-default" value="终止流程"/>
</form>
{% endif %}

{% elif workflowDetail.status == '定时执行' %}
{% if loginUser == workflowDetail.engineer %}
{% elif loginUser == workflowDetail.engineer %}
<form id="form-cancel" action="/cancel/" method="post" style="display:inline-block;">
{% csrf_token %}
<input type="hidden" name="workflowid" value="{{ workflowDetail.id }}">
<input type="hidden" id="audit_remark" name="audit_remark" value="">
<input type="submit" onclick="loading(this)" class="btn btn-default" value="终止流程"/>
</form>
{% endif %}

{% elif loginUserOb.role == 'DBA' %}
{% elif workflowDetail.status == '定时执行' %}
{% if loginUserOb.role == 'DBA' %}
<textarea id="remark" name="remark" class="form-control" data-name="审核备注"
placeholder="请填写驳回原因" rows=3></textarea>
<br>
Expand All @@ -188,6 +180,14 @@ <h4 style="display: inline;">单子名称:<span id="editWorkflowNname">{{ work
<input type="hidden" id="audit_remark" name="audit_remark" value="">
<input type="button" id="btnCancel" class="btn btn-default" value="终止流程"/>
</form>

{% elif loginUser == workflowDetail.engineer %}
<form id="form-cancel" action="/cancel/" method="post" style="display:inline-block;">
{% csrf_token %}
<input type="hidden" name="workflowid" value="{{ workflowDetail.id }}">
<input type="hidden" id="audit_remark" name="audit_remark" value="">
<input type="submit" onclick="loading(this)" class="btn btn-default" value="终止流程"/>
</form>
{% endif %}

{% elif workflowDetail.status == '已正常结束' and workflowDetail.is_backup == '是' %}
Expand Down Expand Up @@ -371,12 +371,12 @@ <h4 class="modal-title text-danger">定时执行SQL</h4>
$('#tb-detail').bootstrapTable('destroy').bootstrapTable({
striped: true, //是否显示行间隔色
cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
pagination: false, //是否显示分页(*)
pagination: true, //是否显示分页(*)
sortable: true, //是否启用排序
sidePagination: "client", //分页方式:client客户端分页,server服务端分页(*)
pageNumber: 1, //初始化加载第一页,默认第一页,并记录
pageSize: 14, //每页的记录行数(*)
pageList: [10, 30, 50, 100], //可供选择的每页的行数(*)
pageSize: 500, //每页的记录行数(*)
pageList: [500, 1000, 10000], //可供选择的每页的行数(*)
search: false, //是否显示表格搜索
strictSearch: false, //是否全匹配搜索
showColumns: false, //是否显示所有的列(选择显示的列)
Expand Down
8 changes: 4 additions & 4 deletions sql/static/slowquery.html
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@
}
},
formatter: function (value, row, index) {
if (value.length > 500) {
var sql = value.substr(0, 500) + '...';
if (value.length > 80) {
var sql = value.substr(0, 808) + '...';
return sql;
}
else {
Expand Down Expand Up @@ -435,8 +435,8 @@
title: 'SQL语句',
field: 'SQLText',
formatter: function (value, row, index) {
if (value.length > 100) {
var sql = value.substr(0, 100) + '...';
if (value.length > 80) {
var sql = value.substr(0, 80) + '...';
return sql;
}
else {
Expand Down
Loading

0 comments on commit 2380613

Please sign in to comment.