52 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
| # Create your tasks here
 | |
| from __future__ import absolute_import, unicode_literals
 | |
| from apps.opm.models import Operation, Opl
 | |
| from apps.utils.tasks import CustomTask
 | |
| from celery import shared_task
 | |
| 
 | |
| from apps.wf.models import Ticket
 | |
| 
 | |
| 
 | |
| @shared_task(base=CustomTask)
 | |
| def opl_end(ticket_id):
 | |
|     """
 | |
|     作业许可证关闭时执行
 | |
|     """
 | |
|     ticket = Ticket.objects.get(id=ticket_id)
 | |
|     opl = ticket.opl
 | |
|     if opl.mtask_id:
 | |
|         from celery.app.control import Control
 | |
|         from server.celery import app
 | |
|         celery_control = Control(app=app)
 | |
|         # 关闭作业视频监控任务
 | |
|         celery_control.revoke(opl.mtask_id, terminate=True)
 | |
|         opl.mtask_id = None
 | |
|         opl.save()
 | |
|     operation = 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()
 | |
|     # 授予区域或围栏权限
 |