Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions backend/plugin/dict/api/v1/sys/dict_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
router = APIRouter()


@router.get('/all', summary='获取所有字典数据', dependencies=[DependsJwtAuth])
async def get_all_dict_datas() -> ResponseSchemaModel[list[GetDictDataDetail]]:
data = await dict_data_service.get_all()
return response_base.success(data=data)


@router.get('/{pk}', summary='获取字典数据详情', dependencies=[DependsJwtAuth])
async def get_dict_data(
pk: Annotated[int, Path(description='字典数据 ID')],
Expand Down
8 changes: 8 additions & 0 deletions backend/plugin/dict/api/v1/sys/dict_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
router = APIRouter()


@router.get('/{pk}', summary='获取字典类型详情', dependencies=[DependsJwtAuth])
async def get_dict_type(
pk: Annotated[int, Path(description='字典类型 ID')],
) -> ResponseSchemaModel[GetDictTypeDetail]:
data = await dict_type_service.get(pk=pk)
return response_base.success(data=data)


@router.get(
'',
summary='分页获取所有字典类型',
Expand Down
13 changes: 12 additions & 1 deletion backend/plugin/dict/crud/crud_dict_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Sequence

from sqlalchemy import Select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy_crud_plus import CRUDPlus
Expand All @@ -21,6 +23,15 @@ async def get(self, db: AsyncSession, pk: int) -> DictData | None:
"""
return await self.select_model(db, pk)

async def get_all(self, db: AsyncSession) -> Sequence[DictData]:
"""
获取所有字典数据

:param db: 数据库会话
:return:
"""
return await self.select_models(db, load_strategies={'type': 'noload'})

async def get_list(self, label: str | None, value: str | None, status: int | None) -> Select:
"""
获取字典数据列表
Expand All @@ -39,7 +50,7 @@ async def get_list(self, label: str | None, value: str | None, status: int | Non
if status is not None:
filters['status'] = status

return await self.select_order('id', 'desc', *filters)
return await self.select_order('id', 'desc', load_strategies={'type': 'noload'}, **filters)

async def get_by_label(self, db: AsyncSession, label: str) -> DictData | None:
"""
Expand Down
2 changes: 1 addition & 1 deletion backend/plugin/dict/crud/crud_dict_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def get_list(self, *, name: str | None, code: str | None, status: int | No
if status is not None:
filters['status'] = status

return await self.select_order('id', 'desc', **filters)
return await self.select_order('id', 'desc', load_strategies={'datas': 'noload'}, **filters)

async def get_by_code(self, db: AsyncSession, code: str) -> DictType | None:
"""
Expand Down
2 changes: 1 addition & 1 deletion backend/plugin/dict/plugin.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[plugin]
summary = '数据字典'
version = '0.0.1'
version = '0.0.2'
description = '通常用于约束前端工程数据展示'
author = 'wu-clan'

Expand Down
8 changes: 8 additions & 0 deletions backend/plugin/dict/service/dict_data_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Sequence

from sqlalchemy import Select

from backend.common.exception import errors
Expand Down Expand Up @@ -27,6 +29,12 @@ async def get(*, pk: int) -> DictData:
raise errors.NotFoundError(msg='字典数据不存在')
return dict_data

@staticmethod
async def get_all() -> Sequence[DictData]:
async with async_db_session() as db:
dict_datas = await dict_data_dao.get_all(db)
return dict_datas

@staticmethod
async def get_select(*, label: str | None, value: str | None, status: int | None) -> Select:
"""
Expand Down
15 changes: 15 additions & 0 deletions backend/plugin/dict/service/dict_type_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,27 @@
from backend.common.exception import errors
from backend.database.db import async_db_session
from backend.plugin.dict.crud.crud_dict_type import dict_type_dao
from backend.plugin.dict.model import DictType
from backend.plugin.dict.schema.dict_type import CreateDictTypeParam, DeleteDictTypeParam, UpdateDictTypeParam


class DictTypeService:
"""字典类型服务类"""

@staticmethod
async def get(*, pk) -> DictType:
"""
获取字典类型详情

:param pk: 字典类型 ID
:return:
"""
async with async_db_session() as db:
dict_type = await dict_type_dao.get(db, pk)
if not dict_type:
raise errors.NotFoundError(msg='字典类型不存在')
return dict_type

@staticmethod
async def get_select(*, name: str | None, code: str | None, status: int | None) -> Select:
"""
Expand Down