Skip to content

Commit

Permalink
Merge pull request #1192 from hanshuaikang/feature/develop_by_han
Browse files Browse the repository at this point in the history
minor: 新增获取快速审批summary的接口
  • Loading branch information
hanshuaikang authored Sep 4, 2023
2 parents 5fc8971 + 3335d87 commit 3f9d35f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 52 deletions.
4 changes: 1 addition & 3 deletions itsm/component/bkchat/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,5 @@ def notify_fast_approval(
return

# 异步执行发送快速审批通知操作
notify_fast_approval_task.apply_async(
args=[self, state_id, receivers, message, action], kwargs=kwargs
)
notify_fast_approval_task.apply_async(args=[self, state_id, receivers])
return
94 changes: 48 additions & 46 deletions itsm/component/bkchat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,52 @@
APPROVE_MESSAGE = {"true": "同意", "false": "拒绝"}


def notify_fast_approval_message(
ticket, state_id, receivers, message, action, **kwargs
):
def build_bkchat_summary(ticket):
title = "## 『ITSM』{}: {}".format(
RUNNING_ENV.get(settings.RUN_MODE, ""), ticket.title
)
content = title + "\n"
content += "**单号**: {}\n".format(ticket.sn)
content += "**服务目录**: {}\n".format(ticket.catalog_service_name)

current_steps = ",".join([step.get("name") for step in ticket.current_steps])

content += "**当前环节**: {}\n".format(current_steps)
content += "**提单人**: {}\n".format(ticket.creator)

processor_list = [
processor for processor in ticket.current_processors.split(",") if processor
]
if len(processor_list) > 3:
processor_content = ",".join(processor_list[0:3]) + "..."
else:
processor_content = ",".join(processor_list)

content += "**审批人**: {}".format(processor_content)

# 添加「提单信息」
content = "{}\n **--- 单据基本信息 ---**".format(content)
state_fields = ticket.get_state_fields(ticket.first_state_id, need_serialize=False)
# 隐藏字段过滤
for f in state_fields.exclude(type__in=["TABLE", "CUSTOMTABLE", "FILE"]):
if f.show_type == SHOW_BY_CONDITION:
key_value = {
"params_%s"
% item["key"]: format_exp_value(item["type"], item["_value"])
for item in f.ticket.fields.values("key", "_value", "type")
}
if show_conditions_validate(f.show_conditions, key_value):
continue

detail = "**{}**:{}".format(
f.name, ticket.display_content(f.type, f.display_value)
)
content = "{}\n {}".format(content, detail)

return content


def notify_fast_approval_message(ticket, state_id, receivers):
"""
构建快速审批通知参数
"""
Expand Down Expand Up @@ -63,51 +106,10 @@ def notify_fast_approval_message(
)
)
return
title = "## 『ITSM』{}: {}".format(
RUNNING_ENV.get(settings.RUN_MODE, ""), ticket.title
)
content = title + "\n"
content += "**单号**: {}\n".format(ticket.sn)
content += "**服务目录**: {}\n".format(ticket.catalog_service_name)

current_steps = ",".join([step.get("name") for step in ticket.current_steps])

content += "**当前环节**: {}\n".format(current_steps)
content += "**提单人**: {}\n".format(ticket.creator)

processor_list = [
processor for processor in ticket.current_processors.split(",") if processor
]
if len(processor_list) > 3:
processor_content = ",".join(processor_list[0:3]) + "..."
else:
processor_content = ",".join(processor_list)

content += "**审批人**: {}".format(processor_content)

# 添加「提单信息」
content = "{}\n **--- 单据基本信息 ---**".format(content)
state_fields = ticket.get_state_fields(
ticket.first_state_id, need_serialize=False
)
# 隐藏字段过滤
for f in state_fields.exclude(type__in=["TABLE", "CUSTOMTABLE", "FILE"]):
if f.show_type == SHOW_BY_CONDITION:
key_value = {
"params_%s"
% item["key"]: format_exp_value(item["type"], item["_value"])
for item in f.ticket.fields.values("key", "_value", "type")
}
if show_conditions_validate(f.show_conditions, key_value):
continue

detail = "**{}**:{}".format(
f.name, ticket.display_content(f.type, f.display_value)
)
content = "{}\n {}".format(content, detail)

content = build_bkchat_summary(ticket)
# 发送微信通知
send_fast_approval_message(title, content, receivers, ticket, state_id)
send_fast_approval_message(ticket.title, content, receivers, ticket, state_id)


def send_fast_approval_message(title, content, receivers, ticket, state_id):
Expand Down
15 changes: 14 additions & 1 deletion itsm/openapi/ticket/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from common.log import logger
from common.cipher import AESVerification
from common.redis import Cache
from itsm.component.bkchat.utils import proceed_fast_approval
from itsm.component.bkchat.utils import proceed_fast_approval, build_bkchat_summary
from itsm.component.constants import (
API,
QUEUEING,
Expand Down Expand Up @@ -638,6 +638,19 @@ def proceed_fast_approval(self, request):
"""
return proceed_fast_approval(request)

@action(detail=False, methods=["get"])
@catch_openapi_exception
@custom_apigw_required
def get_fast_approval_summary(self, request):
sn = request.query_params.get("sn")
try:
ticket = Ticket.objects.get(sn=sn)
except Ticket.DoesNotExist:
raise ParamError("sn[{}]对应的单据不存在!".format(sn))

summary = build_bkchat_summary(ticket)
return Response({"summary": summary})

@action(detail=False, methods=["get"])
@catch_openapi_exception
@custom_apigw_required
Expand Down
4 changes: 2 additions & 2 deletions itsm/ticket/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ def notify_task(ticket, receivers, message, action, **kwargs):


@task
def notify_fast_approval_task(ticket, state_id, receivers, message, action, **kwargs):
def notify_fast_approval_task(ticket, state_id, receivers):
"""发送快速审批通知"""

notify_fast_approval_message(ticket, state_id, receivers, message, action, **kwargs)
notify_fast_approval_message(ticket, state_id, receivers)


@periodic_task(run_every=(crontab(minute="*/1")), ignore_result=True)
Expand Down

0 comments on commit 3f9d35f

Please sign in to comment.