tlog增加headers
This commit is contained in:
parent
862210f8d3
commit
5d15469b05
|
@ -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='准入人员类型'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -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
|
|
@ -45,17 +45,11 @@ class DhClient:
|
||||||
'client_id': self.client_id,
|
'client_id': self.client_id,
|
||||||
'client_secret': self.client_secret
|
'client_secret': self.client_secret
|
||||||
}
|
}
|
||||||
try:
|
_, res = self.request(**dhapis['token_login'], params=params, raise_exception=False)
|
||||||
r = requests.post(params=params,
|
self.token = res['access_token']
|
||||||
url=settings.DAHUA_BASE_URL + '/evo-apigw/evo-oauth/oauth/token', verify=False)
|
self.headers['Authorization'] = 'bearer ' + res['access_token']
|
||||||
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'
|
self.headers['User-Id'] = '1'
|
||||||
time.sleep(1200)
|
time.sleep(1200)
|
||||||
except Exception:
|
|
||||||
myLogger.error('大华服务连接失败', exc_info=True)
|
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
t = Thread(target=self._get_token_loop, args=(), daemon=True)
|
t = Thread(target=self._get_token_loop, args=(), daemon=True)
|
||||||
|
@ -73,7 +67,7 @@ class DhClient:
|
||||||
if not settings.DAHUA_ENABLED:
|
if not settings.DAHUA_ENABLED:
|
||||||
raise ParseError('大华对接未启用')
|
raise ParseError('大华对接未启用')
|
||||||
self.log = {"requested_at": now(), "id": uuid.uuid4(), "path": url, "method": method,
|
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
|
files = None
|
||||||
if file_path_rela: # 相对路径
|
if file_path_rela: # 相对路径
|
||||||
files = {'file': open(settings.BASE_DIR + file_path_rela, 'rb')}
|
files = {'file': open(settings.BASE_DIR + file_path_rela, 'rb')}
|
||||||
|
|
|
@ -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),
|
||||||
|
),
|
||||||
|
]
|
|
@ -75,6 +75,7 @@ class Tlog(BaseModel):
|
||||||
path = models.CharField(max_length=400, help_text="请求地址")
|
path = models.CharField(max_length=400, help_text="请求地址")
|
||||||
requested_at = models.DateTimeField()
|
requested_at = models.DateTimeField()
|
||||||
response_ms = models.PositiveIntegerField(default=0)
|
response_ms = models.PositiveIntegerField(default=0)
|
||||||
|
headers = models.JSONField(null=True, blank=True)
|
||||||
response = models.JSONField(null=True, blank=True)
|
response = models.JSONField(null=True, blank=True)
|
||||||
method = models.CharField(max_length=10)
|
method = models.CharField(max_length=10)
|
||||||
url = models.TextField(null=True, blank=True)
|
url = models.TextField(null=True, blank=True)
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
# 大华API接口
|
# 大华API接口
|
||||||
dhapis = {
|
dhapis = {
|
||||||
|
"token_login": {
|
||||||
|
"url": "/evo-apigw/evo-oauth/oauth/token",
|
||||||
|
"method": "post"
|
||||||
|
},
|
||||||
"dept_tree": {
|
"dept_tree": {
|
||||||
"url": "/evo-apigw/evo-brm/1.2.0/department/tree",
|
"url": "/evo-apigw/evo-brm/1.2.0/department/tree",
|
||||||
"method": "post"
|
"method": "post"
|
||||||
|
|
|
@ -39,7 +39,8 @@ def visit_audit_end(ticket):
|
||||||
# 更新企业访客人员库
|
# 更新企业访客人员库
|
||||||
for i in Vpeople.objects.filter(visit=visit):
|
for i in Vpeople.objects.filter(visit=visit):
|
||||||
visitor = i.visitor
|
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()
|
ep = Employee.objects.get_queryset(all=True).filter(id_number=visitor.id_number).first()
|
||||||
elif visitor.phone:
|
elif visitor.phone:
|
||||||
ep = Employee.objects.get_queryset(all=True).filter(phone=visitor.phone).first()
|
ep = Employee.objects.get_queryset(all=True).filter(phone=visitor.phone).first()
|
||||||
|
|
|
@ -113,11 +113,12 @@ class TicketListSerializer(CustomModelSerializer):
|
||||||
workflow_ = WorkflowSimpleSerializer(source='workflow', read_only=True)
|
workflow_ = WorkflowSimpleSerializer(source='workflow', read_only=True)
|
||||||
state_ = StateSimpleSerializer(source='state', read_only=True)
|
state_ = StateSimpleSerializer(source='state', read_only=True)
|
||||||
participant_ = serializers.SerializerMethodField()
|
participant_ = serializers.SerializerMethodField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Ticket
|
model = Ticket
|
||||||
fields = ['id', 'title', 'sn', 'workflow', 'workflow_', 'state', 'state_',
|
fields = ['id', 'title', 'sn', 'workflow', 'workflow_', 'state', 'state_',
|
||||||
'act_state', 'create_time', 'update_time', 'participant_type', 'create_by', 'ticket_data',
|
'act_state', 'create_time', 'update_time', 'participant_type', 'create_by', 'ticket_data',
|
||||||
'participant_']
|
'participant_', 'script_run_last_result']
|
||||||
|
|
||||||
def get_participant_(self, obj):
|
def get_participant_(self, obj):
|
||||||
if obj.participant_type == 1:
|
if obj.participant_type == 1:
|
||||||
|
|
Loading…
Reference in New Issue