|
@@ -1,5 +1,5 @@
|
|
|
from rest_framework import status
|
|
from rest_framework import status
|
|
|
-from rest_framework.viewsets import ModelViewSet
|
|
|
|
|
|
|
+from rest_framework import viewsets
|
|
|
from rest_framework.response import Response
|
|
from rest_framework.response import Response
|
|
|
from rest_framework.decorators import action
|
|
from rest_framework.decorators import action
|
|
|
from rest_framework.serializers import ValidationError
|
|
from rest_framework.serializers import ValidationError
|
|
@@ -16,7 +16,7 @@ from utils.utils import get_equip_list, Get_SIM_info
|
|
|
# Create your views here.
|
|
# Create your views here.
|
|
|
|
|
|
|
|
|
|
|
|
|
-class PlatformIOTCardViewSet(ModelViewSet):
|
|
|
|
|
|
|
+class PlatformIOTCardViewSet(viewsets.ModelViewSet):
|
|
|
serializer_class = PlatSimInfoSerializer
|
|
serializer_class = PlatSimInfoSerializer
|
|
|
pagination_class = CustomPagination
|
|
pagination_class = CustomPagination
|
|
|
queryset = PlatSimInfo.objects.all().order_by("expiry_date")
|
|
queryset = PlatSimInfo.objects.all().order_by("expiry_date")
|
|
@@ -113,3 +113,56 @@ class PlatformIOTCardViewSet(ModelViewSet):
|
|
|
self.perform_create(serializer)
|
|
self.perform_create(serializer)
|
|
|
headers = self.get_success_headers(serializer.data)
|
|
headers = self.get_success_headers(serializer.data)
|
|
|
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
|
|
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
|
|
|
|
|
+ def update(self, request, pk, *args, **kwargs):
|
|
|
|
|
+ req = request.data.get("req")
|
|
|
|
|
+ instance = self.get_object()
|
|
|
|
|
+ if req == "upgrade":
|
|
|
|
|
+ iccid = instance.simId
|
|
|
|
|
+ sim_operators,account_status,active_date,data_plan,data_usage,data_balance,expiry_date = Get_SIM_info(iccid).get_sim_info()
|
|
|
|
|
+ update_data = {
|
|
|
|
|
+ "sim_operators" : sim_operators,
|
|
|
|
|
+ "account_status" : account_status,
|
|
|
|
|
+ "active_date" : active_date,
|
|
|
|
|
+ "data_plan" : data_plan,
|
|
|
|
|
+ "data_usage" : data_usage,
|
|
|
|
|
+ "data_balance" : data_balance,
|
|
|
|
|
+ "expiry_date" : expiry_date
|
|
|
|
|
+ }
|
|
|
|
|
+ elif req == "change":
|
|
|
|
|
+ if instance.input_type == 1:
|
|
|
|
|
+ raise ValidationError("设备录入物联网卡禁止更改")
|
|
|
|
|
+ simId = request.POST.get("simId").strip()
|
|
|
|
|
+ if len(simId) > 20 or len(simId) < 19:
|
|
|
|
|
+ raise ValidationError("物联网卡长度介于19-20位")
|
|
|
|
|
+ if self.get_queryset().filter(simId=simId).exists():
|
|
|
|
|
+ raise ValidationError("预更改卡号已存在")
|
|
|
|
|
+
|
|
|
|
|
+ platform = instance.platform
|
|
|
|
|
+ device_id = instance.deviceId
|
|
|
|
|
+ if platform == 1:
|
|
|
|
|
+ res = requests.post(url="http://www.yfzhwlw.com/equip_simiccid",data={"e_id":device_id,"iccid":simId})
|
|
|
|
|
+ if res.text != "0":
|
|
|
|
|
+ raise ValidationError("对应平台更换异常")
|
|
|
|
|
+ else:
|
|
|
|
|
+ res = requests.post(url="http://8.136.98.49:8002/api/api_gateway?method=forecast.send_control.device_sim",
|
|
|
|
|
+ data={"device_id": device_id,"iccid": simId,"type": "change"})
|
|
|
|
|
+ res_json = json.loads(res.text)
|
|
|
|
|
+ if res_json["message"] != "":
|
|
|
|
|
+ raise ValidationError("对应平台更换异常")
|
|
|
|
|
+ sim_operators,account_status,active_date,data_plan,data_usage,data_balance,expiry_date = Get_SIM_info(simId).get_sim_info()
|
|
|
|
|
+ update_data = {
|
|
|
|
|
+ "simId": simId,
|
|
|
|
|
+ "sim_operators" : sim_operators,
|
|
|
|
|
+ "account_status" : account_status,
|
|
|
|
|
+ "active_date" : active_date,
|
|
|
|
|
+ "data_plan" : data_plan,
|
|
|
|
|
+ "data_usage" : data_usage,
|
|
|
|
|
+ "data_balance" : data_balance,
|
|
|
|
|
+ "expiry_date" : expiry_date
|
|
|
|
|
+ }
|
|
|
|
|
+ else:
|
|
|
|
|
+ raise ValidationError("未识别req参数")
|
|
|
|
|
+ serializer = self.get_serializer(instance, data=update_data, partial=True)
|
|
|
|
|
+ serializer.is_valid(raise_exception=True)
|
|
|
|
|
+ self.perform_update(serializer)
|
|
|
|
|
+ return Response(serializer.data)
|