优化案件生成
This commit is contained in:
@@ -774,26 +774,33 @@ class Project(APIView):
|
||||
class Projectquerytype(APIView):
|
||||
def post(self, request, *args, **kwargs):
|
||||
"""
|
||||
查询某一个项目类型的数量(及下一个合同编号预览)。
|
||||
根据年份和项目类型,先查该年份该项目类型的编号(序号),再组装成合同编号返回。
|
||||
|
||||
入参:
|
||||
- type(必填):项目类型,如 法律顾问、专项服务
|
||||
- times 或 year(可选):年份,不传则按当前年;times 取前四位作为年份
|
||||
- year(可选):年份,如 2025;不传则用 times 或当前年
|
||||
- times(可选):日期字符串,取前四位作为年份
|
||||
|
||||
逻辑:1) 按 年份 + 项目类型 查询当前已用到的编号(序号)
|
||||
2) 下一个可用编号 = 当前编号 + 1,组装成「校准(字)字【年份】第n号」
|
||||
返回 data:
|
||||
- count:该项目类型在指定年份的立项数量(已用序号,即已有多少条)
|
||||
- next_number:下一个序号(count + 1)
|
||||
- next_contract_no:下一个合同编号预览,如 校准(顾)字【2025】第1号
|
||||
|
||||
每个项目类型按「类型+年份」独立计数,跨年归零。
|
||||
- contract_no:组装好的合同编号(下一个可用),如 校准(顾)字【2025】第1号
|
||||
- number:下一个可用序号
|
||||
- count:该年份该项目类型当前已用数量(已用到的最大序号)
|
||||
"""
|
||||
project_type = request.data.get('type')
|
||||
if not project_type:
|
||||
return Response({'status': 'error', 'message': '缺少参数type', 'code': 1}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# 可选:传入 times 或 year 指定年份,否则用当前年
|
||||
# 解析年份:优先 year,其次 times 前四位,否则当前年
|
||||
year_param = request.data.get('year')
|
||||
times = request.data.get('times')
|
||||
if times and len(str(times)) >= 4:
|
||||
if year_param is not None and str(year_param).strip():
|
||||
try:
|
||||
current_year = int(str(year_param).strip()[:4])
|
||||
except ValueError:
|
||||
current_year = datetime.now().year
|
||||
elif times and len(str(times)) >= 4:
|
||||
try:
|
||||
current_year = int(str(times)[:4])
|
||||
except ValueError:
|
||||
@@ -801,6 +808,7 @@ class Projectquerytype(APIView):
|
||||
else:
|
||||
current_year = datetime.now().year
|
||||
|
||||
# 1) 根据年份 + 项目类型 查询该年份该项目类型的编号(当前已用到的序号)
|
||||
try:
|
||||
with transaction.atomic():
|
||||
counter = ContractCounter.objects.filter(
|
||||
@@ -820,11 +828,19 @@ class Projectquerytype(APIView):
|
||||
is_deleted=False
|
||||
).count()
|
||||
|
||||
next_number, next_contract_no = get_next_contract_no_preview(project_type, current_year)
|
||||
# 2) 下一个可用编号 = 当前数量 + 1,组装成合同编号
|
||||
next_number, contract_no = get_next_contract_no_preview(project_type, current_year)
|
||||
if not contract_no:
|
||||
return Response({
|
||||
'status': 'error',
|
||||
'message': f'项目类型「{project_type}」未配置合同编号规则,无法组装编号',
|
||||
'code': 1
|
||||
}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
data = {
|
||||
"contract_no": contract_no,
|
||||
"number": next_number,
|
||||
"count": count,
|
||||
"next_number": next_number,
|
||||
"next_contract_no": next_contract_no or "",
|
||||
}
|
||||
return Response({'message': '查询成功', "data": data, 'code': 0}, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user