feat: 完善员工门店软删除与密码管理
This commit is contained in:
@@ -75,14 +75,14 @@ const PERMISSION_DEFINITIONS: PermissionDefinition[] = [
|
||||
{
|
||||
code: PERMISSIONS.STORE_VIEW,
|
||||
title: "查看门店",
|
||||
description: "查看门店列表、门店详情和门店下拉选项。",
|
||||
description: "查看门店列表、门店详情、门店下员工和门店下拉选项。",
|
||||
groupKey: "stores",
|
||||
groupTitle: "门店管理",
|
||||
},
|
||||
{
|
||||
code: PERMISSIONS.STORE_MANAGE,
|
||||
title: "管理门店",
|
||||
description: "新增、编辑、停用和删除门店。",
|
||||
description: "新增、编辑、停用和软删除门店。",
|
||||
groupKey: "stores",
|
||||
groupTitle: "门店管理",
|
||||
},
|
||||
@@ -96,7 +96,7 @@ const PERMISSION_DEFINITIONS: PermissionDefinition[] = [
|
||||
{
|
||||
code: PERMISSIONS.ROLE_MANAGE,
|
||||
title: "管理角色",
|
||||
description: "新增、编辑和删除非系统角色。",
|
||||
description: "新增、编辑和软删除非系统角色。",
|
||||
groupKey: "roles",
|
||||
groupTitle: "角色管理",
|
||||
},
|
||||
@@ -117,7 +117,7 @@ const PERMISSION_DEFINITIONS: PermissionDefinition[] = [
|
||||
{
|
||||
code: PERMISSIONS.EMPLOYEE_MANAGE,
|
||||
title: "管理员工",
|
||||
description: "新增、编辑、启停和删除员工,并维护员工角色。",
|
||||
description: "新增、编辑、启停、移除、软删除员工,并维护员工角色和密码。",
|
||||
groupKey: "employees",
|
||||
groupTitle: "员工管理",
|
||||
},
|
||||
|
||||
@@ -82,7 +82,9 @@ export const permissionRepository = {
|
||||
r.is_system,
|
||||
rp.permission_code
|
||||
FROM roles r
|
||||
LEFT JOIN role_permissions rp ON rp.role_id = r.id
|
||||
LEFT JOIN role_permissions rp
|
||||
ON rp.role_id = r.id AND rp.deleted_at IS NULL
|
||||
WHERE r.deleted_at IS NULL
|
||||
ORDER BY r.id ASC, rp.permission_code ASC
|
||||
`,
|
||||
);
|
||||
@@ -104,8 +106,10 @@ export const permissionRepository = {
|
||||
r.is_system,
|
||||
rp.permission_code
|
||||
FROM roles r
|
||||
LEFT JOIN role_permissions rp ON rp.role_id = r.id
|
||||
LEFT JOIN role_permissions rp
|
||||
ON rp.role_id = r.id AND rp.deleted_at IS NULL
|
||||
WHERE r.id = ?
|
||||
AND r.deleted_at IS NULL
|
||||
ORDER BY rp.permission_code ASC
|
||||
`,
|
||||
[roleId],
|
||||
@@ -126,6 +130,8 @@ export const permissionRepository = {
|
||||
FROM role_permissions rp
|
||||
INNER JOIN roles r ON r.id = rp.role_id
|
||||
WHERE r.code IN (${placeholders})
|
||||
AND r.deleted_at IS NULL
|
||||
AND rp.deleted_at IS NULL
|
||||
ORDER BY rp.permission_code ASC
|
||||
`,
|
||||
roleCodes,
|
||||
@@ -139,7 +145,14 @@ export const permissionRepository = {
|
||||
permissionCodes: string[],
|
||||
db: DbExecutor = pool,
|
||||
): Promise<void> {
|
||||
await db.execute("DELETE FROM role_permissions WHERE role_id = ?", [roleId]);
|
||||
await db.execute(
|
||||
`
|
||||
UPDATE role_permissions
|
||||
SET deleted_at = CURRENT_TIMESTAMP(3)
|
||||
WHERE role_id = ? AND deleted_at IS NULL
|
||||
`,
|
||||
[roleId],
|
||||
);
|
||||
|
||||
if (permissionCodes.length === 0) {
|
||||
return;
|
||||
@@ -149,6 +162,9 @@ export const permissionRepository = {
|
||||
`
|
||||
INSERT INTO role_permissions (role_id, permission_code)
|
||||
VALUES ${permissionCodes.map(() => "(?, ?)").join(", ")}
|
||||
ON DUPLICATE KEY UPDATE
|
||||
deleted_at = NULL,
|
||||
created_at = CURRENT_TIMESTAMP(3)
|
||||
`,
|
||||
permissionCodes.flatMap((permissionCode) => [roleId, permissionCode]),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user