30 lines
		
	
	
		
			1001 B
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			1001 B
		
	
	
	
		
			Python
		
	
	
	
| from __future__ import absolute_import, unicode_literals
 | |
| from apps.utils.tasks import CustomTask
 | |
| from apps.am.models import Area
 | |
| from celery import shared_task
 | |
| from django.core.cache import cache
 | |
| from shapely.geometry import Polygon
 | |
| 
 | |
| 
 | |
| @shared_task(base=CustomTask)
 | |
| def cache_areas_info():
 | |
|     """
 | |
|     缓存区域信息
 | |
|     """
 | |
|     area_list = []
 | |
|     for i in Area.objects.filter(is_hidden=False).exclude(third_info__xx_rail=None).order_by('number'):
 | |
|         points = []
 | |
|         for item in i.third_info['xx_rail']['detail']['polygon']['points']:
 | |
|             points.append((item['x'], item['y']))
 | |
|         area_dict = {
 | |
|             'id': i.id,
 | |
|             'type': i.type,
 | |
|             'floor_no': i.third_info['xx_rail']['detail']['floorNo'],
 | |
|             'polygon': Polygon(points),
 | |
|             'stay_minute_min': i.stay_minute_min,
 | |
|             'stay_minute_max': i.stay_minute_max
 | |
|         }
 | |
|         area_list.append(area_dict)
 | |
|     cache.set('area_list', area_list, timeout=None)
 | |
|     # return area_list
 |