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):
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):

View File

@ -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': '*'},