31 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
	
from __future__ import absolute_import, unicode_literals
 | 
						|
from apps.utils.task import CustomTask
 | 
						|
from apps.am.models import Area
 | 
						|
from celery import shared_task
 | 
						|
from django.core.cache import cache
 | 
						|
import shapely.geometry
 | 
						|
 | 
						|
 | 
						|
@shared_task(base=CustomTask)
 | 
						|
def cache_areas_info():
 | 
						|
    """
 | 
						|
    缓存区域信息
 | 
						|
    """
 | 
						|
    area_fix_list = []
 | 
						|
    for i in Area.objects.filter(type=Area.AREA_TYPE_FIX).exclude(third_info__xx_rail=None):
 | 
						|
        polygon = []
 | 
						|
        for item in i.third_info['xx_rail']['detail']['polygon']['points']:
 | 
						|
            polygon.append([item.x, item.y])
 | 
						|
        poly_context = {'type': 'MULTIPOLYGON',
 | 
						|
                        'coordinates': [[area_fix_list]]}
 | 
						|
        area_dict = {
 | 
						|
            'id': i.id,
 | 
						|
            'floor_no': i.third_info['xx_rail']['detail']['floorNo'],
 | 
						|
            'poly_shape': shapely.geometry.asShape(poly_context),
 | 
						|
            'stay_minute_min': i.stay_minute_min,
 | 
						|
            'stay_minute_max': i.stay_minute_max
 | 
						|
        }
 | 
						|
        area_fix_list.append(area_dict)
 | 
						|
    cache.set('area_fix_list', area_fix_list, timeout=None)
 | 
						|
    return area_fix_list
 |