更新+mock部分

This commit is contained in:
2026-04-16 18:12:09 +08:00
parent d5c06eca28
commit adadb3bf1d
40 changed files with 884 additions and 174 deletions

View File

@@ -0,0 +1,4 @@
package com.k12study.api.auth.dto;
public record RefreshTokenRequest(String refreshToken) {
}

View File

@@ -4,9 +4,9 @@ import java.util.List;
public record AreaNodeDto(
String areaCode,
String parentCode,
String areaName,
String areaLevel,
String provinceCode,
List<AreaNodeDto> children
) {
}

View File

@@ -6,8 +6,11 @@ public record CurrentRouteUserDto(
String userId,
String username,
String displayName,
String adcode,
String tenantId,
String tenantPath,
String deptId,
String deptPath,
List<String> permissionCodes
) {
}

View File

@@ -4,9 +4,12 @@ import java.util.List;
public record DeptNodeDto(
String deptId,
String parentDeptId,
String deptName,
String deptType,
String tenantId,
String adcode,
String tenantPath,
String deptPath,
List<DeptNodeDto> children
) {

View File

@@ -4,10 +4,10 @@ import java.util.List;
public record TenantNodeDto(
String tenantId,
String parentTenantId,
String tenantName,
String tenantType,
String provinceCode,
String areaCode,
String adcode,
String tenantPath,
List<TenantNodeDto> children
) {

View File

@@ -0,0 +1,13 @@
package com.k12study.api.upms.remote;
public final class UpmsApiPaths {
private UpmsApiPaths() {
}
public static final String BASE = "/upms";
public static final String ROUTES = BASE + "/routes";
public static final String USERS_CURRENT = BASE + "/users/current";
public static final String AREAS = BASE + "/areas";
public static final String TENANTS = BASE + "/tenants";
public static final String DEPARTMENTS = BASE + "/departments";
}

View File

@@ -0,0 +1,21 @@
package com.k12study.api.upms.remote;
import com.k12study.api.upms.dto.AreaNodeDto;
import com.k12study.api.upms.dto.CurrentRouteUserDto;
import com.k12study.api.upms.dto.DeptNodeDto;
import com.k12study.api.upms.dto.RouteNodeDto;
import com.k12study.api.upms.dto.TenantNodeDto;
import com.k12study.common.api.response.ApiResponse;
import java.util.List;
public interface UpmsRemoteApi {
ApiResponse<List<RouteNodeDto>> routes();
ApiResponse<CurrentRouteUserDto> currentUser();
ApiResponse<List<AreaNodeDto>> areas();
ApiResponse<List<TenantNodeDto>> tenants();
ApiResponse<List<DeptNodeDto>> departments();
}

View File

@@ -2,15 +2,16 @@ package com.k12study.auth.controller;
import com.k12study.api.auth.dto.CurrentUserResponse;
import com.k12study.api.auth.dto.LoginRequest;
import com.k12study.api.auth.dto.RefreshTokenRequest;
import com.k12study.api.auth.dto.TokenResponse;
import com.k12study.auth.service.AuthService;
import com.k12study.common.api.response.ApiResponse;
import com.k12study.common.web.exception.BizException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@@ -22,17 +23,21 @@ public class AuthController {
this.authService = authService;
}
@PostMapping("/login")
@PostMapping("/tokens")
public ApiResponse<TokenResponse> login(@RequestBody LoginRequest request) {
return ApiResponse.success("登录成功", authService.login(request));
}
@PostMapping("/refresh")
public ApiResponse<TokenResponse> refresh(@RequestParam("refreshToken") String refreshToken) {
@PostMapping("/tokens/refresh")
public ApiResponse<TokenResponse> refresh(@RequestBody RefreshTokenRequest request) {
String refreshToken = request == null ? null : request.refreshToken();
if (refreshToken == null || refreshToken.isBlank()) {
throw new BizException(400, "refreshToken 不能为空");
}
return ApiResponse.success("刷新成功", authService.refresh(refreshToken));
}
@GetMapping("/current-user")
@GetMapping("/users/current")
public ApiResponse<CurrentUserResponse> currentUser(
@RequestHeader(value = "Authorization", required = false) String authorizationHeader) {
return ApiResponse.success(authService.currentUser(authorizationHeader));

View File

@@ -23,6 +23,6 @@ auth:
enabled: true
gateway-mode: true
whitelist:
- /auth/login
- /auth/refresh
- /auth/tokens
- /auth/tokens/refresh
- /actuator/**

View File

@@ -30,8 +30,8 @@ auth:
enabled: true
gateway-mode: false
whitelist:
- /auth/login
- /auth/refresh
- /auth/tokens
- /auth/tokens/refresh
- /actuator/**
ai:

View File

@@ -14,7 +14,11 @@ public class AuthProperties {
private String secret = "k12study-dev-secret-k12study-dev-secret";
private Duration accessTokenTtl = Duration.ofHours(12);
private Duration refreshTokenTtl = Duration.ofDays(7);
private List<String> whitelist = new ArrayList<>(List.of("/actuator/**", "/auth/login", "/auth/refresh"));
private List<String> whitelist = new ArrayList<>(List.of(
"/actuator/**",
"/auth/tokens",
"/auth/tokens/refresh"
));
public boolean isEnabled() {
return enabled;

View File

@@ -29,6 +29,6 @@ management:
auth:
enabled: true
whitelist:
- /api/auth/login
- /api/auth/refresh
- /api/auth/tokens
- /api/auth/tokens/refresh
- /actuator/**

View File

@@ -5,6 +5,7 @@ import com.k12study.api.upms.dto.CurrentRouteUserDto;
import com.k12study.api.upms.dto.DeptNodeDto;
import com.k12study.api.upms.dto.RouteNodeDto;
import com.k12study.api.upms.dto.TenantNodeDto;
import com.k12study.api.upms.remote.UpmsApiPaths;
import com.k12study.common.api.response.ApiResponse;
import com.k12study.upms.service.UpmsQueryService;
import java.util.List;
@@ -13,7 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/upms")
@RequestMapping(UpmsApiPaths.BASE)
public class UpmsController {
private final UpmsQueryService upmsQueryService;
@@ -26,22 +27,22 @@ public class UpmsController {
return ApiResponse.success(upmsQueryService.routes());
}
@GetMapping("/areas/tree")
@GetMapping("/areas")
public ApiResponse<List<AreaNodeDto>> areas() {
return ApiResponse.success(upmsQueryService.areas());
}
@GetMapping("/tenants/tree")
@GetMapping("/tenants")
public ApiResponse<List<TenantNodeDto>> tenants() {
return ApiResponse.success(upmsQueryService.tenants());
}
@GetMapping("/depts/tree")
@GetMapping("/departments")
public ApiResponse<List<DeptNodeDto>> departments() {
return ApiResponse.success(upmsQueryService.departments());
}
@GetMapping("/current-user")
@GetMapping("/users/current")
public ApiResponse<CurrentRouteUserDto> currentUser() {
return ApiResponse.success(upmsQueryService.currentUser());
}

View File

@@ -1,10 +1,12 @@
package com.k12study.upms.domain;
public record SysArea(
String areaCode,
String parentCode,
long id,
long pid,
long adcode,
String areaName,
String areaLevel,
String provinceCode
String areaType,
String areaStatus,
String delFlag
) {
}

View File

@@ -6,6 +6,8 @@ public record SysDept(
String tenantId,
String deptName,
String deptType,
String adcode,
String tenantPath,
String deptPath
) {
}

View File

@@ -5,8 +5,8 @@ public record SysTenant(
String parentTenantId,
String tenantName,
String tenantType,
String provinceCode,
String areaCode,
String tenantPath
String adcode,
String tenantPath,
String status
) {
}

View File

@@ -3,109 +3,17 @@ package com.k12study.upms.service;
import com.k12study.api.upms.dto.AreaNodeDto;
import com.k12study.api.upms.dto.CurrentRouteUserDto;
import com.k12study.api.upms.dto.DeptNodeDto;
import com.k12study.api.upms.dto.LayoutType;
import com.k12study.api.upms.dto.RouteMetaDto;
import com.k12study.api.upms.dto.RouteNodeDto;
import com.k12study.api.upms.dto.TenantNodeDto;
import com.k12study.common.security.context.RequestUserContextHolder;
import java.util.List;
import org.springframework.stereotype.Service;
public interface UpmsQueryService {
List<RouteNodeDto> routes();
@Service
public class UpmsQueryService {
List<AreaNodeDto> areas();
public List<RouteNodeDto> routes() {
return List.of(
new RouteNodeDto(
"dashboard",
"/",
"dashboard",
"dashboard",
LayoutType.SIDEBAR,
new RouteMetaDto("控制台", "layout-dashboard", List.of("dashboard:view"), false),
List.of()
),
new RouteNodeDto(
"tenant-management",
"/tenant",
"tenant-management",
"tenant",
LayoutType.SIDEBAR,
new RouteMetaDto("租户组织", "building-2", List.of("tenant:view"), false),
List.of()
)
);
}
List<TenantNodeDto> tenants();
public List<AreaNodeDto> areas() {
return List.of(
new AreaNodeDto(
"330000",
"浙江省",
"province",
"330000",
List.of(
new AreaNodeDto("330100", "杭州市", "city", "330000", List.of())
)
)
);
}
List<DeptNodeDto> departments();
public List<TenantNodeDto> tenants() {
return List.of(
new TenantNodeDto(
"SCH-HQ",
"K12Study 总校",
"head_school",
"330000",
"330100",
"/SCH-HQ/",
List.of(
new TenantNodeDto(
"SCH-ZJ-HZ-01",
"杭州分校",
"city_school",
"330000",
"330100",
"/SCH-HQ/SCH-ZJ-HZ-01/",
List.of()
)
)
)
);
}
public List<DeptNodeDto> departments() {
return List.of(
new DeptNodeDto(
"DEPT-HQ",
"总校教学部",
"grade",
"SCH-HQ",
"/DEPT-HQ/",
List.of(
new DeptNodeDto(
"DEPT-HQ-MATH",
"数学学科组",
"subject",
"SCH-HQ",
"/DEPT-HQ/DEPT-HQ-MATH/",
List.of()
)
)
)
);
}
public CurrentRouteUserDto currentUser() {
var context = RequestUserContextHolder.get();
return new CurrentRouteUserDto(
context == null ? "U10001" : context.userId(),
context == null ? "admin" : context.username(),
context == null ? "K12Study 管理员" : context.displayName(),
context == null ? "SCH-HQ" : context.tenantId(),
context == null ? "DEPT-HQ-ADMIN" : context.deptId(),
List.of("dashboard:view", "tenant:view", "dept:view")
);
}
CurrentRouteUserDto currentUser();
}

View File

@@ -0,0 +1,132 @@
package com.k12study.upms.service.impl;
import com.k12study.api.upms.dto.AreaNodeDto;
import com.k12study.api.upms.dto.CurrentRouteUserDto;
import com.k12study.api.upms.dto.DeptNodeDto;
import com.k12study.api.upms.dto.LayoutType;
import com.k12study.api.upms.dto.RouteMetaDto;
import com.k12study.api.upms.dto.RouteNodeDto;
import com.k12study.api.upms.dto.TenantNodeDto;
import com.k12study.common.security.context.RequestUserContextHolder;
import com.k12study.upms.service.UpmsQueryService;
import java.util.List;
import org.springframework.stereotype.Service;
@Service
public class UpmsQueryServiceImpl implements UpmsQueryService {
@Override
public List<RouteNodeDto> routes() {
return List.of(
new RouteNodeDto(
"dashboard",
"/",
"dashboard",
"dashboard",
LayoutType.SIDEBAR,
new RouteMetaDto("控制台", "layout-dashboard", List.of("dashboard:view"), false),
List.of()
),
new RouteNodeDto(
"tenant-management",
"/tenant",
"tenant-management",
"tenant",
LayoutType.SIDEBAR,
new RouteMetaDto("租户组织", "building-2", List.of("tenant:view"), false),
List.of()
)
);
}
@Override
public List<AreaNodeDto> areas() {
return List.of(
new AreaNodeDto(
"330000",
"100000",
"浙江省",
"PROVINCE",
List.of(
new AreaNodeDto(
"330100",
"330000",
"杭州市",
"CITY",
List.of()
)
)
)
);
}
@Override
public List<TenantNodeDto> tenants() {
return List.of(
new TenantNodeDto(
"SCH-HQ",
null,
"K12Study 总校",
"HEAD_SCHOOL",
"330100",
"/SCH-HQ/",
List.of(
new TenantNodeDto(
"SCH-ZJ-HZ-01",
"SCH-HQ",
"杭州分校",
"CITY_SCHOOL",
"330100",
"/SCH-HQ/SCH-ZJ-HZ-01/",
List.of()
)
)
)
);
}
@Override
public List<DeptNodeDto> departments() {
return List.of(
new DeptNodeDto(
"DEPT-HQ",
null,
"总校教学部",
"GRADE",
"SCH-HQ",
"330100",
"/SCH-HQ/",
"/DEPT-HQ/",
List.of(
new DeptNodeDto(
"DEPT-HQ-MATH",
"DEPT-HQ",
"数学学科组",
"SUBJECT",
"SCH-HQ",
"330100",
"/SCH-HQ/",
"/DEPT-HQ/DEPT-HQ-MATH/",
List.of()
)
)
)
);
}
@Override
public CurrentRouteUserDto currentUser() {
var context = RequestUserContextHolder.get();
return new CurrentRouteUserDto(
context == null ? "U10001" : context.userId(),
context == null ? "admin" : context.username(),
context == null ? "K12Study 管理员" : context.displayName(),
"330100",
context == null ? "SCH-HQ" : context.tenantId(),
"/SCH-HQ/",
context == null ? "DEPT-HQ-ADMIN" : context.deptId(),
"/DEPT-HQ/DEPT-HQ-ADMIN/",
List.of("dashboard:view", "tenant:view", "dept:view")
);
}
}