From 66182e56f85d4a0087109dc19e74ce5e258cdc01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E5=89=8D=E6=98=8E?= <909355014@qq.com> Date: Fri, 2 Sep 2022 10:34:57 +0800 Subject: [PATCH] =?UTF-8?q?blt=20bind=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/third/serializers.py | 5 +++-- apps/third/views_d.py | 36 ++++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/apps/third/serializers.py b/apps/third/serializers.py index b7041878..cb61a2a3 100755 --- a/apps/third/serializers.py +++ b/apps/third/serializers.py @@ -92,11 +92,12 @@ class BltQuerySerializer(serializers.ModelSerializer): class BltBindCreateSerializer(serializers.ModelSerializer): - blt = serializers.PrimaryKeyRelatedField(queryset=TDevice.objects.filter(type=TDevice.DEVICE_BLT)) + # blt = serializers.PrimaryKeyRelatedField(queryset=TDevice.objects.filter(type=TDevice.DEVICE_BLT)) + code = serializers.CharField(label='标签mac地址') class Meta: model = BltBind - fields = ['type', 'blt', 'employee'] + fields = ['type', 'code', 'employee'] class BltCreatesSerializer(serializers.Serializer): diff --git a/apps/third/views_d.py b/apps/third/views_d.py index dc289b2a..2479fb4e 100644 --- a/apps/third/views_d.py +++ b/apps/third/views_d.py @@ -260,22 +260,26 @@ class TDeviceViewSet(ListModelMixin, UpdateModelMixin, DestroyModelMixin, Custom serializer = BltBindCreateSerializer(data=request.data) serializer.is_valid(raise_exception=True) vdata = serializer.validated_data - blt = vdata['blt'] - if vdata['type'] == BltBind.BLT_BIND and vdata['employee']: - if blt.employee: - raise ParseError('该定位卡已绑定人员,请先解绑') - else: - blt.employee = vdata['employee'] - blt.obj_cate = 'people' - blt.save() - vdata['obj_cate'] = 'people' - BltBind.objects.create(**vdata) - elif vdata['type'] == BltBind.BLT_UNBIND: - if blt.employee: - blt.employee = None - blt.save() - vdata['obj_cate'] = 'people' - BltBind.objects.create(**vdata) + code = vdata['code'] + blt = TDevice.objects.filter(code=code, type=TDevice.DEVICE_BLT).first() + if blt: + if vdata['type'] == BltBind.BLT_BIND and vdata['employee']: + if blt.employee: + raise ParseError('该定位卡已绑定人员,请先解绑') + else: + blt.employee = vdata['employee'] + blt.obj_cate = 'people' + blt.save() + vdata['obj_cate'] = 'people' + BltBind.objects.create(**vdata) + elif vdata['type'] == BltBind.BLT_UNBIND: + if blt.employee: + blt.employee = None + blt.save() + vdata['obj_cate'] = 'people' + BltBind.objects.create(**vdata) + else: + raise ParseError('该定位卡在系统中不存在') return Response() @action(methods=['post'], detail=False, perms_map={'post': '*'},