Skip to content

Commit

Permalink
工单通知分阶段控制 (#1406)
Browse files Browse the repository at this point in the history
* 工单通知分阶段控制

工单通知分阶段控制

* Revert "移除配置信息的缓存依赖"

This reverts commit 7fd62b2.

# Conflicts:
#	common/config.py
#	common/templates/config.html

* Revert "Revert "移除配置信息的缓存依赖""

This reverts commit bb4d1f3.

* 参数改为在前台处理

参数改为在前台处理
  • Loading branch information
nick2wang authored Mar 6, 2022
1 parent a7cde53 commit bbcf17a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 15 deletions.
38 changes: 38 additions & 0 deletions common/templates/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,18 @@ <h6 style="color:red">注3:企业微信群机器人需要配置资源组webhoo
</select>
</div>
</div>
<div class="form-group">
<label for="notify_phase_control"
class="col-sm-4 control-label">NOTIFY_PHASE_CONTROL</label>
<div class="col-sm-5">
<select id="notify_phase_control" key="notify_phase_control"
class="selectpicker show-tick form-control bs-select-hidden"
data-live-search="true"
data-none-selected-text="工单通知分阶段控制"
multiple required>
</select>
</div>
</div>
<div class="form-group">
<label for="mail"
class="col-sm-4 control-label">MAIL</label>
Expand Down Expand Up @@ -860,6 +872,32 @@ <h5 class="control-label text-bold">当前审批流程:<b id="workflow_auditor
<link href="{% static 'bootstrap-switch/css/bootstrap-switch.min.css' %}" rel="stylesheet" type="text/css"/>
<script src="{% static 'bootstrap-switch/js/bootstrap-switch.min.js' %}"></script>
<script>
// notify_phase_control参数处理
$(document).ready(function (){
let cfg_value = "{{ config.notify_phase_control }}";
let phases = ['Apply', 'Pass', 'Execute', 'Cancel'];
// notify_phase_control未设置时默认全部开启
if (cfg_value === "") {
for (let i in phases) {
let phase = "<option value=\"" + phases[i]+ "\" selected>" + phases[i] + "</option>"
$("#notify_phase_control").append(phase)
}
} else {
for (let i=0;i<phases.length;i++) {
let phase = "";
let cfg_arr = cfg_value.split(',');
if (cfg_arr.indexOf(phases[i]) >= 0) {
phase = "<option value=\"" + phases[i]+ "\" selected>" + phases[i] + "</option>"
} else {
phase = "<option value=\"" + phases[i]+ "\">" + phases[i] + "</option>"
}
$("#notify_phase_control").append(phase)
}
}
$("#notify_phase_control").selectpicker('render');
$("#notify_phase_control").selectpicker('refresh');
})

//配置项切换
$("#config").change(function () {
sessionStorage.setItem('config_type', $("#config").val());
Expand Down
40 changes: 27 additions & 13 deletions sql/sql_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,10 @@ def submit(request):
logger.error(traceback.format_exc())
return render(request, 'error.html', context)
else:
# 自动审核通过才进行消息通知
if workflow_status == 'workflow_manreviewing':
# 自动审核通过且开启了Apply阶段通知参数才发送消息通知
is_notified = 'Apply' in sys_config.get('notify_phase_control').split(',') \
if sys_config.get('notify_phase_control') else True
if workflow_status == 'workflow_manreviewing' and is_notified:
# 获取审核信息
audit_id = Audit.detail_by_workflow_id(workflow_id=workflow_id,
workflow_type=WorkflowDict.workflow_type['sqlreview']).audit_id
Expand Down Expand Up @@ -368,9 +370,13 @@ def passed(request):
context = {'errMsg': msg}
return render(request, 'error.html', context)
else:
# 消息通知
async_task(notify_for_audit, audit_id=audit_id, audit_remark=audit_remark, timeout=60,
task_name=f'sqlreview-pass-{workflow_id}')
# 开启了Pass阶段通知参数才发送消息通知
sys_config = SysConfig()
is_notified = 'Pass' in sys_config.get('notify_phase_control').split(',') \
if sys_config.get('notify_phase_control') else True
if is_notified:
async_task(notify_for_audit, audit_id=audit_id, audit_remark=audit_remark, timeout=60,
task_name=f'sqlreview-pass-{workflow_id}')

return HttpResponseRedirect(reverse('sql:detail', args=(workflow_id,)))

Expand Down Expand Up @@ -432,8 +438,12 @@ def execute(request):
operation_info='确认手工执行结束',
operator=request.user.username,
operator_display=request.user.display)
# 发送消息
notify_for_execute(SqlWorkflow.objects.get(id=workflow_id))
# 开启了Execute阶段通知参数才发送消息通知
sys_config = SysConfig()
is_notified = 'Execute' in sys_config.get('notify_phase_control').split(',') \
if sys_config.get('notify_phase_control') else True
if is_notified:
notify_for_execute(SqlWorkflow.objects.get(id=workflow_id))
return HttpResponseRedirect(reverse('sql:detail', args=(workflow_id,)))


Expand Down Expand Up @@ -565,13 +575,17 @@ def cancel(request):
context = {'errMsg': msg}
return render(request, 'error.html', context)
else:
# 发送取消、驳回通知
audit_detail = Audit.detail_by_workflow_id(workflow_id=workflow_id,
# 发送取消、驳回通知,开启了Cancel阶段通知参数才发送消息通知
sys_config = SysConfig()
is_notified = 'Cancel' in sys_config.get('notify_phase_control').split(',') \
if sys_config.get('notify_phase_control') else True
if is_notified:
audit_detail = Audit.detail_by_workflow_id(workflow_id=workflow_id,
workflow_type=WorkflowDict.workflow_type['sqlreview'])
if audit_detail.current_status in (
WorkflowDict.workflow_status['audit_abort'], WorkflowDict.workflow_status['audit_reject']):
async_task(notify_for_audit, audit_id=audit_detail.audit_id, audit_remark=audit_remark, timeout=60,
task_name=f'sqlreview-cancel-{workflow_id}')
if audit_detail.current_status in (
WorkflowDict.workflow_status['audit_abort'], WorkflowDict.workflow_status['audit_reject']):
async_task(notify_for_audit, audit_id=audit_detail.audit_id, audit_remark=audit_remark, timeout=60,
task_name=f'sqlreview-cancel-{workflow_id}')
return HttpResponseRedirect(reverse('sql:detail', args=(workflow_id,)))


Expand Down
9 changes: 7 additions & 2 deletions sql/utils/execute_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.db import close_old_connections, connection, transaction
from django_redis import get_redis_connection
from common.utils.const import WorkflowDict
from common.config import SysConfig
from sql.engines.models import ReviewResult, ReviewSet
from sql.models import SqlWorkflow
from sql.notify import notify_for_execute
Expand Down Expand Up @@ -90,5 +91,9 @@ def execute_callback(task):
for key in r.scan_iter(match='*insRes*', count=2000):
r.delete(key)

# 发送消息
notify_for_execute(workflow)
# 开启了Execute阶段通知参数才发送消息通知
sys_config = SysConfig()
is_notified = 'Execute' in sys_config.get('notify_phase_control').split(',') \
if sys_config.get('notify_phase_control') else True
if is_notified:
notify_for_execute(workflow)

0 comments on commit bbcf17a

Please sign in to comment.