From 5d15469b054fec199546e63ab07f7a30a6c31f96 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, 26 Sep 2022 13:17:00 +0800 Subject: [PATCH] =?UTF-8?q?tlog=E5=A2=9E=E5=8A=A0headers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0003_alter_area_access_list.py | 18 ++++++++++++++++++ apps/monitor/tasks.py | 4 ++++ apps/third/dahua.py | 18 ++++++------------ apps/third/migrations/0006_tlog_headers.py | 18 ++++++++++++++++++ apps/third/models.py | 1 + apps/third/tapis.py | 4 ++++ apps/vm/services.py | 3 ++- apps/wf/serializers.py | 3 ++- 8 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 apps/am/migrations/0003_alter_area_access_list.py create mode 100644 apps/monitor/tasks.py create mode 100644 apps/third/migrations/0006_tlog_headers.py diff --git a/apps/am/migrations/0003_alter_area_access_list.py b/apps/am/migrations/0003_alter_area_access_list.py new file mode 100644 index 00000000..3165f581 --- /dev/null +++ b/apps/am/migrations/0003_alter_area_access_list.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.12 on 2022-09-26 05:16 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('am', '0002_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='area', + name='access_list', + field=models.JSONField(blank=True, default=list, help_text='employee/remployee/visitor/driver', verbose_name='准入人员类型'), + ), + ] diff --git a/apps/monitor/tasks.py b/apps/monitor/tasks.py new file mode 100644 index 00000000..77a41992 --- /dev/null +++ b/apps/monitor/tasks.py @@ -0,0 +1,4 @@ +# Create your tasks here +from __future__ import absolute_import, unicode_literals +from apps.utils.tasks import CustomTask +from celery import shared_task diff --git a/apps/third/dahua.py b/apps/third/dahua.py index b1103f1d..12fd58cd 100644 --- a/apps/third/dahua.py +++ b/apps/third/dahua.py @@ -45,17 +45,11 @@ class DhClient: 'client_id': self.client_id, 'client_secret': self.client_secret } - try: - r = requests.post(params=params, - url=settings.DAHUA_BASE_URL + '/evo-apigw/evo-oauth/oauth/token', verify=False) - ret = r.json() - if ret['success']: - self.token = ret['data']['access_token'] - self.headers['Authorization'] = 'bearer ' + ret['data']['access_token'] - self.headers['User-Id'] = '1' - time.sleep(1200) - except Exception: - myLogger.error('大华服务连接失败', exc_info=True) + _, res = self.request(**dhapis['token_login'], params=params, raise_exception=False) + self.token = res['access_token'] + self.headers['Authorization'] = 'bearer ' + res['access_token'] + self.headers['User-Id'] = '1' + time.sleep(1200) def setup(self): t = Thread(target=self._get_token_loop, args=(), daemon=True) @@ -73,7 +67,7 @@ class DhClient: if not settings.DAHUA_ENABLED: raise ParseError('大华对接未启用') self.log = {"requested_at": now(), "id": uuid.uuid4(), "path": url, "method": method, - "params": params, "body": json, "target": "dahua", "result": 10} + "params": params, "body": json, "target": "dahua", "result": 10, "headers": self.headers} files = None if file_path_rela: # 相对路径 files = {'file': open(settings.BASE_DIR + file_path_rela, 'rb')} diff --git a/apps/third/migrations/0006_tlog_headers.py b/apps/third/migrations/0006_tlog_headers.py new file mode 100644 index 00000000..4a77c42e --- /dev/null +++ b/apps/third/migrations/0006_tlog_headers.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.12 on 2022-09-26 05:16 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('third', '0005_alter_tdevice_access_list'), + ] + + operations = [ + migrations.AddField( + model_name='tlog', + name='headers', + field=models.JSONField(blank=True, null=True), + ), + ] diff --git a/apps/third/models.py b/apps/third/models.py index ff1582cc..5f558757 100755 --- a/apps/third/models.py +++ b/apps/third/models.py @@ -75,6 +75,7 @@ class Tlog(BaseModel): path = models.CharField(max_length=400, help_text="请求地址") requested_at = models.DateTimeField() response_ms = models.PositiveIntegerField(default=0) + headers = models.JSONField(null=True, blank=True) response = models.JSONField(null=True, blank=True) method = models.CharField(max_length=10) url = models.TextField(null=True, blank=True) diff --git a/apps/third/tapis.py b/apps/third/tapis.py index b0491e19..a0854c00 100755 --- a/apps/third/tapis.py +++ b/apps/third/tapis.py @@ -1,5 +1,9 @@ # 大华API接口 dhapis = { + "token_login": { + "url": "/evo-apigw/evo-oauth/oauth/token", + "method": "post" + }, "dept_tree": { "url": "/evo-apigw/evo-brm/1.2.0/department/tree", "method": "post" diff --git a/apps/vm/services.py b/apps/vm/services.py index fba8589e..bbf61dae 100644 --- a/apps/vm/services.py +++ b/apps/vm/services.py @@ -39,7 +39,8 @@ def visit_audit_end(ticket): # 更新企业访客人员库 for i in Vpeople.objects.filter(visit=visit): visitor = i.visitor - if visitor.id_number and visitor.photo: + # if visitor.id_number and visitor.photo: + if visitor.id_number: ep = Employee.objects.get_queryset(all=True).filter(id_number=visitor.id_number).first() elif visitor.phone: ep = Employee.objects.get_queryset(all=True).filter(phone=visitor.phone).first() diff --git a/apps/wf/serializers.py b/apps/wf/serializers.py index e1744ba1..238680de 100755 --- a/apps/wf/serializers.py +++ b/apps/wf/serializers.py @@ -113,11 +113,12 @@ class TicketListSerializer(CustomModelSerializer): workflow_ = WorkflowSimpleSerializer(source='workflow', read_only=True) state_ = StateSimpleSerializer(source='state', read_only=True) participant_ = serializers.SerializerMethodField() + class Meta: model = Ticket fields = ['id', 'title', 'sn', 'workflow', 'workflow_', 'state', 'state_', 'act_state', 'create_time', 'update_time', 'participant_type', 'create_by', 'ticket_data', - 'participant_'] + 'participant_', 'script_run_last_result'] def get_participant_(self, obj): if obj.participant_type == 1: