Skip to content

Commit c84f065

Browse files
authored
Update the dict pagination query parameters (#689)
* Update the dict pagination query parameters * Update the dict pagination query parameters * Update version
1 parent a2902bd commit c84f065

File tree

10 files changed

+140
-128
lines changed

10 files changed

+140
-128
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
CreateDictDataParam,
1515
DeleteDictDataParam,
1616
GetDictDataDetail,
17-
GetDictDataWithRelation,
1817
UpdateDictDataParam,
1918
)
2019
from backend.plugin.dict.service.dict_data_service import dict_data_service
@@ -31,7 +30,7 @@ async def get_all_dict_datas() -> ResponseSchemaModel[list[GetDictDataDetail]]:
3130
@router.get('/{pk}', summary='获取字典数据详情', dependencies=[DependsJwtAuth])
3231
async def get_dict_data(
3332
pk: Annotated[int, Path(description='字典数据 ID')],
34-
) -> ResponseSchemaModel[GetDictDataWithRelation]:
33+
) -> ResponseSchemaModel[GetDictDataDetail]:
3534
data = await dict_data_service.get(pk=pk)
3635
return response_base.success(data=data)
3736

@@ -46,11 +45,15 @@ async def get_dict_data(
4645
)
4746
async def get_dict_datas_paged(
4847
db: CurrentSession,
48+
type_code: Annotated[str | None, Query(description='字典类型编码')] = None,
4949
label: Annotated[str | None, Query(description='字典数据标签')] = None,
5050
value: Annotated[str | None, Query(description='字典数据键值')] = None,
5151
status: Annotated[int | None, Query(description='状态')] = None,
52+
type_id: Annotated[int | None, Query(description='字典类型 ID')] = None,
5253
) -> ResponseSchemaModel[PageData[GetDictDataDetail]]:
53-
dict_data_select = await dict_data_service.get_select(label=label, value=value, status=status)
54+
dict_data_select = await dict_data_service.get_select(
55+
type_code=type_code, label=label, value=value, status=status, type_id=type_id
56+
)
5457
page_data = await paging_data(db, dict_data_select)
5558
return response_base.success(data=page_data)
5659

backend/plugin/dict/crud/crud_dict_data.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async def get(self, db: AsyncSession, pk: int) -> DictData | None:
2121
:param pk: 字典数据 ID
2222
:return:
2323
"""
24-
return await self.select_model(db, pk)
24+
return await self.select_model(db, pk, load_strategies={'type': 'noload'})
2525

2626
async def get_all(self, db: AsyncSession) -> Sequence[DictData]:
2727
"""
@@ -32,23 +32,31 @@ async def get_all(self, db: AsyncSession) -> Sequence[DictData]:
3232
"""
3333
return await self.select_models(db, load_strategies={'type': 'noload'})
3434

35-
async def get_list(self, label: str | None, value: str | None, status: int | None) -> Select:
35+
async def get_list(
36+
self, type_code: str | None, label: str | None, value: str | None, status: int | None, type_id: int | None
37+
) -> Select:
3638
"""
3739
获取字典数据列表
3840
41+
:param type_code: 字典类型编码
3942
:param label: 字典数据标签
4043
:param value: 字典数据键值
4144
:param status: 字典状态
45+
:param type_id: 字典类型 ID
4246
:return:
4347
"""
4448
filters = {}
4549

50+
if type_code is not None:
51+
filters['type_code'] = type_code
4652
if label is not None:
4753
filters['label__like'] = f'%{label}%'
4854
if value is not None:
4955
filters['value__like'] = f'%{value}%'
5056
if status is not None:
5157
filters['status'] = status
58+
if type_id is not None:
59+
filters['type_id'] = type_id
5260

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

backend/plugin/dict/model/dict_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class DictData(Base):
2121
__tablename__ = 'sys_dict_data'
2222

2323
id: Mapped[id_key] = mapped_column(init=False)
24+
type_code: Mapped[str] = mapped_column(String(32), comment='对应的字典类型编码')
2425
label: Mapped[str] = mapped_column(String(32), comment='字典标签')
2526
value: Mapped[str] = mapped_column(String(32), comment='字典值')
2627
sort: Mapped[int] = mapped_column(default=0, comment='排序')

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.3'
3+
version = '0.0.4'
44
description = '通常用于约束前端工程数据展示'
55
author = 'wu-clan'
66

backend/plugin/dict/schema/dict_data.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
from backend.common.enums import StatusType
88
from backend.common.schema import SchemaBase
9-
from backend.plugin.dict.schema.dict_type import GetDictTypeDetail
109

1110

1211
class DictDataSchemaBase(SchemaBase):
1312
"""字典数据基础模型"""
1413

1514
type_id: int = Field(description='字典类型 ID')
15+
type_code: str = Field(description='字典类型编码')
1616
label: str = Field(description='字典标签')
1717
value: str = Field(description='字典值')
1818
sort: int = Field(description='排序')
@@ -42,9 +42,3 @@ class GetDictDataDetail(DictDataSchemaBase):
4242
id: int = Field(description='字典数据 ID')
4343
created_time: datetime = Field(description='创建时间')
4444
updated_time: datetime | None = Field(None, description='更新时间')
45-
46-
47-
class GetDictDataWithRelation(DictDataSchemaBase):
48-
"""字典数据关联详情"""
49-
50-
type: GetDictTypeDetail | None = Field(None, description='字典类型信息')

backend/plugin/dict/service/dict_data_service.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async def get(*, pk: int) -> DictData:
2424
:return:
2525
"""
2626
async with async_db_session() as db:
27-
dict_data = await dict_data_dao.get_with_relation(db, pk)
27+
dict_data = await dict_data_dao.get(db, pk)
2828
if not dict_data:
2929
raise errors.NotFoundError(msg='字典数据不存在')
3030
return dict_data
@@ -36,16 +36,22 @@ async def get_all() -> Sequence[DictData]:
3636
return dict_datas
3737

