fix: 协议子资源单事务保存,并补齐样本编码/OA/质检等近期能力
锁定缴费校验失败时整单回滚,避免样本半成功落库;前端禁止删除锁定缴费样本,改码走更正编码。同步落地样本更正、采集微信通知、OA提及未读、细胞产品套餐与相关迁移文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
19bc66ba45
commit
5dad1bb0e3
142 files changed
+95584
-65717
No files matched your search
@@ -331,8 +331,8 @@ def _ensure_view_grants(
|
||||
) -> None:
|
||||
if not user_ids:
|
||||
return
|
||||
existing = (
|
||||
db.query(OaInstanceViewGrant.user_id)
|
||||
existing_rows = (
|
||||
db.query(OaInstanceViewGrant)
|
||||
.filter(
|
||||
OaInstanceViewGrant.instance_id == instance_id,
|
||||
OaInstanceViewGrant.tenant_no == tenant_no,
|
||||
@@ -341,10 +341,17 @@ def _ensure_view_grants(
|
||||
)
|
||||
.all()
|
||||
)
|
||||
have = {str(r[0]) for r in existing}
|
||||
by_uid = {str(r.user_id): r for r in existing_rows}
|
||||
now = datetime.now()
|
||||
for uid in user_ids:
|
||||
if uid in have:
|
||||
row = by_uid.get(uid)
|
||||
if row is not None:
|
||||
# 再 @:重置未读
|
||||
row.is_read = 0
|
||||
row.comment_id = comment_id
|
||||
row.granted_by = actor_user_id
|
||||
row.update_by = actor_user_id
|
||||
row.update_time = now
|
||||
continue
|
||||
db.add(
|
||||
OaInstanceViewGrant(
|
||||
@@ -354,6 +361,7 @@ def _ensure_view_grants(
|
||||
source="comment_mention",
|
||||
comment_id=comment_id,
|
||||
granted_by=actor_user_id,
|
||||
is_read=0,
|
||||
tenant_no=tenant_no,
|
||||
create_by=actor_user_id,
|
||||
create_dept_id=dept_id or "",
|
||||
@@ -404,6 +412,83 @@ def list_mentioned_instance_ids(
|
||||
return [iid for iid in inst_ids if iid in allowed]
|
||||
|
||||
|
||||
def mention_read_map(
|
||||
db: Session, *, tenant_no: str, user_id: str, instance_ids: List[str]
|
||||
) -> Dict[str, bool]:
|
||||
"""instance_id → isRead(无 grant 视为已读)。"""
|
||||
ids = [str(x).strip() for x in (instance_ids or []) if str(x).strip()]
|
||||
uid = (user_id or "").strip()
|
||||
if not ids or not uid:
|
||||
return {}
|
||||
rows = (
|
||||
db.query(OaInstanceViewGrant)
|
||||
.filter(
|
||||
OaInstanceViewGrant.tenant_no == tenant_no,
|
||||
OaInstanceViewGrant.user_id == uid,
|
||||
OaInstanceViewGrant.del_flag == 0,
|
||||
OaInstanceViewGrant.instance_id.in_(ids),
|
||||
)
|
||||
.all()
|
||||
)
|
||||
out: Dict[str, bool] = {iid: True for iid in ids}
|
||||
for g in rows:
|
||||
iid = (g.instance_id or "").strip()
|
||||
if iid:
|
||||
out[iid] = bool(int(getattr(g, "is_read", 0) or 0) == 1)
|
||||
return out
|
||||
|
||||
|
||||
def count_mention_unread(db: Session, *, tenant_no: str, user_id: str) -> int:
|
||||
uid = (user_id or "").strip()
|
||||
if not uid:
|
||||
return 0
|
||||
q = (
|
||||
db.query(OaInstanceViewGrant)
|
||||
.join(
|
||||
OaInstance,
|
||||
OaInstance.id == OaInstanceViewGrant.instance_id,
|
||||
)
|
||||
.filter(
|
||||
OaInstanceViewGrant.tenant_no == tenant_no,
|
||||
OaInstanceViewGrant.user_id == uid,
|
||||
OaInstanceViewGrant.del_flag == 0,
|
||||
OaInstanceViewGrant.is_read == 0,
|
||||
OaInstance.tenant_no == tenant_no,
|
||||
OaInstance.del_flag == 0,
|
||||
)
|
||||
)
|
||||
return int(q.count())
|
||||
|
||||
|
||||
def mark_mention_instance_read(
|
||||
db: Session, *, tenant_no: str, user_id: str, instance_id: str
|
||||
) -> Dict[str, Any]:
|
||||
uid = (user_id or "").strip()
|
||||
iid = (instance_id or "").strip()
|
||||
if not uid or not iid:
|
||||
raise OaEngineError("参数无效")
|
||||
row = (
|
||||
db.query(OaInstanceViewGrant)
|
||||
.filter(
|
||||
OaInstanceViewGrant.tenant_no == tenant_no,
|
||||
OaInstanceViewGrant.user_id == uid,
|
||||
OaInstanceViewGrant.instance_id == iid,
|
||||
OaInstanceViewGrant.del_flag == 0,
|
||||
)
|
||||
.first()
|
||||
)
|
||||
if not row:
|
||||
raise OaEngineError("提到记录不存在或无权操作")
|
||||
now = datetime.now()
|
||||
if int(getattr(row, "is_read", 0) or 0) != 1:
|
||||
row.is_read = 1
|
||||
row.update_by = uid
|
||||
row.update_time = now
|
||||
db.commit()
|
||||
db.refresh(row)
|
||||
return {"instanceId": iid, "isRead": True}
|
||||
|
||||
|
||||
def create_comment(
|
||||
db: Session,
|
||||
*,
|
||||
@@ -461,6 +546,14 @@ def create_comment(
|
||||
)
|
||||
db.commit()
|
||||
db.refresh(row)
|
||||
if mentions:
|
||||
from app.services.oa_wechat_notify import schedule_oa_mention_notifies
|
||||
|
||||
schedule_oa_mention_notifies(
|
||||
instance_id=instance_id,
|
||||
commenter_user_id=user_id,
|
||||
mentioned_user_ids=mentions,
|
||||
)
|
||||
name_map = _user_name_map(db, [user_id, *mentions])
|
||||
return _comment_to_dict(
|
||||
row,
|
||||
|
||||
Reference in new issue
Block a user