From b01db6240660980e1ec3c54b2581b1f6a5dff853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E5=89=8D=E6=98=8E?= <909355014@qq.com> Date: Mon, 27 Jun 2022 17:41:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0rcertificate=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/am/services.py | 0 apps/am/tasks.py | 0 apps/ecm/service.py | 32 +++++++++++++++++++++++++++++++- apps/rpm/urls.py | 3 ++- apps/utils/tools.py | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 apps/am/services.py create mode 100644 apps/am/tasks.py diff --git a/apps/am/services.py b/apps/am/services.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/am/tasks.py b/apps/am/tasks.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/ecm/service.py b/apps/ecm/service.py index 61714382..74413a4f 100644 --- a/apps/ecm/service.py +++ b/apps/ecm/service.py @@ -7,6 +7,14 @@ from apps.third.clients import xxClient from apps.third.models import TDevice from apps.third.tapis import xxapis from apps.utils.queryset import get_child_queryset2 +from django.core.cache import cache +import time + +ep_loc_dict = { + "area": None, # 当前所在区域 + "time1": None, # 首次在该区域时间戳 + "time2": None, # 当前在该区域时间戳 +} class EcmService: @@ -39,6 +47,9 @@ class EcmService: elif data.type == 'onKeyAlarm': # 一键呼救 cls.one_key_alarm(data=data) + elif data.type == 'location': + # 定位信息 + cls.loc_change(data=data) elif data.type == 'onOffLine': if data.data.online: # 标签定位在线 @@ -117,8 +128,27 @@ class EcmService: @classmethod def low_power(cls, data): - pass + # 有绑定对象再提示低电量 + blts = TDevice.objects.filter(code=data['userId']).first() + if blts.employee: + # 触发低电量提醒事件 + pass @classmethod def one_key_alarm(cls, data): pass + + @classmethod + def loc_change(cls, data): + blts = TDevice.objects.filter(code=data['userId']).first() + if blts.employee: + time2 = int(time.time()) + key_str = f'ep_{blts.employee.id}' + ep_default_dict = { + "area": None, # 当前所在区域 + "time1": None, # 首次在该区域时间戳 + "time2": time2, # 当前在该区域时间戳 + } + ep_loc_dict = cache.get_or_set( + key_str, ep_default_dict, 60*60*24*7 + ) \ No newline at end of file diff --git a/apps/rpm/urls.py b/apps/rpm/urls.py index 68562586..601f6a28 100644 --- a/apps/rpm/urls.py +++ b/apps/rpm/urls.py @@ -1,4 +1,4 @@ -from apps.rpm.views import RpartyViewSet, RemployeeViewSet, RfileViewSet, RpjViewSet, RpjfileViewSet, RpjmemberViewSet +from apps.rpm.views import RcertificateViewSet, RpartyViewSet, RemployeeViewSet, RfileViewSet, RpjViewSet, RpjfileViewSet, RpjmemberViewSet from django.urls import path, include from rest_framework.routers import DefaultRouter @@ -8,6 +8,7 @@ HTML_BASE_URL = 'rpm/' router = DefaultRouter() router.register('rparty', RpartyViewSet, basename='rparty') router.register('remployee', RemployeeViewSet, basename='remployee') +router.register('rcertificate', RcertificateViewSet, basename='rcertificate') router.register('rfile', RfileViewSet, basename='rfile') router.register('rpj', RpjViewSet, basename='rpj') router.register('rpj_member', RpjmemberViewSet, basename='rpj_member') diff --git a/apps/utils/tools.py b/apps/utils/tools.py index ced0caf5..70aa6b39 100755 --- a/apps/utils/tools.py +++ b/apps/utils/tools.py @@ -1,6 +1,7 @@ import textwrap import random import string +import time def print_roundtrip(response, *args, **kwargs): @@ -32,3 +33,39 @@ def ranstr(num): def rannum(num): salt = ''.join(random.sample(string.digits, num)) return salt + + +def p_in_poly(p, poly): + px = p['x'] + py = p['y'] + flag = False + + i = 0 + l = len(poly) + j = l - 1 + # for(i = 0, l = poly.length, j = l - 1; i < l; j = i, i++): + while i < l: + sx = poly[i]['x'] + sy = poly[i]['y'] + tx = poly[j]['x'] + ty = poly[j]['y'] + + # 点与多边形顶点重合 + if (sx == px and sy == py) or (tx == px and ty == py): + return (px, py) + + # 判断线段两端点是否在射线两侧 + if (sy < py and ty >= py) or (sy >= py and ty < py): + # 线段上与射线 Y 坐标相同的点的 X 坐标 + x = sx + (py - sy) * (tx - sx) / (ty - sy) + # 点在多边形的边上 + if x == px: + return (px, py) + # 射线穿过多边形的边界 + if x > px: + flag = not flag + j = i + i += 1 + + # 射线穿过多边形边界的次数为奇数时点在多边形内 + return (px, py) if flag else 'out'