forked from erp-dev/erp
feat: change api/v2/plate-orders/by-process-node/ logic ***** danger
This commit is contained in:
@@ -824,6 +824,28 @@ class PlateOrderByProcessNodeV2APITest(TestCase):
|
||||
self.assertEqual(resp.data['count'], 2)
|
||||
self.assertEqual(len(resp.data['results']), 1)
|
||||
|
||||
def test_param_filter_requires_both_key_and_value(self):
|
||||
resp = self.client.get(self.url, {'process_node_id': self.node2.id, 'param_key': 'temperature'})
|
||||
self.assertEqual(resp.status_code, 400)
|
||||
self.assertIn('param_key', resp.data.get('detail', ''))
|
||||
|
||||
resp = self.client.get(self.url, {'process_node_id': self.node2.id, 'param_value': '30'})
|
||||
self.assertEqual(resp.status_code, 400)
|
||||
self.assertIn('param_value', resp.data.get('detail', ''))
|
||||
|
||||
def test_param_filter_ignores_cancelled_state_logs(self):
|
||||
resp = self.client.get(
|
||||
self.url,
|
||||
{
|
||||
'process_node_id': self.node2.id,
|
||||
'param_key': 'temperature',
|
||||
'param_value': '30',
|
||||
},
|
||||
)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertEqual(resp.data['count'], 0)
|
||||
self.assertEqual(resp.data['results'], [])
|
||||
|
||||
|
||||
class PlateOrderByProcessV2APITest(TestCase):
|
||||
def setUp(self):
|
||||
|
||||
@@ -484,8 +484,12 @@ class PlateOrderByProcessNodeView(APIView):
|
||||
def get(self, request):
|
||||
qp = request.query_params
|
||||
process_node_id = qp.get('process_node_id')
|
||||
param_key = (qp.get('param_key') or '').strip()
|
||||
param_value = (qp.get('param_value') or '').strip()
|
||||
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)
|
||||
|
||||
try:
|
||||
process_node_id_int = int(process_node_id)
|
||||
@@ -545,6 +549,15 @@ class PlateOrderByProcessNodeView(APIView):
|
||||
)
|
||||
).filter(completed_target=0)
|
||||
|
||||
if param_key and param_value:
|
||||
matching_logs = stateflow_models.StateFlowRecord.objects.filter(
|
||||
business_object_id=OuterRef('business_object_id'),
|
||||
state_id=target_state_id,
|
||||
is_cancelled=False,
|
||||
parameter_records__parameters__contains={param_key: param_value},
|
||||
)
|
||||
queryset = queryset.annotate(_has_state_param=Exists(matching_logs)).filter(_has_state_param=True)
|
||||
|
||||
# search:同时支持主键与 design_code icontains(不新增额外参数)
|
||||
search = (qp.get('search') or '').strip()
|
||||
if search:
|
||||
|
||||
Reference in New Issue
Block a user