Skip to content

Commit 3efca8a

Browse files
authored
Update the dict plugin table structure (#817)
* Update the dict plugin table structure * Update dict sql * FIx the dict plugin sql
1 parent 82b2f80 commit 3efca8a

File tree

15 files changed

+241
-169
lines changed

15 files changed

+241
-169
lines changed

backend/plugin/dict/api/v1/sys/dict_data.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ async def get_dict_data(
3535
return response_base.success(data=data)
3636

3737

38+
@router.get('/type-codes/{code}', summary='获取字典数据列表', dependencies=[DependsJwtAuth])
39+
async def get_dict_data_by_type_code(
40+
code: Annotated[str, Path(description='字典类型编码')],
41+
) -> ResponseSchemaModel[list[GetDictDataDetail]]:
42+
data = await dict_data_service.get_by_type_code(code=code)
43+
return response_base.success(data=data)
44+
45+
3846
@router.get(
3947
'',
4048
summary='分页获取所有字典数据',

backend/plugin/dict/api/v1/sys/dict_type.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ async def get_dict_types_paged(
4747
db: CurrentSession,
4848
name: Annotated[str | None, Query(description='字典类型名称')] = None,
4949
code: Annotated[str | None, Query(description='字典类型编码')] = None,
50-
status: Annotated[int | None, Query(description='状态')] = None,
5150
) -> ResponseSchemaModel[PageData[GetDictTypeDetail]]:
52-
dict_type_select = await dict_type_service.get_select(name=name, code=code, status=status)
51+
dict_type_select = await dict_type_service.get_select(name=name, code=code)
5352
page_data = await paging_data(db, dict_type_select)
5453
return response_base.success(data=page_data)
5554

backend/plugin/dict/crud/crud_dict_data.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ async def get(self, db: AsyncSession, pk: int) -> DictData | None:
2323
"""
2424
return await self.select_model(db, pk, load_strategies={'type': 'noload'})
2525

26+
async def get_by_type_code(self, db: AsyncSession, type_code: str) -> Sequence[DictData]:
27+
"""
28+
通过字典类型编码获取字典数据
29+
30+
:param db: 数据库会话
31+
:param type_code: 字典类型编码
32+
:return:
33+
"""
34+
return await self.select_models_order(
35+
db, sort_columns='sort', sort_orders='desc', type_code=type_code, load_strategies={'type': 'noload'}
36+
)
37+
2638
async def get_all(self, db: AsyncSession) -> Sequence[DictData]:
2739
"""
2840
获取所有字典数据

backend/plugin/dict/crud/crud_dict_type.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@ async def get_all(self, db: AsyncSession) -> Sequence[DictType]:
3232
"""
3333
return await self.select_models(db, load_strategies={'datas': 'noload'})
3434

35-
async def get_list(self, *, name: str | None, code: str | None, status: int | None) -> Select:
35+
async def get_list(self, *, name: str | None, code: str | None) -> Select:
3636
"""
3737
获取字典类型列表
3838
3939
:param name: 字典类型名称
4040
:param code: 字典类型编码
41-
:param status: 字典状态
4241
:return:
4342
"""
4443
filters = {}
@@ -47,8 +46,6 @@ async def get_list(self, *, name: str | None, code: str | None, status: int | No
4746
filters['name__like'] = f'%{name}%'
4847
if code is not None:
4948
filters['code__like'] = f'%{code}%'
50-
if status is not None:
51-
filters['status'] = status
5249

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

backend/plugin/dict/model/dict_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class DictData(Base):
2424
type_code: Mapped[str] = mapped_column(String(32), comment='对应的字典类型编码')
2525
label: Mapped[str] = mapped_column(String(32), comment='字典标签')
2626
value: Mapped[str] = mapped_column(String(32), comment='字典值')
27+
color: Mapped[str | None] = mapped_column(String(32), default=None, comment='标签颜色')
2728
sort: Mapped[int] = mapped_column(default=0, comment='排序')
2829
status: Mapped[int] = mapped_column(default=1, comment='状态(0停用 1正常)')
2930
remark: Mapped[str | None] = mapped_column(

backend/plugin/dict/model/dict_type.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class DictType(Base):
2323
id: Mapped[id_key] = mapped_column(init=False)
2424
name: Mapped[str] = mapped_column(String(32), comment='字典类型名称')
2525
code: Mapped[str] = mapped_column(String(32), unique=True, comment='字典类型编码')
26-
status: Mapped[int] = mapped_column(default=1, comment='状态(0停用 1正常)')
2726
remark: Mapped[str | None] = mapped_column(
2827
LONGTEXT().with_variant(TEXT, 'postgresql'), default=None, comment='备注'
2928
)

backend/plugin/dict/plugin.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[plugin]
22
summary = '数据字典'
3-
version = '0.0.5'
3+
version = '0.0.6'
44
description = '通常用于约束前端工程数据展示'
55
author = 'wu-clan'
66

backend/plugin/dict/schema/dict_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class DictDataSchemaBase(SchemaBase):
1414
type_id: int = Field(description='字典类型 ID')
1515
label: str = Field(description='字典标签')
1616
value: str = Field(description='字典值')
17+
color: str | None = Field(None, description='标签颜色')
1718
sort: int = Field(description='排序')
1819
status: StatusType = Field(description='状态')
1920
remark: str | None = Field(None, description='备注')

backend/plugin/dict/schema/dict_type.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from pydantic import ConfigDict, Field
66

7-
from backend.common.enums import StatusType
87
from backend.common.schema import SchemaBase
98

109

@@ -13,7 +12,6 @@ class DictTypeSchemaBase(SchemaBase):
1312

1413
name: str = Field(description='字典名称')
1514
code: str = Field(description='字典编码')
16-
status: StatusType = Field(description='状态')
1715
remark: str | None = Field(None, description='备注')
1816

1917

backend/plugin/dict/service/dict_data_service.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ async def get(*, pk: int) -> DictData:
2929
raise errors.NotFoundError(msg='字典数据不存在')
3030
return dict_data
3131

32+
@staticmethod
33+
async def get_by_type_code(*, code: str) -> Sequence[DictData]:
34+
"""
35+
获取字典数据详情
36+
37+
:param code: 字典类型编码
38+
:return:
39+
"""
40+
async with async_db_session() as db:
41+
dict_datas = await dict_data_dao.get_by_type_code(db, code)
42+
if not dict_datas:
43+
raise errors.NotFoundError(msg='字典数据不存在')
44+
return dict_datas
45+
3246
@staticmethod
3347
async def get_all() -> Sequence[DictData]:
3448
async with async_db_session() as db:

0 commit comments

Comments
 (0)