You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

103 lines
3.5 KiB

from sqlalchemy import desc, delete, func, select, update
from sqlalchemy.ext.asyncio import AsyncSession
from module_admin.entity.do.approval_do import FlowApproval, FlowConfig
from module_admin.entity.vo.approval_vo import ApprovalQueryObject
from module_admin.entity.vo.user_vo import CurrentUserModel
from sqlalchemy import select, text, cast, Integer, and_, or_, outerjoin, func, join
from utils.page_util import PageUtil
class ApprovalDao:
"""
菜单管理模块数据库操作层
"""
@classmethod
async def add_flow_approval(cls, db: AsyncSession, flow_approval: FlowApproval):
db.add(flow_approval)
await db.flush()
return flow_approval
@classmethod
async def get_flow_by_id(cls, db: AsyncSession, flowId: str):
result = (
(
await db.execute(
select(FlowApproval).where(
FlowApproval.id == flowId
)
)
)
.scalars()
.first()
)
return result
@classmethod
async def edit_flow_approval(cls, db: AsyncSession, flow: dict):
await db.execute(update(FlowApproval), [flow])
@classmethod
async def get_flow_list(cls, db: AsyncSession, query_param: ApprovalQueryObject, current_user: CurrentUserModel):
query = (
select(FlowApproval)
.where(
(FlowApproval.applicant == query_param.status) if query_param.applicant else True,
(FlowApproval.businessType == query_param.businessType) if query_param.businessType else True,
or_(
FlowApproval.approver == current_user.user.user_name,
FlowApproval.approver.in_(current_user.roles)
) if current_user.user.user_name != 'admin' else True
)
.order_by(FlowApproval.applyTime)
.distinct()
)
# 注意:这里不执行查询,而是将查询对象传递给 paginate 方法
result = await PageUtil.paginate(db, query, query_param.page_num, query_param.page_size, True)
return result
@classmethod
async def get_waiting_total(cls, db: AsyncSession, current_user: CurrentUserModel):
return (await db.execute(select(func.count()).select_from(FlowApproval)
.where(FlowApproval.approver == current_user.user.user_name))).scalar()
@classmethod
async def get_flow_by_idAndUser(cls, db: AsyncSession, flow_id: str, username: str):
result = (
(
await db.execute(
select(FlowApproval).where(
FlowApproval.id == flow_id,
FlowApproval.applicant == username
)
)
)
.scalars()
.first()
)
return result
@classmethod
async def get_conf_list(cls, db: AsyncSession, module: str):
result = (
(
await db.execute(select(FlowConfig).where(
FlowConfig.module == module
))
).scalars().all()
)
return result
@classmethod
async def add_flow_config(cls, db: AsyncSession, conf: dict):
db_conf = FlowConfig(**conf)
db.add(db_conf)
await db.flush()
return conf
@classmethod
async def delete_flow_by_module(cls, module: str, db: AsyncSession):
await db.execute(delete(FlowConfig).where(FlowConfig.module == module))