forked from erp-dev/erp
fix: by-process-node do not filter current state and added datr_from + date_to
This commit is contained in:
@@ -486,10 +486,14 @@ class PlateOrderByProcessNodeView(APIView):
|
||||
process_node_id = qp.get('process_node_id')
|
||||
param_key = (qp.get('param_key') or '').strip()
|
||||
param_value = (qp.get('param_value') or '').strip()
|
||||
date_from = qp.get('date_from')
|
||||
date_to = qp.get('date_to')
|
||||
if not process_node_id:
|
||||
return Response({'detail': 'process_node_id 为必填参数'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
if (param_key and not param_value) or (param_value and not param_key):
|
||||
return Response({'detail': 'param_key 与 param_value 必须同时提供'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
if (date_from and not date_to) or (date_to and not date_from):
|
||||
return Response({'detail': 'date_from 与 date_to 必须同时提供'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
try:
|
||||
process_node_id_int = int(process_node_id)
|
||||
@@ -505,6 +509,22 @@ class PlateOrderByProcessNodeView(APIView):
|
||||
except stateflow_models.ProcessNode.DoesNotExist:
|
||||
return Response({'detail': 'process_node 不存在'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
if date_from and date_to:
|
||||
try:
|
||||
start_date = datetime.datetime.strptime(date_from, '%Y-%m-%d').date()
|
||||
end_date = datetime.datetime.strptime(date_to, '%Y-%m-%d').date()
|
||||
except ValueError:
|
||||
return Response({'detail': '日期格式需为 YYYY-MM-DD'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# 闭区间:包含当日 00:00:00 和 23:59:59.999999
|
||||
start_dt = datetime.datetime.combine(start_date, datetime.time.min)
|
||||
end_dt = datetime.datetime.combine(end_date, datetime.time.max)
|
||||
|
||||
if timezone.is_naive(start_dt):
|
||||
start_dt = timezone.make_aware(start_dt, timezone.get_default_timezone())
|
||||
if timezone.is_naive(end_dt):
|
||||
end_dt = timezone.make_aware(end_dt, timezone.get_default_timezone())
|
||||
|
||||
# 目标节点信息
|
||||
target_state_id = process_node.state_id
|
||||
target_order = process_node.order
|
||||
@@ -525,7 +545,10 @@ class PlateOrderByProcessNodeView(APIView):
|
||||
.filter(business_object__isnull=False, business_object__process_id=process_id)
|
||||
)
|
||||
|
||||
# NEXT 模式判定:前置节点都已完成(未撤销) + 目标节点尚未完成(未撤销)
|
||||
if date_from and date_to:
|
||||
queryset = queryset.filter(created_at__gte=start_dt, created_at__lte=end_dt)
|
||||
|
||||
# COMPLETED 模式判定:目标节点已完成(未撤销)
|
||||
if prev_state_ids:
|
||||
queryset = queryset.annotate(
|
||||
completed_prev_states=Count(
|
||||
@@ -547,7 +570,7 @@ class PlateOrderByProcessNodeView(APIView):
|
||||
),
|
||||
distinct=True,
|
||||
)
|
||||
).filter(completed_target=0)
|
||||
).filter(completed_target__gt=0)
|
||||
|
||||
if param_key and param_value:
|
||||
matching_logs = stateflow_models.StateFlowRecord.objects.filter(
|
||||
|
||||
Reference in New Issue
Block a user