blt bind接口修改

This commit is contained in:
曹前明 2022-09-02 10:34:57 +08:00
parent 41dd724ffb
commit 66182e56f8
2 changed files with 23 additions and 18 deletions

View File

@ -92,11 +92,12 @@ class BltQuerySerializer(serializers.ModelSerializer):
class BltBindCreateSerializer(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: class Meta:
model = BltBind model = BltBind
fields = ['type', 'blt', 'employee'] fields = ['type', 'code', 'employee']
class BltCreatesSerializer(serializers.Serializer): class BltCreatesSerializer(serializers.Serializer):

View File

@ -260,22 +260,26 @@ class TDeviceViewSet(ListModelMixin, UpdateModelMixin, DestroyModelMixin, Custom
serializer = BltBindCreateSerializer(data=request.data) serializer = BltBindCreateSerializer(data=request.data)
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
vdata = serializer.validated_data vdata = serializer.validated_data
blt = vdata['blt'] code = vdata['code']
if vdata['type'] == BltBind.BLT_BIND and vdata['employee']: blt = TDevice.objects.filter(code=code, type=TDevice.DEVICE_BLT).first()
if blt.employee: if blt:
raise ParseError('该定位卡已绑定人员,请先解绑') if vdata['type'] == BltBind.BLT_BIND and vdata['employee']:
else: if blt.employee:
blt.employee = vdata['employee'] raise ParseError('该定位卡已绑定人员,请先解绑')
blt.obj_cate = 'people' else:
blt.save() blt.employee = vdata['employee']
vdata['obj_cate'] = 'people' blt.obj_cate = 'people'
BltBind.objects.create(**vdata) blt.save()
elif vdata['type'] == BltBind.BLT_UNBIND: vdata['obj_cate'] = 'people'
if blt.employee: BltBind.objects.create(**vdata)
blt.employee = None elif vdata['type'] == BltBind.BLT_UNBIND:
blt.save() if blt.employee:
vdata['obj_cate'] = 'people' blt.employee = None
BltBind.objects.create(**vdata) blt.save()
vdata['obj_cate'] = 'people'
BltBind.objects.create(**vdata)
else:
raise ParseError('该定位卡在系统中不存在')
return Response() return Response()
@action(methods=['post'], detail=False, perms_map={'post': '*'}, @action(methods=['post'], detail=False, perms_map={'post': '*'},