68 lines
3.2 KiB
Python
68 lines
3.2 KiB
Python
"""服务号绑定及事务内通知 outbox;不复用小程序 OpenID。"""
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import Column, String, DateTime, Integer, SmallInteger, Text, UniqueConstraint, Index
|
|
from app.core.database import Base
|
|
|
|
|
|
class NoticePublicFields:
|
|
tenant_no = Column(String(64), nullable=False)
|
|
order_num = Column(Integer, nullable=True)
|
|
remark = Column(String(512), nullable=True)
|
|
create_by = Column(String(64), nullable=True)
|
|
create_dept_id = Column(String(64), nullable=False, default="")
|
|
create_time = Column(DateTime, nullable=False, default=datetime.now)
|
|
update_by = Column(String(64), nullable=True)
|
|
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now)
|
|
del_flag = Column(SmallInteger, nullable=False, default=0)
|
|
|
|
|
|
class WechatBinding(NoticePublicFields, Base):
|
|
__tablename__ = "sys_wechat_oa_binding"
|
|
id = Column(String(64), primary_key=True)
|
|
user_id = Column(String(64), nullable=False)
|
|
appid = Column(String(64), nullable=False)
|
|
openid = Column(String(64), nullable=True)
|
|
subscribed = Column(SmallInteger, nullable=False, default=0)
|
|
__table_args__ = (
|
|
UniqueConstraint("tenant_no", "appid", "user_id", name="uk_oa_binding_user"),
|
|
UniqueConstraint("tenant_no", "appid", "openid", name="uk_oa_binding_openid"),
|
|
)
|
|
|
|
|
|
class WechatApprovalCycle(NoticePublicFields, Base):
|
|
__tablename__ = "sys_wechat_approval_cycle"
|
|
id = Column(String(64), primary_key=True)
|
|
business_type = Column(String(32), nullable=False)
|
|
business_id = Column(String(64), nullable=False)
|
|
cycle_id = Column(String(64), nullable=False)
|
|
submitted_at = Column(DateTime, nullable=False)
|
|
# 当前任务集合及分配版本。转交 A→B→A 仍产生一次新的待办。
|
|
assignments = Column(Text, nullable=False, default="{}")
|
|
__table_args__ = (UniqueConstraint("tenant_no", "business_type", "business_id", name="uk_oa_cycle_business"),)
|
|
|
|
|
|
class WechatNotice(NoticePublicFields, Base):
|
|
__tablename__ = "sys_wechat_notice"
|
|
id = Column(String(64), primary_key=True)
|
|
appid = Column(String(64), nullable=False)
|
|
business_type = Column(String(32), nullable=False)
|
|
business_id = Column(String(64), nullable=False)
|
|
cycle_id = Column(String(64), nullable=False)
|
|
event_key = Column(String(64), nullable=False, unique=True)
|
|
kind = Column(String(16), nullable=False)
|
|
task_key = Column(String(256), nullable=False, default="")
|
|
recipient_id = Column(String(64), nullable=False)
|
|
result = Column(String(16), nullable=True)
|
|
template_id = Column(String(128), nullable=False)
|
|
payload = Column(Text, nullable=False)
|
|
page = Column(String(1024), nullable=False, default="")
|
|
status = Column(String(16), nullable=False, default="pending")
|
|
attempts = Column(Integer, nullable=False, default=0)
|
|
next_attempt_at = Column(DateTime, nullable=False, default=datetime.now)
|
|
claimed_at = Column(DateTime, nullable=True)
|
|
sent_at = Column(DateTime, nullable=True)
|
|
message_id = Column(String(128), nullable=True)
|
|
last_error = Column(String(256), nullable=True)
|
|
__table_args__ = (Index("idx_oa_notice_due", "status", "next_attempt_at"),)
|