|
|
@@ -24,8 +24,8 @@ from utils.utils import get_equip_list, Get_SIM_info
|
|
|
def time_dif(checkdatetime):
|
|
|
# 获取传入时间和当前时间差
|
|
|
nowdatetime = datetime.datetime.now()
|
|
|
- checkdatetime = datetime.datetime.strptime(checkdatetime,"%Y-%m-%d %H:%M:%S")
|
|
|
-
|
|
|
+ checkdatetime = datetime.datetime.strptime(checkdatetime, "%Y-%m-%d %H:%M:%S")
|
|
|
+
|
|
|
timedif = nowdatetime - checkdatetime
|
|
|
return timedif.days
|
|
|
|
|
|
@@ -89,9 +89,9 @@ class PlatformIOTCardViewSet(viewsets.ModelViewSet):
|
|
|
platformid = 2
|
|
|
else:
|
|
|
raise ValidationError("平台不存在该设备ID,请核查!")
|
|
|
- requests.post(url="http://www.yfzhwlw.com/equip_simiccid", data={"e_id": device_id, "iccid": simId},timeout=5)
|
|
|
+ requests.post(url="http://www.yfzhwlw.com/equip_simiccid", data={"e_id": device_id, "iccid": simId}, timeout=5)
|
|
|
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"},timeout=5)
|
|
|
+ data={"device_id": device_id, "iccid": simId, "type": "change"}, timeout=5)
|
|
|
sim_operators, account_status, active_date, data_plan, data_usage, data_balance, expiry_date = Get_SIM_info(
|
|
|
simId).get_sim_info()
|
|
|
request_data = {
|
|
|
@@ -119,15 +119,16 @@ class PlatformIOTCardViewSet(viewsets.ModelViewSet):
|
|
|
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()
|
|
|
+ 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
|
|
|
+ "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":
|
|
|
deviceId = instance.deviceId
|
|
|
@@ -139,21 +140,23 @@ class PlatformIOTCardViewSet(viewsets.ModelViewSet):
|
|
|
if self.get_queryset().filter(simId=simId).exists():
|
|
|
raise ValidationError("预更改卡号已存在,请核对!")
|
|
|
try:
|
|
|
- requests.post(url="http://www.yfzhwlw.com/equip_simiccid",data={"e_id":deviceId,"iccid":simId},timeout=5)
|
|
|
+ requests.post(url="http://www.yfzhwlw.com/equip_simiccid", data={"e_id": deviceId, "iccid": simId},
|
|
|
+ timeout=5)
|
|
|
requests.post(url="http://8.136.98.49:8002/api/api_gateway?method=forecast.send_control.device_sim",
|
|
|
- data={"device_id": deviceId,"iccid": simId,"type": "change"},timeout=5)
|
|
|
+ data={"device_id": deviceId, "iccid": simId, "type": "change"}, timeout=5)
|
|
|
except:
|
|
|
pass
|
|
|
- sim_operators,account_status,active_date,data_plan,data_usage,data_balance,expiry_date = Get_SIM_info(simId).get_sim_info()
|
|
|
+ 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
|
|
|
+ "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参数")
|
|
|
@@ -169,20 +172,20 @@ class PlatformIOTCardViewSet(viewsets.ModelViewSet):
|
|
|
for i in queryset:
|
|
|
data.append(i.device_type)
|
|
|
return Response(data)
|
|
|
-
|
|
|
+
|
|
|
@action(methods=['get'], detail=False, url_path='down_excel', url_name='down_excel')
|
|
|
def down_excel(self, request, *args, **kwargs):
|
|
|
filename = request.query_params.get("filename")
|
|
|
if filename == "发货表示例模板.xlsx":
|
|
|
save_data = dict(设备ID=[])
|
|
|
elif filename == "合宙续存流量卡筛选模板.xlsx":
|
|
|
- save_data = dict(ICCID=[],续费价格=[],当月消耗流量=[])
|
|
|
+ save_data = dict(ICCID=[], 续费价格=[], 当月消耗流量=[])
|
|
|
elif filename == "SIMBoss续存流量卡筛选模板.xlsx":
|
|
|
- save_data = dict(ICCID=[],筛查月份1=[],筛查月份2=[],筛查月份3=[],筛查月份4=[],筛查月份5=[],
|
|
|
- 筛查月份6=[],筛查月份7=[],筛查月份8=[],筛查月份9=[])
|
|
|
+ save_data = dict(ICCID=[], 筛查月份1=[], 筛查月份2=[], 筛查月份3=[], 筛查月份4=[], 筛查月份5=[],
|
|
|
+ 筛查月份6=[], 筛查月份7=[], 筛查月份8=[], 筛查月份9=[])
|
|
|
else:
|
|
|
now_dir = os.path.dirname(__file__)
|
|
|
- file_path = os.path.join(now_dir,"excel_folder",filename)
|
|
|
+ file_path = os.path.join(now_dir, "excel_folder", filename)
|
|
|
if os.path.exists(file_path) == False:
|
|
|
raise ValidationError("文件不存在,请确认文件名")
|
|
|
else:
|
|
|
@@ -205,14 +208,14 @@ class PlatformIOTCardViewSet(viewsets.ModelViewSet):
|
|
|
def card_delivery_filter(self, request, *args, **kwargs):
|
|
|
file = request.FILES.get('file')
|
|
|
file_dataframe = pd.read_excel(file)
|
|
|
- save_data = dict(deviceid=[],fulldeviceid=[],device_type=[],is_recharge=[],backword=[])
|
|
|
+ save_data = dict(deviceid=[], fulldeviceid=[], device_type=[], is_recharge=[], backword=[])
|
|
|
|
|
|
for deviceId in file_dataframe["设备ID"]:
|
|
|
- if isinstance(deviceId,int):
|
|
|
+ if isinstance(deviceId, int):
|
|
|
deviceId = str(int(deviceId))
|
|
|
else:
|
|
|
deviceId = deviceId.strip()
|
|
|
- sim_queryset = self.get_queryset().filter(deviceId__endswith=deviceId,input_type=1)
|
|
|
+ sim_queryset = self.get_queryset().filter(deviceId__endswith=deviceId, input_type=1)
|
|
|
if sim_queryset.count() == 0:
|
|
|
fulldeviceid = "未知"
|
|
|
device_type = "未知"
|
|
|
@@ -231,8 +234,8 @@ class PlatformIOTCardViewSet(viewsets.ModelViewSet):
|
|
|
else:
|
|
|
is_recharge = "否"
|
|
|
backword = "{}".format(sim_obj.simId)
|
|
|
- if sim_obj.device_type=="孢子仪" or sim_obj.device_type=="测报灯":
|
|
|
- sim2_queryset = self.get_queryset().filter(deviceId=fulldeviceid,input_type=2).order_by("-id")
|
|
|
+ if sim_obj.device_type == "孢子仪" or sim_obj.device_type == "测报灯":
|
|
|
+ sim2_queryset = self.get_queryset().filter(deviceId=fulldeviceid, input_type=2).order_by("-id")
|
|
|
if sim2_queryset:
|
|
|
sim2_obj = sim2_queryset[0]
|
|
|
if sim2_obj.expiry_date == "未知":
|
|
|
@@ -243,10 +246,10 @@ class PlatformIOTCardViewSet(viewsets.ModelViewSet):
|
|
|
is_recharge = "卡1" + is_recharge + ",卡2是"
|
|
|
else:
|
|
|
is_recharge = "卡1" + is_recharge + ",卡2否"
|
|
|
- backword = "卡1:{};卡2:{}".format(sim_obj.simId,sim2_obj.simId)
|
|
|
+ backword = "卡1:{};卡2:{}".format(sim_obj.simId, sim2_obj.simId)
|
|
|
else:
|
|
|
print("卡二不存在")
|
|
|
-
|
|
|
+
|
|
|
else:
|
|
|
fulldeviceid = "未知"
|
|
|
device_type = "未知"
|
|
|
@@ -257,21 +260,21 @@ class PlatformIOTCardViewSet(viewsets.ModelViewSet):
|
|
|
save_data["is_recharge"].append(is_recharge)
|
|
|
save_data["device_type"].append(device_type)
|
|
|
save_data["backword"].append(backword)
|
|
|
-
|
|
|
+
|
|
|
df = pd.DataFrame(data=save_data)
|
|
|
- save_filename = str(uuid.uuid4())+".xlsx"
|
|
|
+ save_filename = str(uuid.uuid4()) + ".xlsx"
|
|
|
now_dir = os.path.dirname(__file__)
|
|
|
- save_path = os.path.join(now_dir,"excel_folder",save_filename)
|
|
|
- df.to_excel(save_path,index=False,header=["设备ID","完整设备号(自行判断)","设备类型","是否需要充值","说明备注"])
|
|
|
+ save_path = os.path.join(now_dir, "excel_folder", save_filename)
|
|
|
+ df.to_excel(save_path, index=False, header=["设备ID", "完整设备号(自行判断)", "设备类型", "是否需要充值", "说明备注"])
|
|
|
return Response(save_filename)
|
|
|
-
|
|
|
+
|
|
|
@action(methods=['post'], detail=False, url_path='xucun_card_filter', url_name='xucun_card_filter')
|
|
|
def xucun_card_filter(self, request, *args, **kwargs):
|
|
|
simtype = request.data.get("simtype")
|
|
|
renew_file = request.FILES.get("file")
|
|
|
file_dataframe = pd.read_excel(renew_file)
|
|
|
if simtype == "1": # 合宙卡
|
|
|
- save_data = dict(ICCID=[], 续费价格=[], 是否需要充值=[],备注=[])
|
|
|
+ save_data = dict(ICCID=[], 续费价格=[], 是否需要充值=[], 备注=[])
|
|
|
sim_list = list(file_dataframe["ICCID"])
|
|
|
price_list = list(file_dataframe["续费价格"])
|
|
|
usage_list = list(file_dataframe["当月消耗流量"])
|
|
|
@@ -287,7 +290,7 @@ class PlatformIOTCardViewSet(viewsets.ModelViewSet):
|
|
|
if card_queryset.exists():
|
|
|
card_obj = card_queryset.first()
|
|
|
deviceId = card_obj.deviceId
|
|
|
- device_info_list = get_equip_list(d_id=deviceId,isfullId=1)
|
|
|
+ device_info_list = get_equip_list(d_id=deviceId, isfullId=1)
|
|
|
if device_info_list:
|
|
|
device_info = device_info_list[0]
|
|
|
uptime = device_info["uptime"]
|
|
|
@@ -306,13 +309,13 @@ class PlatformIOTCardViewSet(viewsets.ModelViewSet):
|
|
|
else:
|
|
|
save_data["是否需要充值"].append("是")
|
|
|
save_data["备注"].append("当月存在流量使用")
|
|
|
- else: # SIMboss
|
|
|
- save_data = dict(ICCID=[],是否需要充值=[])
|
|
|
+ else: # SIMboss
|
|
|
+ save_data = dict(ICCID=[], 是否需要充值=[])
|
|
|
for index, sim in enumerate(file_dataframe["ICCID"]):
|
|
|
save_data["ICCID"].append(str(sim))
|
|
|
status = 0
|
|
|
for i in range(9):
|
|
|
- if float(file_dataframe["筛查月份{}".format(str(i+1))][index]) > 1:
|
|
|
+ if float(file_dataframe["筛查月份{}".format(str(i + 1))][index]) > 1:
|
|
|
status = 1
|
|
|
break
|
|
|
if status == 1:
|
|
|
@@ -321,27 +324,28 @@ class PlatformIOTCardViewSet(viewsets.ModelViewSet):
|
|
|
save_data["是否需要充值"].append("否")
|
|
|
|
|
|
df = pd.DataFrame(data=save_data)
|
|
|
- save_filename = str(uuid.uuid4())+".xlsx"
|
|
|
+ save_filename = str(uuid.uuid4()) + ".xlsx"
|
|
|
now_dir = os.path.dirname(__file__)
|
|
|
- save_path = os.path.join(now_dir,"excel_folder",save_filename)
|
|
|
- df.to_excel(save_path,index=False)
|
|
|
+ save_path = os.path.join(now_dir, "excel_folder", save_filename)
|
|
|
+ df.to_excel(save_path, index=False)
|
|
|
return Response(save_filename)
|
|
|
|
|
|
@action(methods=['post'], detail=False, url_path='inquiries', url_name='inquiries')
|
|
|
- def inquiries(self,request):
|
|
|
+ def inquiries(self, request):
|
|
|
iccid = request.data.get("iccid")
|
|
|
if iccid:
|
|
|
- sim_operators,account_status,active_date,data_plan,data_usage,data_balance,expiry_date = Get_SIM_info(iccid).get_sim_info()
|
|
|
+ sim_operators, account_status, active_date, data_plan, data_usage, data_balance, expiry_date = Get_SIM_info(
|
|
|
+ iccid).get_sim_info()
|
|
|
data = {
|
|
|
"simId": iccid,
|
|
|
- "sim_operators" : "合宙" if sim_operators==1 else "SIMBoss" if sim_operators==2 else "未知",
|
|
|
- "account_status" : account_status,
|
|
|
- "active_date" : active_date,
|
|
|
- "data_plan" : data_plan,
|
|
|
- "data_usage" : data_usage,
|
|
|
- "data_balance" : data_balance,
|
|
|
- "expiry_date" : expiry_date
|
|
|
+ "sim_operators": "合宙" if sim_operators == 1 else "SIMBoss" if sim_operators == 2 else "未知",
|
|
|
+ "account_status": account_status,
|
|
|
+ "active_date": active_date,
|
|
|
+ "data_plan": data_plan,
|
|
|
+ "data_usage": data_usage,
|
|
|
+ "data_balance": data_balance,
|
|
|
+ "expiry_date": expiry_date
|
|
|
}
|
|
|
return Response(data)
|
|
|
else:
|
|
|
- raise ValidationError("iccid参数缺失")
|
|
|
+ raise ValidationError("iccid参数缺失")
|