3838
@staticmethod
39-
async def get_select(*, label: str | None, value: str | None, status: int | None) -> Select:
39+
async def get_select(
40+
*, type_code: str | None, label: str | None, value: str | None, status: int | None, type_id: int | None
41+
) -> Select:
4042
"""
4143
获取字典数据列表查询条件
4244
45+
:param type_code: 字典类型编码
4346
:param label: 字典数据标签
4447
:param value: 字典数据键值
4548
:param status: 状态
49+
:param type_id: 字典类型 ID
4650
:return:
4751
"""
48-
return await dict_data_dao.get_list(label=label, value=value, status=status)
52+
return await dict_data_dao.get_list(
53+
type_code=type_code, label=label, value=value, status=status, type_id=type_id
54+
)
4955

5056
@staticmethod
5157
async def create(*, obj: CreateDictDataParam) -> None:

backend/plugin/dict/sql/mysql/init_snowflake_test_data.sql

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@ values
1010
(2048602512755392512, '菜单显示', 'sys_menu_display', 1, '菜单是否显示', now(), null),
1111
(2048602512818307072, '菜单缓存', 'sys_menu_cache', 1, '菜单是否缓存', now(), null);
1212

13-
insert into sys_dict_data (id, label, value, sort, status, remark, type_id, created_time, updated_time)
13+
insert into sys_dict_data (id, type_code, label, value, sort, status, remark, type_id, created_time, updated_time)
1414
values
15-
(2048602512881221632, '停用', 0, 1, 1, '系统停用状态', 2048602512340156416, now(), null),
16-
(2048602512948330496, '正常', 1, 2, 1, '系统正常状态', 2048602512340156416, now(), null),
17-
(2048602513015439360, '目录', 0, 1, 1, '菜单目录类型', 2048602512369516544, now(), null),
18-
(2048602513078353920, '菜单', 1, 2, 1, '普通菜单类型', 2048602512369516544, now(), null),
19-
(2048602513128685568, '按钮', 2, 3, 1, '按钮权限类型', 2048602512369516544, now(), null),
20-
(2048602513174822912, '内嵌', 3, 4, 1, '内嵌页面类型', 2048602512369516544, now(), null),
21-
(2048602513241931776, '外链', 4, 5, 1, '外部链接类型', 2048602512369516544, now(), null),
22-
(2048602513292263424, '失败', 0, 1, 1, '登录失败状态', 2048602512432431104, now(), null),
23-
(2048602513359372288, '成功', 1, 2, 1, '登录成功状态', 2048602512432431104, now(), null),
24-
(2048602513422286848, 'AND', 0, 1, 1, '逻辑与运算符', 2048602512495345664, now(), null),
25-
(2048602513476812800, 'OR', 1, 2, 1, '逻辑或运算符', 2048602512495345664, now(), null),
26-
(2048602513543921664, '等于(==)', 0, 1, 1, '等于比较表达式', 2048602512549871616, now(), null),
27-
(2048602513590059008, '不等于(!=)', 1, 2, 1, '不等于比较表达式', 2048602512549871616, now(), null),
28-
(2048602513657167872, '大于(>)', 2, 3, 1, '大于比较表达式', 2048602512549871616, now(), null),
29-
(2048602513720082432, '大于等于(>=)', 3, 4, 1, '大于等于比较表达式', 2048602512549871616, now(), null),
30-
(2048602513782996992, '小于(<)', 4, 5, 1, '小于比较表达式', 2048602512549871616, now(), null),
31-
(2048602513850105856, '小于等于(<=)', 5, 6, 1, '小于等于比较表达式', 2048602512549871616, now(), null),
32-
(2048602513917214720, '包含(in)', 6, 7, 1, '包含表达式', 2048602512549871616, now(), null),
33-
(2048602513984323584, '不包含(not in)', 7, 8, 1, '不包含表达式', 2048602512549871616, now(), null),
34-
(2048602514051432448, '', 0, 1, 1, '不是前端参数配置', 2048602512616980480, now(), null),
35-
(2048602514118541312, '', 1, 2, 1, '是前端参数配置', 2048602512616980480, now(), null),
36-
(2048602514168872960, '', 0, 1, 1, '不进行数据权限过滤', 2048602512692477952, now(), null),
37-
(2048602514231787520, '', 1, 2, 1, '进行数据权限过滤', 2048602512692477952, now(), null),
38-
(2048602514303090688, '隐藏', 0, 1, 1, '菜单隐藏', 2048602512755392512, now(), null),
39-
(2048602514366005248, '显示', 1, 2, 1, '菜单显示', 2048602512755392512, now(), null),
40-
(2048602514433114112, '不缓存', 0, 1, 1, '菜单不缓存', 2048602512818307072, now(), null),
41-
(2048602514500222976, '缓存', 1, 2, 1, '菜单缓存', 2048602512818307072, now(), null);
15+
(2048602512881221632, 'sys_status', '停用', '0', 1, 1, '系统停用状态', 2048602512340156416, now(), null),
16+
(2048602512948330496, 'sys_status', '正常', '1', 2, 1, '系统正常状态', 2048602512340156416, now(), null),
17+
(2048602513015439360, 'sys_menu_type', '目录', '0', 1, 1, '菜单目录类型', 2048602512369516544, now(), null),
18+
(2048602513078353920, 'sys_menu_type', '菜单', '1', 2, 1, '普通菜单类型', 2048602512369516544, now(), null),
19+
(2048602513128685568, 'sys_menu_type', '按钮', '2', 3, 1, '按钮权限类型', 2048602512369516544, now(), null),
20+
(2048602513174822912, 'sys_menu_type', '内嵌', '3', 4, 1, '内嵌页面类型', 2048602512369516544, now(), null),
21+
(2048602513241931776, 'sys_menu_type', '外链', '4', 5, 1, '外部链接类型', 2048602512369516544, now(), null),
22+
(2048602513292263424, 'sys_login_status', '失败', '0', 1, 1, '登录失败状态', 2048602512432431104, now(), null),
23+
(2048602513359372288, 'sys_login_status', '成功', '1', 2, 1, '登录成功状态', 2048602512432431104, now(), null),
24+
(2048602513422286848, 'sys_data_rule_operator', 'AND', '0', 1, 1, '逻辑与运算符', 2048602512495345664, now(), null),
25+
(2048602513476812800, 'sys_data_rule_operator', 'OR', '1', 2, 1, '逻辑或运算符', 2048602512495345664, now(), null),
26+
(2048602513543921664, 'sys_data_rule_expression', '等于(==)', '0', 1, 1, '等于比较表达式', 2048602512549871616, now(), null),
27+
(2048602513590059008, 'sys_data_rule_expression', '不等于(!=)', '1', 2, 1, '不等于比较表达式', 2048602512549871616, now(), null),
28+
(2048602513657167872, 'sys_data_rule_expression', '大于(>)', '2', 3, 1, '大于比较表达式', 2048602512549871616, now(), null),
29+
(2048602513720082432, 'sys_data_rule_expression', '大于等于(>=)', '3', 4, 1, '大于等于比较表达式', 2048602512549871616, now(), null),
30+
(2048602513782996992, 'sys_data_rule_expression', '小于(<)', '4', 5, 1, '小于比较表达式', 2048602512549871616, now(), null),
31+
(2048602513850105856, 'sys_data_rule_expression', '小于等于(<=)', '5', 6, 1, '小于等于比较表达式', 2048602512549871616, now(), null),
32+
(2048602513917214720, 'sys_data_rule_expression', '包含(in)', '6', 7, 1, '包含表达式', 2048602512549871616, now(), null),
33+
(2048602513984323584, 'sys_data_rule_expression', '不包含(not in)', '7', 8, 1, '不包含表达式', 2048602512549871616, now(), null),
34+
(2048602514051432448, 'sys_frontend_config', '', '0', 1, 1, '不是前端参数配置', 2048602512616980480, now(), null),
35+
(2048602514118541312, 'sys_frontend_config', '', '1', 2, 1, '是前端参数配置', 2048602512616980480, now(), null),
36+
(2048602514168872960, 'sys_data_permission', '', '0', 1, 1, '不进行数据权限过滤', 2048602512692477952, now(), null),
37+
(2048602514231787520, 'sys_data_permission', '', '1', 2, 1, '进行数据权限过滤', 2048602512692477952, now(), null),
38+
(2048602514303090688, 'sys_menu_display', '隐藏', '0', 1, 1, '菜单隐藏', 2048602512755392512, now(), null),
39+
(2048602514366005248, 'sys_menu_display', '显示', '1', 2, 1, '菜单显示', 2048602512755392512, now(), null),
40+
(2048602514433114112, 'sys_menu_cache', '不缓存', '0', 1, 1, '菜单不缓存', 2048602512818307072, now(), null),
41+
(2048602514500222976, 'sys_menu_cache', '缓存', '1', 2, 1, '菜单缓存', 2048602512818307072, now(), null);

