项目初始化提交,移除仓库默认README
build / build-push (push) Failing after 48s

This commit is contained in:
chenxing
2026-08-21 09:37:21 +08:00
parent 729e1d0c35
commit 000993df80
30 changed files with 1497 additions and 0 deletions
@@ -0,0 +1,154 @@
package com.yunhai.userhome.controller.api;
import com.yunhai.platform.utils.model.BoaApp;
import com.yunhai.platform.utils.model.BoaAppType;
import com.yunhai.platform.utils.model.BoaUser;
import com.yunhai.userhome.config.Config;
import com.yunhai.userhome.entity.UsedApp;
import com.yunhai.userhome.model.SetType;
import com.yunhai.userhome.service.AppRemoteService;
import com.yunhai.userhome.service.UsedAppService;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 常用应用接口(CAS 登录态,路径 {@code /{platform}/usedapp/}),对齐旧 UserHome契约
*/
@RestController
@RequestMapping(value = Config.API_PATH + "/usedapp/")
public class UsedAppController {
@Autowired
private UsedAppService usedAppService;
@Autowired
private AppRemoteService appRemoteService;
/**
* 取当前角色生效的常用应用(BoaApp 详情,按 appIds 顺序)。
*
* @param roleType 角色类型
* @param schId 学校ID(0 时按用户主学校/主归属组推断)
* @param isSch 是否学校级(超管设置学校常用时 true,isSch 时 uid=schId)
*/
@GetMapping("getUsedApp")
public List<BoaApp> getUsedApp(BoaUser authUserWithDept, Integer roleType, Integer schId,
@RequestParam(name = "isSch", defaultValue = "false") Boolean isSch) {
if (schId == null || schId == 0) {
schId = resolveSchId(authUserWithDept);
}
Integer uid = authUserWithDept.getId();
if (authUserWithDept.getType() != null && authUserWithDept.getType() == 1) {
isSch = false; // 超管设置学校常用时走用户维度
}
if (isSch) {
uid = schId;
}
return usedAppService.getUsedAppList(schId, uid, roleType, authUserWithDept);
}
/**
* 覆盖式保存常用应用(≤8 由前端控制)。
* 参数:appIds(逗号分隔)、type(0系统/1学校/2用户)、roleType、schId;超管强制 type=0。
*/
@PostMapping("saveUsedApp")
public void saveUsedApp(BoaUser authUserWithDept, @RequestBody Map<String, Object> params) {
String appIds = params.get("appIds") == null ? "" : String.valueOf(params.get("appIds"));
Integer type = params.get("type") == null ? SetType.USER.id()
: Integer.valueOf(String.valueOf(params.get("type")));
Integer roleType = params.get("roleType") == null ? -1
: Integer.valueOf(String.valueOf(params.get("roleType")));
Integer schId = params.get("schId") == null ? 0
: Integer.valueOf(String.valueOf(params.get("schId")));
if (schId == 0) {
schId = resolveSchId(authUserWithDept);
}
UsedApp usedApp = new UsedApp();
usedApp.setAppIds(appIds);
usedApp.setType(SetType.byId(type));
usedApp.setRoleType(roleType);
usedApp.setCDate(new Date());
usedApp.setCId(authUserWithDept.getId());
usedApp.setSchId(schId);
usedApp.setSetId(usedApp.getType() == SetType.SCHOOL ? schId : authUserWithDept.getId());
if (authUserWithDept.getType() != null && authUserWithDept.getType() == 1) {
// 超管保存 → 系统级
usedApp.setType(SetType.BASE);
usedApp.setSetId(authUserWithDept.getId());
}
usedAppService.save(usedApp);
}
/** 用户级常用(type=USER, roleType=-1)精简映射(id/name/icon/url)。 */
@GetMapping("getUsedAppById")
public List<Map<String, Object>> getUsedAppById(BoaUser authUserWithDept) {
return usedAppService.getUsedAppMapList(authUserWithDept, authUserWithDept.getId());
}
/** 用户级保存常用(type=USER, roleType=-1)。 */
@PostMapping("saveUsedAppById")
public void saveUsedAppById(BoaUser authUserWithDept, @RequestBody Map<String, Object> params) {
String appIds = params.get("appIds") == null ? "" : String.valueOf(params.get("appIds"));
UsedApp usedApp = new UsedApp();
usedApp.setAppIds(appIds);
usedApp.setType(SetType.USER);
usedApp.setRoleType(-1);
usedApp.setCDate(new Date());
usedApp.setCId(authUserWithDept.getId());
usedApp.setSetId(authUserWithDept.getId());
usedAppService.saveUserId(usedApp);
}
/** 按 appIds(逗号分隔)取应用精简映射(id/name/icon/url),在全集中查找。 */
@GetMapping("getAppByIds")
public List<Map<String, Object>> getAppByIds(BoaUser authUserWithDept, String appIds) {
List<Map<String, Object>> list = new ArrayList<>();
if (appIds == null || appIds.trim().isEmpty()) {
return list;
}
List<BoaApp> appList = appRemoteService.getUserApps(authUserWithDept).stream()
.filter(t -> t.getApps() != null)
.flatMap(t -> t.getApps().stream())
.collect(Collectors.toList());
for (String appId : appIds.split(",")) {
try {
Integer id = Integer.parseInt(appId.trim());
appList.stream().filter(a -> id.equals(a.getId())).findFirst().ifPresent(app -> {
Map<String, Object> m = new HashMap<>();
m.put("id", app.getId());
m.put("name", app.getName());
m.put("icon", app.getIcon());
m.put("url", app.getWebAddr());
list.add(m);
});
} catch (NumberFormatException ignore) {
// 脏数据容错
}
}
return list;
}
/** schId=0 时推断:主学校 → 主归属组(bureau)→ 0。 */
private Integer resolveSchId(BoaUser user) {
if (user.getSchool() != null) {
return user.getSchool().getId();
}
if (user.getBureau() != null) {
return user.getBureau().getId();
}
return 0;
}
}
@@ -0,0 +1,88 @@
package com.yunhai.userhome.controller.api;
import com.yunhai.platform.apistd.BizException;
import com.yunhai.platform.openapi.client.YschBaseOpenApi;
import com.yunhai.platform.utils.exception.ErrorCode;
import com.yunhai.platform.utils.model.BoaApp;
import com.yunhai.platform.utils.model.BoaAppType;
import com.yunhai.platform.utils.model.BoaRoleInfo;
import com.yunhai.platform.utils.model.BoaUser;
import com.yunhai.userhome.config.Config;
import com.yunhai.userhome.entity.UserCurrentRole;
import com.yunhai.userhome.service.AppRemoteService;
import com.yunhai.userhome.service.IUserCurrentRoleService;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 用户首页接口(CAS 登录态,路径 {@code /{platform}/user/})。
* 控制器直接 return 对象,由 yh-api-std 包成 {@code {code:0,data}}。
*/
@RestController
@RequestMapping(value = Config.API_PATH + "/user/")
public class UserController {
@Autowired
private AppRemoteService appRemoteService;
@Autowired
private IUserCurrentRoleService userCurrentRoleService;
/** 当前登录用户信息(CAS 注入)。 */
@GetMapping("GetUserInfo")
public BoaUser getUserInfo(BoaUser authUserWithDept) {
return authUserWithDept;
}
/**
* 当前用户可访问的应用全集(跨仓 UserBase 实时拉取,按应用类型分组)。
* 前端据此:渲染分类 tab(含「全部」)+ 图标网格;常用区由 getUsedApp 独立提供。
*
* @param schId 兼容旧前端入参(yh-platform getUserApp 当前按 userId 全局权限过滤,schId 暂不参与)
* @param userId 指定用户(缺省用登录用户)
*/
@GetMapping("GetUserApp")
public List<BoaAppType> getUserApp(BoaUser authUserWithDept, Integer schId,
@RequestParam(name = "userId", required = false) Integer userId) {
return appRemoteService.getUserApps(authUserWithDept);
}
/** 按应用ID取单个应用(在已拉取全集中查找,免额外跨仓请求)。 */
@GetMapping("GetAppInfoById")
public BoaApp getAppInfoById(BoaUser authUserWithDept, @RequestParam(name = "id", required = false) Integer id) {
return appRemoteService.getAppById(authUserWithDept, id).orElse(null);
}
/** 当前用户角色身份列表(跨仓 UserBase,含 学校/角色/子节点)。 */
@GetMapping("getUserRole")
public List<BoaRoleInfo> getUserRole(BoaUser authUserWithDept) {
return YschBaseOpenApi.getUserRoleList(authUserWithDept.getId());
}
/** 当前用户激活的角色(本地 user_current_role,可能为空)。 */
@GetMapping("findUserRole")
public UserCurrentRole findUserRole(BoaUser authUserWithDept) {
return userCurrentRoleService.findById(authUserWithDept.getId()).orElse(null);
}
/** 保存当前激活角色(校验所选 学校+角色 属于用户角色列表,防越权)。 */
@PostMapping("savUserRole")
public void savUserRole(BoaUser authUserWithDept, @RequestBody UserCurrentRole roleInfo) {
List<BoaRoleInfo> roleList = YschBaseOpenApi.getUserRoleList(authUserWithDept.getId());
boolean exists = roleList.stream().anyMatch(r ->
r.getRoleId() != null && r.getRoleId().equals(roleInfo.getRoleId())
&& r.getSchId() != null && r.getSchId().equals(roleInfo.getSchId()));
if (!exists) {
throw new BizException(ErrorCode.FORBIDDEN, "非法操作,没有权限");
}
roleInfo.setUserId(authUserWithDept.getId());
userCurrentRoleService.save(roleInfo);
}
}