feat(pl): 按运输段产品维护合法使用证明并隔离异步会话。
This commit is contained in:
1 parent
722076fb3f
commit
4cb2d88dab
8 files changed
+1103
-404
No files matched your search
@@ -262,10 +262,11 @@ def list_documents(keyword: Optional[str] = None, status: Optional[str] = None,
|
||||
|
||||
@legal_router.get('/stops')
|
||||
def list_stop_documents(keyword: Optional[str] = None, status: Optional[str] = None,
|
||||
plan_no: Optional[str] = Query(None, alias='planNo'),
|
||||
contract_id: Optional[str] = Query(None, alias='contractId'),
|
||||
page: int = Query(1, ge=1), page_size: int = Query(20, alias='pageSize', ge=1, le=100),
|
||||
db: Session = Depends(get_db), user: DbUserContext = Depends(current_user)):
|
||||
return _wire(stop_documents.list_documents(db, user, keyword, status, contract_id, page, page_size))
|
||||
return _wire(stop_documents.list_documents(db, user, keyword, status, contract_id, page, page_size, plan_no=plan_no))
|
||||
|
||||
|
||||
@legal_router.get('/stops/{plan_id}')
|
||||
|
||||
@@ -70,7 +70,9 @@ def _details(db, user, plans, contract_id=None, lock=False):
|
||||
query = _query(db, user, side, model, parent, field, contract_id).filter(model.plan_id.in_(result))
|
||||
if lock:
|
||||
query = query.with_for_update().populate_existing()
|
||||
for row, stop, product, contract, document in query.order_by(parent.order_num, parent.id, model.order_num, model.id).all():
|
||||
stop_order = (func.coalesce(func.nullif(parent.seq, 0), parent.order_num)
|
||||
if side == 'delivery' else parent.order_num)
|
||||
for row, stop, product, contract, document in query.order_by(stop_order, parent.id, model.order_num, model.id).all():
|
||||
url = document.legal_use_cert_url if document else None
|
||||
result[row.plan_id]['items'].append({
|
||||
'stopType': side, 'stopId': stop.id, 'stopOrder': getattr(stop, 'seq', None) or stop.order_num or 1,
|
||||
@@ -102,7 +104,7 @@ def get_documents(db, user, plan_id, contract_id=None):
|
||||
return _details(db, user, [plan], contract_id)[plan_id]
|
||||
|
||||
|
||||
def list_documents(db, user, keyword=None, status=None, contract_id=None, page=1, page_size=20):
|
||||
def list_documents(db, user, keyword=None, status=None, contract_id=None, page=1, page_size=20, plan_no=None):
|
||||
if status not in (None, 'pending', 'uploaded') or page < 1 or not 1 <= page_size <= 100:
|
||||
raise HTTPException(400, '无效资料状态或分页参数')
|
||||
if contract_id:
|
||||
@@ -124,6 +126,8 @@ def list_documents(db, user, keyword=None, status=None, contract_id=None, page=1
|
||||
query = apply_pl_scope(query, PlPlan, user, db, user.tenant_no)
|
||||
if keyword:
|
||||
query = query.filter(PlPlan.plan_no.contains(keyword))
|
||||
if plan_no:
|
||||
query = query.filter(PlPlan.plan_no.contains(plan_no))
|
||||
if status == 'pending':
|
||||
query = query.filter(counts.c.uploaded < counts.c.required)
|
||||
elif status == 'uploaded':
|
||||
|
||||
@@ -180,7 +180,7 @@ def test_multiple_plans_filter_then_page_and_route_shape(case):
|
||||
c.db.add(c.m.PlPlanDeliveryProduct(id=pid+'dp', delivery_id=pid+'d', plan_id=pid,
|
||||
plan_product_id=pid+'pp', product_id='sku', product_no='S', product_name='产品', tenant_no='t'))
|
||||
c.db.flush()
|
||||
first = list_stop_documents(keyword=None, status='pending', contract_id=None, page=1, page_size=2, db=c.db, user=c.user)
|
||||
first = list_stop_documents(keyword=None, plan_no=None, status='pending', contract_id=None, page=1, page_size=2, db=c.db, user=c.user)
|
||||
second = c.svc.list_documents(c.db, c.user, status='pending', page=2, page_size=2)
|
||||
assert first['total'] == second['total'] == 4
|
||||
assert len(first['list']) == len(second['list']) == 2
|
||||
@@ -269,3 +269,21 @@ def test_save_response_stop_details_keep_current_read(case):
|
||||
# 装送两侧均有校验读与最终响应读,均须保留当前读。
|
||||
assert len(statements) == 4
|
||||
assert all('FOR UPDATE' in sql for sql in statements)
|
||||
|
||||
|
||||
def test_keyword_and_plan_number_filter_are_combined(case):
|
||||
c = case
|
||||
assert c.svc.list_documents(c.db, c.user, keyword='P', plan_no='P')['total'] == 1
|
||||
assert c.svc.list_documents(c.db, c.user, keyword='P', plan_no='OTHER')['total'] == 0
|
||||
|
||||
|
||||
def test_delivery_details_follow_sequence_before_legacy_order(case):
|
||||
c = case
|
||||
c.db.get(c.m.PlPlanDelivery, 'd1').seq = 2
|
||||
c.db.get(c.m.PlPlanDelivery, 'd1').order_num = 1
|
||||
c.db.get(c.m.PlPlanDelivery, 'd2').seq = 1
|
||||
c.db.get(c.m.PlPlanDelivery, 'd2').order_num = 2
|
||||
c.db.flush()
|
||||
rows = c.svc.get_documents(c.db, c.user, 'p')['items']
|
||||
assert [row['stopProductId'] for row in rows] == ['lp', 'd2p', 'd1p']
|
||||
assert [row['stopOrder'] for row in rows] == [1, 1, 2]
|
||||
Reference in new issue
Block a user