|
@@ -65,7 +65,7 @@ class SerialNumberView(View):
|
|
|
@param response: 响应对象
|
|
|
"""
|
|
|
use_status = request_dict.get('useStatus', None) # 序列号表的状态
|
|
|
- status = request_dict.get('status', None) # 关联企业序列号表的状态
|
|
|
+ status = request_dict.get('status', None) # 关联企业序列号表的状态
|
|
|
|
|
|
if not all([use_status, status]):
|
|
|
return response.json(444)
|
|
@@ -135,7 +135,7 @@ class SerialNumberView(View):
|
|
|
'user_id': 1,
|
|
|
'status': 200,
|
|
|
'time': now_time,
|
|
|
- 'url': 'company/createSerial',
|
|
|
+ 'url': 'serialNumber/serialCompany',
|
|
|
'content': json.dumps(content),
|
|
|
'operation': '{}生成{}个Company Serial{}: {}'.format(company.name, quantity, '成功', '同步更新成功'),
|
|
|
}
|
|
@@ -183,11 +183,11 @@ class SerialNumberView(View):
|
|
|
# res4 = requests.post(url=url4, data=requests_data, timeout=2 * 60)
|
|
|
# if res4.status_code != 200:
|
|
|
# fail_reason = '请求欧洲服务器生成Company Serial响应状态码异常'
|
|
|
- # return self.failResponse1(company.name, quantity, fail_reason, Log, response)
|
|
|
+ # return self.failResponse(company.name, quantity, fail_reason, Log, response)
|
|
|
# res4 = res4.json()
|
|
|
# if res4['code'] != 0:
|
|
|
# fail_reason = '欧洲服务器生成Company Serial发生异常'
|
|
|
- # return self.failResponse1(company.name, quantity, fail_reason, Log, response)
|
|
|
+ # return self.failResponse(company.name, quantity, fail_reason, Log, response)
|
|
|
|
|
|
return response.json(0)
|
|
|
|
|
@@ -238,7 +238,7 @@ class SerialNumberView(View):
|
|
|
'user_id': 1,
|
|
|
'status': 200,
|
|
|
'time': now_time,
|
|
|
- 'url': 'serialNumber/create',
|
|
|
+ 'url': 'serialNumber/createSerial',
|
|
|
'content': json.dumps(content),
|
|
|
'operation': '生成{}个Serial Number{}: {}'.format(quantity, '成功', '同步更新成功'),
|
|
|
}
|
|
@@ -284,11 +284,11 @@ class SerialNumberView(View):
|
|
|
# res4 = requests.post(url=url4, data=requests_data, timeout=2 * 60)
|
|
|
# if res4.status_code != 200:
|
|
|
# fail_reason = '请求欧洲服务器生成Company Serial响应状态码异常'
|
|
|
- # return self.failResponse(quantity, fail_reason, Log, response)
|
|
|
+ # return self.generateFail(quantity, fail_reason, Log, response)
|
|
|
# res4 = res4.json()
|
|
|
# if res4['code'] != 0:
|
|
|
# fail_reason = '欧洲服务器生成Company Serial发生异常'
|
|
|
- # return self.failResponse(quantity, fail_reason, Log, response)
|
|
|
+ # return self.generateFail(quantity, fail_reason, Log, response)
|
|
|
return response.json(0)
|
|
|
|
|
|
except Exception as e:
|
|
@@ -316,31 +316,40 @@ class SerialNumberView(View):
|
|
|
unused_serial_number_count = SerialNumberModel.objects.filter(use_status=0).count()
|
|
|
remain_qs = CompanySerialModel.objects.filter(status=1).count()
|
|
|
company_qs = CompanyModel.objects.values('id', 'name')
|
|
|
- company_serial_list = [] # 剩余已分配未使用的序列号数量
|
|
|
- company_not_used_list = [] # 已使用的序列号数量
|
|
|
- for company in company_qs:
|
|
|
- id = company['id']
|
|
|
- name = company['name']
|
|
|
- not_used_qs = CompanySerialModel.objects.filter(status=3, company_id=id).count()
|
|
|
- res = {
|
|
|
- 'name': name,
|
|
|
- 'number': not_used_qs
|
|
|
- }
|
|
|
- company_not_used_list.append(res)
|
|
|
-
|
|
|
- for company in company_qs:
|
|
|
- id = company['id']
|
|
|
- name = company['name']
|
|
|
- company_used_qs = CompanySerialModel.objects.filter(status=1, company_id=id).count()
|
|
|
- res = {
|
|
|
- 'name': name,
|
|
|
- 'numbers': company_used_qs
|
|
|
- }
|
|
|
- company_serial_list.append(res)
|
|
|
- res_data = {'code': 0, 'companyRemainCount': company_not_used_list, 'companyRemain': company_serial_list,
|
|
|
- 'unused_serial_number_count': unused_serial_number_count,
|
|
|
- 'unused_all_count': remain_qs}
|
|
|
- return response.json(0, {'data': res_data})
|
|
|
+ try:
|
|
|
+ company_serial_list = [] # 剩余已分配未使用的序列号数量
|
|
|
+ company_not_used_list = [] # 已使用的序列号数量
|
|
|
+ for company in company_qs:
|
|
|
+ id = company['id']
|
|
|
+ name = company['name']
|
|
|
+ not_used_qs = CompanySerialModel.objects.filter(status=3, company_id=id).count()
|
|
|
+ res = {
|
|
|
+ 'name': name,
|
|
|
+ 'number': not_used_qs
|
|
|
+ }
|
|
|
+ company_not_used_list.append(res)
|
|
|
+
|
|
|
+ for company in company_qs:
|
|
|
+ id = company['id']
|
|
|
+ name = company['name']
|
|
|
+ company_serial_qs = CompanySerialModel.objects.filter(status=1, company_id=id).values(
|
|
|
+ 'serial_number').order_by('serial_number')
|
|
|
+ company_used_qs = company_serial_qs.count()
|
|
|
+ serial_list = [item[key] for item in company_serial_qs for key in item]
|
|
|
+ last_serial = serial_list[-1] if company_serial_qs.exists() else ''
|
|
|
+ res = {
|
|
|
+ 'name': name,
|
|
|
+ 'numbers': company_used_qs,
|
|
|
+ 'lastSerial': last_serial
|
|
|
+ }
|
|
|
+ company_serial_list.append(res)
|
|
|
+ res_data = {'code': 0, 'companyRemainCount': company_not_used_list, 'companyRemain': company_serial_list,
|
|
|
+ 'unused_serial_number_count': unused_serial_number_count,
|
|
|
+ 'unused_all_count': remain_qs}
|
|
|
+ return response.json(0, {'data': res_data})
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500)
|
|
|
|
|
|
def do_create(self, request_dict, response):
|
|
|
quantity = int(request_dict.get('quantity', 0))
|