seed-s8-business-roles.sql 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. -- =============================================================================
  2. -- seed-s8-business-roles.sql
  3. -- S8-SEED-DURABILITY-1: idempotent seed for S8 business roles
  4. --
  5. -- Purpose: Restore S8 business SysRole entries and related config that
  6. -- S8SysRoleSeedData / S8RolePermissionSeedData would normally insert
  7. -- when EnableIncreSeed=true. This script is safe to run repeatedly.
  8. --
  9. -- Root cause: EnableIncreSeed=false in Database.json (intentional, avoids
  10. -- unintended re-seed of other modules on restart).
  11. --
  12. -- Usage:
  13. -- mysql -h <host> -P 3306 -u <user> -p<pwd> <db> < seed-s8-business-roles.sql
  14. --
  15. -- Idempotency: INSERT IGNORE skips rows with duplicate primary keys.
  16. -- No DROP / TRUNCATE / DELETE on any table.
  17. --
  18. -- Targets (dev DB): aidopdev
  19. -- Last updated: 2026-04-29
  20. -- =============================================================================
  21. -- ---------------------------------------------------------------------------
  22. -- Section 1: S8 business roles → SysRole
  23. -- Matches S8SysRoleSeedData.HasData() exactly.
  24. -- TenantId = 1300000000001 (SqlSugarConst.DefaultTenantId)
  25. -- DataScope = 4 (DataScopeEnum.Self)
  26. -- Status = 1 (StatusEnum.Enable)
  27. -- ---------------------------------------------------------------------------
  28. INSERT IGNORE INTO SysRole
  29. (Id, Name, Code, OrderNo, DataScope, Remark, Status, TenantId, CreateTime)
  30. VALUES
  31. (1329908000101, '订单计划员', 'ROLE_ORDER_PLANNER', 800, 4, 'S8 业务角色(异常协同承接)', 1, 1300000000001, '2026-04-18 00:00:00'),
  32. (1329908000102, '生产计划员', 'ROLE_PRODUCTION_PLANNER', 801, 4, 'S8 业务角色(异常协同承接)', 1, 1300000000001, '2026-04-18 00:00:00'),
  33. (1329908000103, '采购员', 'ROLE_PURCHASER', 802, 4, 'S8 业务角色(异常协同承接)', 1, 1300000000001, '2026-04-18 00:00:00'),
  34. (1329908000104, '仓库收货员', 'ROLE_WH_INBOUND', 803, 4, 'S8 业务角色(异常协同承接)', 1, 1300000000001, '2026-04-18 00:00:00'),
  35. (1329908000105, '仓库发货员', 'ROLE_WH_OUTBOUND', 804, 4, 'S8 业务角色(异常协同承接)', 1, 1300000000001, '2026-04-18 00:00:00'),
  36. (1329908000106, '质检员', 'ROLE_QC', 805, 4, 'S8 业务角色(异常协同承接)', 1, 1300000000001, '2026-04-18 00:00:00'),
  37. (1329908000107, '设备维修员', 'ROLE_EQUIP_MAINT', 806, 4, 'S8 业务角色(异常协同承接)', 1, 1300000000001, '2026-04-18 00:00:00');
  38. SELECT CONCAT('SysRole inserted: ', ROW_COUNT()) AS result;
  39. -- ---------------------------------------------------------------------------
  40. -- Section 2: S8 role permission baseline → ado_s8_role_permission_config
  41. -- Matches S8RolePermissionSeedData.HasData() exactly.
  42. -- TenantId=0 / FactoryId=0 = global baseline (not tenant-scoped).
  43. -- ---------------------------------------------------------------------------
  44. INSERT IGNORE INTO ado_s8_role_permission_config
  45. (id, tenant_id, factory_id, role_code, permission_codes, created_at)
  46. VALUES
  47. (1329908000001, 0, 0, 'ROLE_ORDER_PLANNER', 's8:exception:read,s8:exception:assign', '2026-04-18 00:00:00'),
  48. (1329908000002, 0, 0, 'ROLE_PRODUCTION_PLANNER', 's8:exception:read,s8:exception:assign', '2026-04-18 00:00:00'),
  49. (1329908000003, 0, 0, 'ROLE_PURCHASER', 's8:exception:read,s8:exception:assign', '2026-04-18 00:00:00'),
  50. (1329908000004, 0, 0, 'ROLE_WH_INBOUND', 's8:exception:read,s8:exception:assign', '2026-04-18 00:00:00'),
  51. (1329908000005, 0, 0, 'ROLE_WH_OUTBOUND', 's8:exception:read,s8:exception:assign', '2026-04-18 00:00:00'),
  52. (1329908000006, 0, 0, 'ROLE_QC', 's8:exception:read,s8:exception:assign', '2026-04-18 00:00:00'),
  53. (1329908000007, 0, 0, 'ROLE_EQUIP_MAINT', 's8:exception:read,s8:exception:assign', '2026-04-18 00:00:00');
  54. SELECT CONCAT('S8RolePermissionConfig inserted: ', ROW_COUNT()) AS result;
  55. -- ---------------------------------------------------------------------------
  56. -- Section 3: S8 business role → test user bindings → SysUserRole
  57. -- Demo01 UserId=1300000000117 (Account='Demo01')
  58. -- Demo02 UserId=789819678195781 (Account='Demo02')
  59. -- Strategy: Demo01 → planning/purchasing/warehouse; Demo02 → production/QC/maintenance
  60. -- All 7 roles must resolve to ≥1 userId for notification chain to work.
  61. -- ---------------------------------------------------------------------------
  62. INSERT IGNORE INTO SysUserRole (Id, UserId, RoleId)
  63. VALUES
  64. (1329909000001, 1300000000117, 1329908000101), -- Demo01 → ROLE_ORDER_PLANNER
  65. (1329909000002, 789819678195781, 1329908000102), -- Demo02 → ROLE_PRODUCTION_PLANNER
  66. (1329909000003, 1300000000117, 1329908000103), -- Demo01 → ROLE_PURCHASER
  67. (1329909000004, 1300000000117, 1329908000104), -- Demo01 → ROLE_WH_INBOUND
  68. (1329909000005, 1300000000117, 1329908000105), -- Demo01 → ROLE_WH_OUTBOUND
  69. (1329909000006, 789819678195781, 1329908000106), -- Demo02 → ROLE_QC
  70. (1329909000007, 789819678195781, 1329908000107); -- Demo02 → ROLE_EQUIP_MAINT
  71. SELECT CONCAT('SysUserRole (S8 role bindings) inserted: ', ROW_COUNT()) AS result;
  72. -- ---------------------------------------------------------------------------
  73. -- Section 4: notification_layer zero-datetime guard
  74. -- ado_s8_notification_layer.created_at is NOT NULL with no default.
  75. -- If rows exist with '0000-00-00 00:00:00', SqlSugar DateTime binding fails.
  76. -- Fix any zero-date rows (safe: only affects layers that already have bad data).
  77. -- ---------------------------------------------------------------------------
  78. -- YEAR(created_at)=0 avoids the '0000-00-00' literal which MySQL strict mode rejects.
  79. UPDATE ado_s8_notification_layer
  80. SET created_at = '2026-04-29 00:00:00'
  81. WHERE YEAR(created_at) = 0;
  82. SELECT CONCAT('notification_layer zero-date fixed: ', ROW_COUNT()) AS result;