|
@@ -12,7 +12,7 @@ import time
|
|
|
from decimal import Decimal
|
|
|
|
|
|
from Ansjer.config import LOGGER
|
|
|
-from Model.models import UnicomDeviceInfo, LogModel
|
|
|
+from Model.models import UnicomDeviceInfo, LogModel, AccessNumberTaskQueue
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.TelecomObject import TelecomObject
|
|
|
|
|
@@ -74,24 +74,81 @@ class TelecomService:
|
|
|
return sim_flow_used_total
|
|
|
|
|
|
@classmethod
|
|
|
- def update_access_number_network(cls, access_number, action):
|
|
|
+ def update_access_number_network(cls, iccid, access_number, action_value, reason=''):
|
|
|
"""
|
|
|
根据接入号码修改卡网络状态
|
|
|
+ @param reason:
|
|
|
+ @param iccid:
|
|
|
@param access_number: 11位接入号码
|
|
|
- @param action: ADD:单独添加断网,DEL:单独恢复上网
|
|
|
- @return: True|False
|
|
|
+ @param action_value: ADD:单独添加断网,DEL:单独恢复上网
|
|
|
+ @return: 修改后结果 None | success
|
|
|
"""
|
|
|
try:
|
|
|
- result = TelecomObject().single_cut_net(access_number, action)
|
|
|
- url = 'update/access_number/network'
|
|
|
- ip = '127.0.0.1'
|
|
|
- params = {'access_number': access_number, 'action': action, 'result': result}
|
|
|
- if not result:
|
|
|
- explain = f'{access_number}单独断网或恢复异常'
|
|
|
- cls.create_operation_log(url, ip, params, explain)
|
|
|
+ # 获取当前卡号是否有过变更网络状态缓存记录
|
|
|
+ redis = RedisObject()
|
|
|
+ key = f'ASJ:TELECOM:CHANGE:{iccid}'
|
|
|
+ change_data = redis.get_data(key)
|
|
|
+
|
|
|
+ action = 1 if action_value == 'ADD' else 2
|
|
|
+ now_time = int(time.time())
|
|
|
+ # 变更网络存表数据
|
|
|
+ data = {'iccid': iccid, 'access_number': access_number, 'type': 2, 'action': action, 'previous_status': 0,
|
|
|
+ 'new_status': 0, 'count': 0, 'reason': reason,
|
|
|
+ 'status': 0, 'created_time': now_time, 'updated_time': now_time}
|
|
|
+
|
|
|
+ if change_data:
|
|
|
+ c_data = json.loads(change_data)
|
|
|
+ if c_data['actionValue'] == action_value: # 判断是否重复操作
|
|
|
+ return None
|
|
|
+ AccessNumberTaskQueue.objects.create(**data)
|
|
|
+ LOGGER.info(f'{iccid}未执行变更网络,数据已加入任务队列记录')
|
|
|
+ return None
|
|
|
+
|
|
|
+ # 获取当前卡号网络状态 接口有调用限制并发 15000次/秒 所以尝试多次调用
|
|
|
+ now_network_status = 0
|
|
|
+ i = 0
|
|
|
+ while i < 3:
|
|
|
+ network_result = cls.get_access_number_network_status(access_number)
|
|
|
+ if network_result:
|
|
|
+ now_network_status = 2 if network_result == 'connect' else 1
|
|
|
+ break
|
|
|
+ i += 1
|
|
|
+
|
|
|
+ if 0 < now_network_status == action: # 当前状态与要变更的状态相同则不调用变更API
|
|
|
+ ip = '127.0.0.1'
|
|
|
+ params = {'access_number': access_number, 'action': action_value, 'result': '当前网络状态已符合要求'}
|
|
|
+ explain = f'{iccid}单独断网或恢复网络'
|
|
|
+ cls.create_operation_log('updateNetworkStatus', ip, params, explain)
|
|
|
+ return None
|
|
|
+
|
|
|
+ result = TelecomObject().single_cut_net(access_number, action_value)
|
|
|
+
|
|
|
+ # 更新变更状态
|
|
|
+ data['previous_status'] = now_network_status
|
|
|
+ data['new_status'] = action
|
|
|
+ data['count'] = 1
|
|
|
+
|
|
|
+ cache_data = {'iccid': iccid, 'actionValue': action_value}
|
|
|
+ if not result: # 变更电信卡网络状态 失败处理
|
|
|
+ data['status'] = 2
|
|
|
+ data['result'] = {'code': '101007', 'message': '该接入号码高频次受理此业务,调用暂时受限,请稍后再试'}
|
|
|
+
|
|
|
+ AccessNumberTaskQueue.objects.create(**data) # 失败后保存数据记录,走重试机制
|
|
|
+ redis.CONN.setnx(key, json.dumps(cache_data)) # 缓存当前卡号130秒不再调用变更网络状态接口,防止调用限制
|
|
|
+ redis.CONN.expire(key, 130)
|
|
|
return None
|
|
|
- explain = f'{access_number}单独断网或恢复成功'
|
|
|
- cls.create_operation_log(url, ip, params, explain)
|
|
|
+
|
|
|
+ data['status'] = 1
|
|
|
+ data['completion_time'] = now_time
|
|
|
+ if result == '-5': # 已符合变更后状态
|
|
|
+ data['result'] = {'-5': '该号码未订购单独断网功能!;流水号:1000000190202402201640359500'}
|
|
|
+ else:
|
|
|
+ data['result'] = result
|
|
|
+
|
|
|
+ AccessNumberTaskQueue.objects.create(**data)
|
|
|
+ redis.CONN.setnx(key, json.dumps(cache_data))
|
|
|
+ redis.CONN.expire(key, 130)
|
|
|
+
|
|
|
return 'success'
|
|
|
except Exception as e:
|
|
|
LOGGER.info('***{} TelecomService.update_access_number_network:errLine:{}, errMsg:{}'
|
|
@@ -137,9 +194,10 @@ class TelecomService:
|
|
|
result = TelecomObject().query_product_information(access_number)
|
|
|
if not result:
|
|
|
return None
|
|
|
- if result and result['result_code']:
|
|
|
+
|
|
|
+ if result and result['SvcCont']['resultCode'] == '0':
|
|
|
# 获取产品信息
|
|
|
- prod_infos = result["result"]["SvcCont"]["result"]["prodInfos"]
|
|
|
+ prod_infos = result["SvcCont"]["result"]["prodInfos"]
|
|
|
|
|
|
# 获取 funProdInfos 列表
|
|
|
fun_prod_infos = prod_infos["funProdInfos"]
|
|
@@ -154,9 +212,9 @@ class TelecomService:
|
|
|
is_disconnect_value = re.search(r"(?<=:).+", is_disconnect).group(0)
|
|
|
# 进行判断
|
|
|
if is_disconnect_value == "否":
|
|
|
- return 'disconnect'
|
|
|
- else:
|
|
|
return 'connect'
|
|
|
+ else:
|
|
|
+ return 'disconnect'
|
|
|
return None
|
|
|
except Exception as e:
|
|
|
print('***{}get_access_number_network_status,errLine:{}, errMsg:{}'
|