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.
		
		
		
		
			
				
					97 lines
				
				3.2 KiB
			
		
		
			
		
	
	
					97 lines
				
				3.2 KiB
			| 
								 
											8 months ago
										 
									 | 
							
								import uuid
							 | 
						||
| 
								 | 
							
								from typing import List
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								from sqlalchemy import desc, delete, func, select, update
							 | 
						||
| 
								 | 
							
								from sqlalchemy.ext.asyncio import AsyncSession
							 | 
						||
| 
								 | 
							
								from module_admin.entity.vo.user_vo import CurrentUserModel
							 | 
						||
| 
								 | 
							
								from module_admin.entity.vo.dataint_vo import SscfPageObject, TreeOperateModel
							 | 
						||
| 
								 | 
							
								from module_admin.entity.do.dataint_do import SysSscf, SysDassetTree
							 | 
						||
| 
								 | 
							
								from sqlalchemy import select, text, cast, Integer, and_, or_, outerjoin, func, join
							 | 
						||
| 
								 | 
							
								from utils.page_util import PageUtil
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class SscfDao:
							 | 
						||
| 
								 | 
							
								    """
							 | 
						||
| 
								 | 
							
								    菜单管理模块数据库操作层
							 | 
						||
| 
								 | 
							
								    """
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @classmethod
							 | 
						||
| 
								 | 
							
								    async def get_sscf_list(cls, db: AsyncSession, sscf_query: SscfPageObject):
							 | 
						||
| 
								 | 
							
								        query = (
							 | 
						||
| 
								 | 
							
								            select(SysSscf).where(
							 | 
						||
| 
								 | 
							
								                SysSscf.keyword == sscf_query.keyword if sscf_query.keyword else True,
							 | 
						||
| 
								 | 
							
								                SysSscf.type == sscf_query.type if sscf_query.type else True,
							 | 
						||
| 
								 | 
							
								                SysSscf.dasset_id == sscf_query.dasset_id if sscf_query.dasset_id else True,
							 | 
						||
| 
								 | 
							
								                SysSscf.status == sscf_query.status if sscf_query.status else True
							 | 
						||
| 
								 | 
							
								            ).distinct()
							 | 
						||
| 
								 | 
							
								        )
							 | 
						||
| 
								 | 
							
								        query_result = await PageUtil.paginate(db, query, sscf_query.page_num, sscf_query.page_size, True)
							 | 
						||
| 
								 | 
							
								        return query_result
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @classmethod
							 | 
						||
| 
								 | 
							
								    async def insert_sscf(cls, db: AsyncSession, sysSscf: SysSscf):
							 | 
						||
| 
								 | 
							
								        db.add(sysSscf)
							 | 
						||
| 
								 | 
							
								        await db.flush()
							 | 
						||
| 
								 | 
							
								        return sysSscf
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @classmethod
							 | 
						||
| 
								 | 
							
								    async def get_sscf_by_id(cls, db: AsyncSession, onum: str):
							 | 
						||
| 
								 | 
							
								        result = (
							 | 
						||
| 
								 | 
							
								            (
							 | 
						||
| 
								 | 
							
								                await db.execute(
							 | 
						||
| 
								 | 
							
								                    select(SysSscf).where(SysSscf.onum == onum).distinct()
							 | 
						||
| 
								 | 
							
								                )
							 | 
						||
| 
								 | 
							
								            ).scalars().first()
							 | 
						||
| 
								 | 
							
								        )
							 | 
						||
| 
								 | 
							
								        return result
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @classmethod
							 | 
						||
| 
								 | 
							
								    async def update_sscf(cls, db: AsyncSession, saveObj: dict):
							 | 
						||
| 
								 | 
							
								        await db.execute(update(SysSscf), [saveObj])
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @classmethod
							 | 
						||
| 
								 | 
							
								    async def delete_sscf(cls, db: AsyncSession, array: List[str]):
							 | 
						||
| 
								 | 
							
								        await db.execute(delete(SysSscf).where(SysSscf.onum.in_(array)))
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @classmethod
							 | 
						||
| 
								 | 
							
								    async def get_dasset_tree(cls, db: AsyncSession):
							 | 
						||
| 
								 | 
							
								        result = (
							 | 
						||
| 
								 | 
							
								            (
							 | 
						||
| 
								 | 
							
								                await db.execute(
							 | 
						||
| 
								 | 
							
								                    select(SysDassetTree).distinct()
							 | 
						||
| 
								 | 
							
								                )
							 | 
						||
| 
								 | 
							
								            ).scalars().all()
							 | 
						||
| 
								 | 
							
								        )
							 | 
						||
| 
								 | 
							
								        return result
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @classmethod
							 | 
						||
| 
								 | 
							
								    async def get_dasset_tree_by_code(cls, db: AsyncSession, code: str):
							 | 
						||
| 
								 | 
							
								        result = (
							 | 
						||
| 
								 | 
							
								            (
							 | 
						||
| 
								 | 
							
								                await db.execute(
							 | 
						||
| 
								 | 
							
								                    select(SysDassetTree).where(SysDassetTree.dasset_code == code).distinct()
							 | 
						||
| 
								 | 
							
								                )
							 | 
						||
| 
								 | 
							
								            ).scalars().first()
							 | 
						||
| 
								 | 
							
								        )
							 | 
						||
| 
								 | 
							
								        return result
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @classmethod
							 | 
						||
| 
								 | 
							
								    async def insert_dasset_tree(cls, db: AsyncSession, treeOperate: TreeOperateModel):
							 | 
						||
| 
								 | 
							
								        tree = SysDassetTree()
							 | 
						||
| 
								 | 
							
								        tree.onum = uuid.uuid4()
							 | 
						||
| 
								 | 
							
								        tree.dasset_code = treeOperate.dasset_code
							 | 
						||
| 
								 | 
							
								        tree.dasset_name = treeOperate.dasset_name
							 | 
						||
| 
								 | 
							
								        tree.parent_code = "1"
							 | 
						||
| 
								 | 
							
								        db.add(tree)
							 | 
						||
| 
								 | 
							
								        await db.flush()
							 | 
						||
| 
								 | 
							
								        return tree
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @classmethod
							 | 
						||
| 
								 | 
							
								    async def save_dasset_tree(cls, db: AsyncSession, treeOperate: dict):
							 | 
						||
| 
								 | 
							
								        await db.execute(update(SysDassetTree), [treeOperate])
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @classmethod
							 | 
						||
| 
								 | 
							
								    async def delete_dasset_tree(cls, db: AsyncSession, onum: str):
							 | 
						||
| 
								 | 
							
								        await db.execute(delete(SysDassetTree).where(SysDassetTree.onum == onum))
							 | 
						||
| 
								 | 
							
								
							 |