单例模式修改
This commit is contained in:
parent
3c01174105
commit
3a38ee28b9
|
@ -5,7 +5,7 @@ from apps.utils.viewsets import CustomModelViewSet, CustomGenericViewSet
|
|||
from django.db import transaction
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework import serializers
|
||||
from apps.third.clients import xxClient
|
||||
from apps.third.xunxi import xxClient
|
||||
from apps.third.tapis import xxapis
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.mixins import ListModelMixin, CreateModelMixin, DestroyModelMixin
|
||||
|
|
|
@ -14,11 +14,11 @@ from rest_framework.exceptions import APIException
|
|||
from apps.ecm.service import check_not_in_place, create_remind, handle_xx_event, loc_change, notify_event, rail_in, snap_and_analyse
|
||||
from apps.ecm.tasks import opl_task, update_count_people
|
||||
from apps.opm.models import Opl
|
||||
from apps.third.clients import dhClient
|
||||
from apps.third.dahua import dhClient
|
||||
from apps.third.speaker import spClient
|
||||
from apps.third.models import TDevice
|
||||
from apps.utils.sms import send_sms
|
||||
from apps.utils.speech import generate_voice
|
||||
from apps.third.clients import spClient
|
||||
|
||||
from apps.utils.viewsets import CustomGenericViewSet
|
||||
from apps.utils.wx import wxClient
|
||||
|
|
|
@ -15,14 +15,15 @@ from apps.utils.queryset import get_child_queryset2, get_parent_queryset
|
|||
from django.core.cache import cache
|
||||
import time
|
||||
from shapely.geometry import Point
|
||||
from apps.third.clients import dhClient, spClient
|
||||
from apps.third.dahua import dhClient
|
||||
from apps.third.xunxi import xxClient
|
||||
from apps.third.speaker import spClient
|
||||
from django.utils import timezone
|
||||
from django.conf import settings
|
||||
import os
|
||||
from apps.utils.speech import generate_voice
|
||||
from threading import Thread
|
||||
from apps.utils.tools import timestamp_to_time
|
||||
from apps.third.clients import xxClient
|
||||
from apps.third.tapis import xxapis
|
||||
import logging
|
||||
myLogger = logging.getLogger('log')
|
||||
|
|
|
@ -9,8 +9,7 @@ from apps.ecm.models import EventCate, Eventdo, Event
|
|||
from apps.ecm.service import notify_event, snap_and_analyse
|
||||
from apps.hrm.models import Employee
|
||||
from apps.opm.models import Opl
|
||||
from apps.third.clients import xxClient
|
||||
from apps.third.clients import dhClient
|
||||
from apps.third.xunxi import xxClient
|
||||
from apps.third.models import TDevice
|
||||
from apps.third.tapis import xxapis
|
||||
from django.utils import timezone
|
||||
|
|
|
@ -11,7 +11,7 @@ from apps.utils.constants import EXCLUDE_FIELDS
|
|||
from apps.hrm.models import Certificate, ClockRecord, Employee, NotWorkRemark
|
||||
from apps.system.serializers import DeptSimpleSerializer, UserSimpleSerializer
|
||||
from django.db import transaction
|
||||
from apps.third.clients import dhClient
|
||||
from apps.third.dahua import dhClient
|
||||
from apps.third.tapis import dhapis
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
|
|
|
@ -5,7 +5,7 @@ from apps.hrm.models import ClockRecord, Employee
|
|||
from apps.third.errors import DH_REQUEST_ERROR
|
||||
from apps.third.models import TDevice
|
||||
from apps.third.tapis import dhapis
|
||||
from apps.third.clients import dhClient
|
||||
from apps.third.dahua import dhClient
|
||||
from apps.utils.tools import rannum, ranstr
|
||||
from datetime import datetime
|
||||
from django.utils import timezone
|
||||
|
|
|
@ -21,7 +21,7 @@ from apps.hrm.serializers import (CertificateCreateUpdateSerializer, Certificate
|
|||
NotWorkRemarkListSerializer)
|
||||
from apps.hrm.services import HrmService
|
||||
|
||||
from apps.third.clients import dhClient
|
||||
from apps.third.dahua import dhClient
|
||||
from apps.third.tapis import dhapis
|
||||
from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
|
|
|
@ -10,7 +10,7 @@ from apps.system.serializers import DictSerializer, DictSimpleSerializer, FileSe
|
|||
from rest_framework import serializers
|
||||
from rest_framework.exceptions import ParseError
|
||||
from django.db import transaction
|
||||
from apps.third.clients import dhClient
|
||||
from apps.third.dahua import dhClient
|
||||
from apps.third.tapis import dhapis
|
||||
from apps.utils.tools import check_id_number_e, check_phone_e
|
||||
from apps.wf.serializers import TicketSimpleSerializer
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
from apps.third.xunxi import XxClient
|
||||
from apps.third.dahua import DhClient
|
||||
from apps.third.speaker import SpClient
|
||||
dhClient = DhClient()
|
||||
xxClient = XxClient()
|
||||
spClient = SpClient()
|
|
@ -15,11 +15,13 @@ from apps.utils.my_rsa import encrypt_data
|
|||
from apps.utils.tools import convert_to_base64, print_roundtrip
|
||||
from django.utils.timezone import now
|
||||
from apps.third.tapis import dhapis
|
||||
from apps.utils.tools import singleton
|
||||
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
myLogger = logging.getLogger('log')
|
||||
|
||||
|
||||
@singleton
|
||||
class DhClient:
|
||||
"""
|
||||
大华
|
||||
|
@ -278,3 +280,6 @@ class DhClient:
|
|||
"chnId": i['id']
|
||||
}
|
||||
self.request(**dhapis['face_deploy'], json=json_data)
|
||||
|
||||
|
||||
dhClient = DhClient()
|
||||
|
|
|
@ -13,11 +13,13 @@ from apps.third.models import Tlog
|
|||
from apps.utils.tools import print_roundtrip, ranstr
|
||||
from apps.third.tapis import spapis
|
||||
from django.utils.timezone import now
|
||||
from apps.utils.tools import singleton
|
||||
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
myLogger = logging.getLogger('log')
|
||||
|
||||
|
||||
@singleton
|
||||
class SpClient:
|
||||
"""
|
||||
音响接口
|
||||
|
@ -128,3 +130,6 @@ class SpClient:
|
|||
"errors": errors
|
||||
})
|
||||
Tlog(**self.log).save()
|
||||
|
||||
|
||||
spClient = SpClient()
|
||||
|
|
|
@ -5,7 +5,9 @@ from apps.ecm.service import dispatch_dahua_event, handle_xx_event, loc_change,
|
|||
from apps.hrm.services import HrmService
|
||||
from apps.third.tapis import dhapis, xxapis, spapis
|
||||
from apps.third.errors import TAPI_CODE_WRONG
|
||||
from apps.third.clients import dhClient, spClient, xxClient
|
||||
from apps.third.dahua import dhClient
|
||||
from apps.third.xunxi import xxClient
|
||||
from apps.third.speaker import spClient
|
||||
from apps.utils.mixins import MyLoggingMixin
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
|
|
@ -3,7 +3,9 @@ from apps.third.models import BltBind, TDevice, Tlog
|
|||
from apps.third.serializers import BindAreaSerializer, BltBindCreateSerializer, BltQuerySerializer, BltSerializer, LabelLocationSerializer, TDeviceSerializer, TDeviceUpdateSerializer, TlogSerializer
|
||||
from apps.utils.viewsets import CustomGenericViewSet
|
||||
from rest_framework.mixins import ListModelMixin, CreateModelMixin
|
||||
from apps.third.clients import xxClient, dhClient, spClient
|
||||
from apps.third.dahua import dhClient
|
||||
from apps.third.xunxi import xxClient
|
||||
from apps.third.speaker import spClient
|
||||
from apps.third.tapis import xxapis, dhapis, spapis
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.serializers import Serializer
|
||||
|
|
|
@ -12,10 +12,12 @@ from apps.third.models import Tlog
|
|||
from apps.utils.tools import print_roundtrip
|
||||
from django.utils.timezone import now
|
||||
from apps.third.tapis import xxapis
|
||||
from apps.utils.tools import singleton
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
myLogger = logging.getLogger('log')
|
||||
|
||||
|
||||
@singleton
|
||||
class XxClient:
|
||||
"""
|
||||
寻息
|
||||
|
@ -100,3 +102,6 @@ class XxClient:
|
|||
"data": {"buildIds": [settings.XX_BUILDID], "serverUrl": settings.BASE_URL_IN + rurl},
|
||||
"licence": settings.XX_LICENCE}
|
||||
self.request(**xxapis['subscribe'], json=json_data)
|
||||
|
||||
|
||||
xxClient = XxClient()
|
||||
|
|
|
@ -10,6 +10,16 @@ from io import BytesIO
|
|||
from rest_framework.serializers import ValidationError
|
||||
|
||||
|
||||
def singleton(cls):
|
||||
_instance = {}
|
||||
|
||||
def inner():
|
||||
if cls not in _instance:
|
||||
_instance[cls] = cls()
|
||||
return _instance[cls]
|
||||
return inner
|
||||
|
||||
|
||||
def print_roundtrip(response, *args, **kwargs):
|
||||
def format_headers(d): return '\n'.join(f'{k}: {v}' for k, v in d.items())
|
||||
print(textwrap.dedent('''
|
||||
|
|
|
@ -8,7 +8,7 @@ from apps.vm.models import Visit, Visitor, Vpeople
|
|||
from rest_framework import serializers
|
||||
from rest_framework.exceptions import ParseError
|
||||
from django.db import transaction
|
||||
from apps.third.clients import dhClient
|
||||
from apps.third.dahua import dhClient
|
||||
from apps.third.tapis import dhapis
|
||||
from apps.system.serializers import UserSimpleSerializer
|
||||
from apps.wf.serializers import TicketSerializer
|
||||
|
|
Loading…
Reference in New Issue