45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
# Create your tasks here
|
|
from __future__ import absolute_import, unicode_literals
|
|
from apps.opm.models import Operation, Opl
|
|
from apps.opm.services import give_perm_by_opl
|
|
from apps.utils.task import CustomTask
|
|
from celery import shared_task
|
|
|
|
from apps.wf.models import State, Ticket
|
|
|
|
|
|
@shared_task(base=CustomTask)
|
|
def opl_end(ticket_id):
|
|
"""
|
|
作业关闭时执行
|
|
"""
|
|
ticket = Ticket.objects.get(id=ticket_id)
|
|
operation = ticket.opl.operation
|
|
opls = Opl.objects.filter(operation=operation)
|
|
opls.filter(ticket=None).delete() # 删除无用许可证
|
|
states = opls.values_list('ticket__state__type', flat=True)
|
|
if 0 in states or 1 in states:
|
|
pass
|
|
else:
|
|
operation.state = Operation.OP_CLOSE
|
|
operation.save()
|
|
|
|
|
|
@shared_task(base=CustomTask)
|
|
def opl_audit_start(ticket_id):
|
|
operation = Opl.objects.get(ticket__id=ticket_id).operation
|
|
if operation.state == Operation.OP_CREATE:
|
|
operation.state = Operation.OP_AUDIT
|
|
operation.save()
|
|
|
|
|
|
@shared_task(base=CustomTask)
|
|
def opl_audit_end(ticket_id):
|
|
opl = Opl.objects.get(ticket__id=ticket_id)
|
|
operation = opl.operation
|
|
if operation.state == Operation.OP_AUDIT:
|
|
operation.state = Operation.OP_WORK
|
|
operation.save()
|
|
# 授予区域或围栏权限
|
|
give_perm_by_opl(opl)
|