|
@@ -17,7 +17,7 @@ from math import ceil
|
|
import openpyxl
|
|
import openpyxl
|
|
import requests
|
|
import requests
|
|
from django.db import transaction, connection
|
|
from django.db import transaction, connection
|
|
-from django.db.models import Q, F
|
|
|
|
|
|
+from django.db.models import Q, F, Count
|
|
from django.http import HttpResponse
|
|
from django.http import HttpResponse
|
|
from django.views.generic.base import View
|
|
from django.views.generic.base import View
|
|
|
|
|
|
@@ -128,6 +128,8 @@ class UnicomManageControllerView(View):
|
|
return self.update_flow_combo_by_id(request_dict, response)
|
|
return self.update_flow_combo_by_id(request_dict, response)
|
|
if operation == 'verifyPackageExport':
|
|
if operation == 'verifyPackageExport':
|
|
return self.verify_package_export_excel(request, request_dict, response)
|
|
return self.verify_package_export_excel(request, request_dict, response)
|
|
|
|
+ elif operation == 'batchSerialNumberCombo': # 批量查询序列号绑定iccid情况
|
|
|
|
+ return self.batch_serial_number_combo(request, response)
|
|
else:
|
|
else:
|
|
return response.json(404)
|
|
return response.json(404)
|
|
|
|
|
|
@@ -1633,3 +1635,57 @@ class UnicomManageControllerView(View):
|
|
LOGGER.info('*****UnicomManageController.batch_order_flow:errLine:{}, errMsg:{}'
|
|
LOGGER.info('*****UnicomManageController.batch_order_flow:errLine:{}, errMsg:{}'
|
|
.format(e.__traceback__.tb_lineno, repr(e)))
|
|
.format(e.__traceback__.tb_lineno, repr(e)))
|
|
return
|
|
return
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def batch_serial_number_combo(request, response):
|
|
|
|
+ file = request.FILES.get('file', None)
|
|
|
|
+ if file is None:
|
|
|
|
+ return response.json(444)
|
|
|
|
+
|
|
|
|
+ # 读取文件内容并只保留每行的前9位
|
|
|
|
+ serial_numbers = set()
|
|
|
|
+ if file.name.endswith('.txt'):
|
|
|
|
+ content = file.read().decode('utf-8')
|
|
|
|
+ for line in content.splitlines():
|
|
|
|
+ if line: # 确保行不为空
|
|
|
|
+ serial_numbers.add(line[:9]) # 只保留前9位
|
|
|
|
+
|
|
|
|
+ print(serial_numbers)
|
|
|
|
+ # 如果没有有效的 serial_no,直接返回
|
|
|
|
+ if not serial_numbers:
|
|
|
|
+ return response.json(0, {
|
|
|
|
+ 'single_iccid': [],
|
|
|
|
+ 'no_iccid': [],
|
|
|
|
+ 'multiple_iccid': []
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ # 查询数据库中每个 serial_no 绑定的 iccid 数量
|
|
|
|
+ results = (
|
|
|
|
+ UnicomDeviceInfo.objects
|
|
|
|
+ .filter(serial_no__in=serial_numbers) # 过滤出有效的 serial_no
|
|
|
|
+ .values('serial_no') # 只查询 serial_no 字段
|
|
|
|
+ .annotate(iccid_count=Count('iccid')) # 统计每个 serial_no 的 iccid 数量
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ # 初始化结果字典
|
|
|
|
+ result_dict = {
|
|
|
|
+ 'single_iccid': [],
|
|
|
|
+ 'no_iccid': [],
|
|
|
|
+ 'multiple_iccid': []
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 将查询结果转换为字典,方便快速查找
|
|
|
|
+ serial_iccid_count = {item['serial_no']: item['iccid_count'] for item in results}
|
|
|
|
+
|
|
|
|
+ # 分类统计
|
|
|
|
+ for serial_no in serial_numbers:
|
|
|
|
+ iccid_count = serial_iccid_count.get(serial_no, 0) # 如果没有记录,默认为0
|
|
|
|
+ if iccid_count == 1:
|
|
|
|
+ result_dict['single_iccid'].append(serial_no)
|
|
|
|
+ elif iccid_count >= 2:
|
|
|
|
+ result_dict['multiple_iccid'].append(serial_no)
|
|
|
|
+ else:
|
|
|
|
+ result_dict['no_iccid'].append(serial_no)
|
|
|
|
+
|
|
|
|
+ return response.json(0, result_dict)
|
|
|
|
+
|