backend/plugin/dict/sql/mysql/init_test_data.sql

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@ values
1010
(8, '菜单显示', 'sys_menu_display', 1, '菜单是否显示', now(), null),
1111
(9, '菜单缓存', 'sys_menu_cache', 1, '菜单是否缓存', now(), null);
1212

13-
insert into sys_dict_data (id, label, value, sort, status, remark, type_id, created_time, updated_time)
13+
insert into sys_dict_data (id, type_code, label, value, sort, status, remark, type_id, created_time, updated_time)
1414
values
15-
(1, '停用', 0, 1, 1, '系统停用状态', 1, now(), null),
16-
(2, '正常', 1, 2, 1, '系统正常状态', 1, now(), null),
17-
(3, '目录', 0, 1, 1, '菜单目录类型', 2, now(), null),
18-
(4, '菜单', 1, 2, 1, '普通菜单类型', 2, now(), null),
19-
(5, '按钮', 2, 3, 1, '按钮权限类型', 2, now(), null),
20-
(6, '内嵌', 3, 4, 1, '内嵌页面类型', 2, now(), null),
21-
(7, '外链', 4, 5, 1, '外部链接类型', 2, now(), null),
22-
(8, '失败', 0, 1, 1, '登录失败状态', 3, now(), null),
23-
(9, '成功', 1, 2, 1, '登录成功状态', 3, now(), null),
24-
(10, 'AND', 0, 1, 1, '逻辑与运算符', 4, now(), null),
25-
(11, 'OR', 1, 2, 1, '逻辑或运算符', 4, now(), null),
26-
(12, '等于(==)', 0, 1, 1, '等于比较表达式', 5, now(), null),
27-
(13, '不等于(!=)', 1, 2, 1, '不等于比较表达式', 5, now(), null),
28-
(14, '大于(>)', 2, 3, 1, '大于比较表达式', 5, now(), null),
29-
(15, '大于等于(>=)', 3, 4, 1, '大于等于比较表达式', 5, now(), null),
30-
(16, '小于(<)', 4, 5, 1, '小于比较表达式', 5, now(), null),
31-
(17, '小于等于(<=)', 5, 6, 1, '小于等于比较表达式', 5, now(), null),
32-
(18, '包含(in)', 6, 7, 1, '包含表达式', 5, now(), null),
33-
(19, '不包含(not in)', 7, 8, 1, '不包含表达式', 5, now(), null),
34-
(20, '', 0, 1, 1, '不是前端参数配置', 6, now(), null),
35-
(21, '', 1, 2, 1, '是前端参数配置', 6, now(), null),
36-
(22, '', 0, 1, 1, '不进行数据权限过滤', 7, now(), null),
37-
(23, '', 1, 2, 1, '进行数据权限过滤', 7, now(), null),
38-
(24, '隐藏', 0, 1, 1, '菜单隐藏', 8, now(), null),
39-
(25, '显示', 1, 2, 1, '菜单显示', 8, now(), null),
40-
(26, '不缓存', 0, 1, 1, '菜单不缓存', 9, now(), null),
41-
(27, '缓存', 1, 2, 1, '菜单缓存', 9, now(), null);
15+
(1, 'sys_status', '停用', '0', 1, 1, '系统停用状态', 1, now(), null),
16+
(2, 'sys_status', '正常', '1', 2, 1, '系统正常状态', 1, now(), null),
17+
(3, 'sys_menu_type', '目录', '0', 1, 1, '菜单目录类型', 2, now(), null),
18+
(4, 'sys_menu_type', '菜单', '1', 2, 1, '普通菜单类型', 2, now(), null),
19+
(5, 'sys_menu_type', '按钮', '2', 3, 1, '按钮权限类型', 2, now(), null),
20+
(6, 'sys_menu_type', '内嵌', '3', 4, 1, '内嵌页面类型', 2, now(), null),
21+
(7, 'sys_menu_type', '外链', '4', 5, 1, '外部链接类型', 2, now(), null),
22+
(8, 'sys_login_status', '失败', '0', 1, 1, '登录失败状态', 3, now(), null),
23+
(9, 'sys_login_status', '成功', '1', 2, 1, '登录成功状态', 3, now(), null),
24+
(10, 'sys_data_rule_operator', 'AND', '0', 1, 1, '逻辑与运算符', 4, now(), null),
25+
(11, 'sys_data_rule_operator', 'OR', '1', 2, 1, '逻辑或运算符', 4, now(), null),
26+
(12, 'sys_data_rule_expression', '等于(==)', '0', 1, 1, '等于比较表达式', 5, now(), null),
27+
(13, 'sys_data_rule_expression', '不等于(!=)', '1', 2, 1, '不等于比较表达式', 5, now(), null),
28+
(14, 'sys_data_rule_expression', '大于(>)', '2', 3, 1, '大于比较表达式', 5, now(), null),
29+
(15, 'sys_data_rule_expression', '大于等于(>=)', '3', 4, 1, '大于等于比较表达式', 5, now(), null),
30+
(16, 'sys_data_rule_expression', '小于(<)', '4', 5, 1, '小于比较表达式', 5, now(), null),
31+
(17, 'sys_data_rule_expression', '小于等于(<=)', '5', 6, 1, '小于等于比较表达式', 5, now(), null),
32+
(18, 'sys_data_rule_expression', '包含(in)', '6', 7, 1, '包含表达式', 5, now(), null),
33+
(19, 'sys_data_rule_expression', '不包含(not in)', '7', 8, 1, '不包含表达式', 5, now(), null),
34+
(20, 'sys_frontend_config', '', '0', 1, 1, '不是前端参数配置', 6, now(), null),
35+
(21, 'sys_frontend_config', '', '1', 2, 1, '是前端参数配置', 6, now(), null),
36+
(22, 'sys_data_permission', '', '0', 1, 1, '不进行数据权限过滤', 7, now(), null),
37+
(23, 'sys_data_permission', '', '1', 2, 1, '进行数据权限过滤', 7, now(), null),
38+
(24, 'sys_menu_display', '隐藏', '0', 1, 1, '菜单隐藏', 8, now(), null),
39+
(25, 'sys_menu_display', '显示', '1', 2, 1, '菜单显示', 8, now(), null),
40+
(26, 'sys_menu_cache', '不缓存', '0', 1, 1, '菜单不缓存', 9, now(), null),
41+
(27, 'sys_menu_cache', '缓存', '1', 2, 1, '菜单缓存', 9, now(), null);

0 commit comments

Comments
 (0)