mysql。PHP 后台权限管理 模块mysql
背景:订单系统后台权限管理ajax
功能要求:redis
方案:sql
表设计数据库
用户表 dp_system_userjson
字段session |
类型app |
默认值elasticsearch |
备注spa |
id |
int 11 |
not null |
角色id |
|
varchar 64 |
not null |
员工名,写入为员工拥有公司邮箱 |
gid |
int 11 |
not null |
系统 ID |
account |
varchar 32 |
not null |
员工名 |
department_id |
text 多个部门 65,657,8 |
not null |
部门 ID |
is_delete |
boolean |
0 |
是否可用 |
add_time |
int 10 |
not null |
添加时间 |
update_time |
int 10 |
not null |
更新时间 |
append_id |
int 11 |
not null |
添加人ID |
role_id |
text |
not null |
角色id |
部门表 dp_system_department
字段 |
类型 |
默认值 |
备注 |
id |
int 11 |
not null |
部门 id |
department_name |
varchar 64 |
not null |
部门名称 |
parent_id |
int 11 |
0 |
上级部门 id |
add_time |
int 10 |
not null |
添加时间 |
append_id |
int 11 |
not null |
添加人ID |
is_delete |
tinyint |
not null |
是否删除 |
角色表 dp_system_role
字段 |
类型 |
默认值 |
备注 |
id |
int |
not null |
角色id |
role_name |
varchar 100 |
not null |
角色名 |
add_time |
int 10 |
not null |
添加时间 |
append_id |
int 10 |
not null |
添加人ID |
is_delete |
tinyint |
not null |
是否删除 |
常见模型 rbac (rolu based access control ) 基于角色访问控制,由于角色多起来管理不便,因此引用了权限组,部门的概念。部门主要职责就是批量受权
然而开始设置权限就须要一个表来存容许访问的 模块信息与用户信息
模块表 dp_system_template
字段 |
类型 |
默认值 |
备注 |
例子 |
id |
int 11 |
not null |
模块id |
1 |
template_code |
varchar 64 |
not null |
模版code |
order.order_list |
template_name |
varchar 64 |
not null |
模版 名字 |
订单查询列表 |
add_user |
int 11 |
not null |
添加人 |
45 |
last_time |
int 10 |
not null |
修改时间 |
154234657 |
is_delete |
boolean |
not null |
是否可用 |
0 |
容许访问信息表dp_system_permission
字段 |
类型 |
默认值 |
备注 |
id |
int 11 |
not null |
id |
role_id |
int 11 |
not null |
权限ID |
template_id |
int 11 |
not null |
模版id |
模块可能无限增加,方便查询效率高,模块ID与 权限ID 多对多存储。
后来mysql主表日增数据 100,000。经历三个月,数据量到达 9,000,000。业务员2000,每次访问数据,先筛选能够访问的权限店铺,而后 in 范围查询,形成查询压力旁大,解决方案:
案例sql
select * from om_unshipped_order where id in (29765473,,,,,省略4000id)and accountId in(567,,,省略200id)limit 50。
1,备份数据库,一个月备份一次,备份出完结订单涉及的表数据,减小数据库压力。
2,能够作成查询延后,首次告诉已经接受请求请稍后,ajax轮训,监控结果,后台PHP分页运行计算结果后,放入一个文件中,文件内容只含有orderid,一行一个,便于页面读取分页读取数据,二次查询数据库查询出结果,文件名用sessionid,中途查询关系存放到redis,保证计算出正确的文件名,方便获取文件。
3,另一个思路,整合数据到mysql表,用于检索须要得数据,或者放入elasticsearch,计算出咱们的结果。
4,一个思路,若是是spu,这样的查询,经过规则整合成int 整型,查询就仅仅须要取出数字区间,很是快