# Partner Type Role Sync Implementation Plan > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. **Goal:** Ensure partner accounts automatically receive the enabled system role matching their partner type whenever user permissions are loaded. **Architecture:** Add a focused system-service component that resolves the current partner type through the existing charging-pile Feign client and synchronizes only the three built-in type roles in `sys_user_role`. Call it before login/current-user permissions are calculated, then reload the user so its role collection and menu permissions reflect the synchronized database state. **Tech Stack:** Java 8, Spring Boot, MyBatis-Plus, OpenFeign, JUnit 5, Mockito ## Global Constraints - Partner type `1` maps to role key `independent_partner`. - Partner type `2` maps to role key `site_owner`. - Partner type `3` maps to role key `service_provider`. - Preserve roles outside these three built-in type roles. - Remove stale built-in type roles when the partner type changes. - Do not modify unrelated existing workspace changes. --- ### Task 1: Partner type role synchronizer **Files:** - Create: `ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/PartnerTypeRoleService.java` - Test: `ruoyi-modules/ruoyi-system/src/test/java/com/ruoyi/system/service/PartnerTypeRoleServiceTest.java` **Interfaces:** - Consumes: `SiteClient.getPartnerR(Integer)`, `ISysRoleService`, and `ISysUserRoleService`. - Produces: `void synchronize(SysUser user)`. - [x] **Step 1: Write failing tests for all three mappings, custom-role preservation, stale built-in-role removal, non-partner bypass, and missing-role failure.** - [x] **Step 2: Run `mvn -pl ruoyi-modules/ruoyi-system -am -Dtest=PartnerTypeRoleServiceTest -Dsurefire.failIfNoSpecifiedTests=false test` and verify the new tests fail before implementation.** - [x] **Step 3: Implement role-key mapping and idempotent `sys_user_role` synchronization.** - [x] **Step 4: Run the focused test and verify it passes.** ### Task 2: Permission-loading integration **Files:** - Modify: `ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java` - Test: `ruoyi-modules/ruoyi-system/src/test/java/com/ruoyi/system/service/PartnerTypeRoleServiceTest.java` **Interfaces:** - Consumes: `PartnerTypeRoleService.synchronize(SysUser)`. - Produces: login and current-user responses whose roles and permissions include the matching partner-type role. - [x] **Step 1: Invoke synchronization in both `/user/info/{username}` and `/user/getInfo` before permission calculation.** - [x] **Step 2: Reload `SysUser` after synchronization so `SysUser.roles` is current.** - [x] **Step 3: Run the focused test and compile the system module.** - [x] **Step 4: Review the diff to confirm unrelated working-tree changes remain untouched.**