Files
UserhomeService/src/main/java/com/yunhai/userhome/controller/api/MenuBarController.java
T
chenxing d9ec243926
build / build-push (push) Successful in 2m10s
ci
2026-08-26 17:37:42 +08:00

100 lines
4.4 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.yunhai.userhome.controller.api;
import com.yunhai.platform.utils.model.BoaUser;
import com.yunhai.userhome.config.Config;
import com.yunhai.userhome.entity.MenuBar;
import com.yunhai.userhome.entity.UserCurrentRole;
import com.yunhai.userhome.service.IMenuBarService;
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.RestController;
import java.util.*;
/**
* 菜单栏控制器(对齐旧 UserHome contorller.api.MenuBarController) 。
*/
@RestController
@RequestMapping(Config.API_PATH)
public class MenuBarController {
@Autowired
private IMenuBarService menuBarService;
@Autowired
private IUserCurrentRoleService userCurrentRoleService;
@GetMapping("getMenuBarSchList")
public List<MenuBar> getMenuBarSchList(BoaUser authUserWithDept) {
Optional<UserCurrentRole> userCurrentRoleOpt = userCurrentRoleService.findById(authUserWithDept.getId());
if (!userCurrentRoleOpt.isPresent()) {
return new ArrayList<>();
}
UserCurrentRole userCurrentRole = userCurrentRoleOpt.get();
return menuBarService.getMenuBarList(userCurrentRole.getSchId());
}
@GetMapping("getMenuBarList")
public List<Map> getMenuBarList(BoaUser authUserWithDept) {
List<Map> result = new ArrayList<>();
Optional<UserCurrentRole> userCurrentRoleOpt = userCurrentRoleService.findById(authUserWithDept.getId());
if (!userCurrentRoleOpt.isPresent()) {
return result;
}
UserCurrentRole userCurrentRole = userCurrentRoleOpt.get();
Integer roleId = userCurrentRole.getRoleId();
if (roleId == 7 || roleId == 2) roleId = 2;
Boolean isSuperAdmin = authUserWithDept.getType() == 1;
List<MenuBar> list = menuBarService.findMenuBarById(authUserWithDept.getId());
for (MenuBar model : list) {
Map map = new HashMap();
if (!isSuperAdmin && !model.getRoleIds().contains(roleId)) continue;
map.put("id", model.getId());
map.put("name", model.getName());
map.put("url", model.getUrl());
map.put("icon", model.getIcon());
map.put("isNative", model.getIsNative());
map.put("isHeader", model.getIsHeader());
map.put("isBottom", model.getIsBottom());
map.put("orderNum", model.getOrderNum());
map.put("openType", model.getLinkOpenType());
result.add(map);
}
return result;
}
@PostMapping(value = "saveMenuBar", produces = "application/json")
public void saveMenuBar(BoaUser authUserWithDept, @RequestBody MenuBar menuBar) {
UserCurrentRole userCurrentRole = userCurrentRoleService.findById(authUserWithDept.getId())
.orElseThrow(() -> new com.yunhai.platform.apistd.BizException(com.yunhai.platform.utils.exception.ErrorCode.INTERNAL_SERVER_ERROR));
menuBar.setCId(authUserWithDept.getId());
menuBar.setSchId(userCurrentRole.getSchId());
if (menuBar.getId() == null) menuBar.setCDate(new Date());
menuBarService.saveMenuBar(menuBar);
}
@PostMapping(value = "toggleMenuBarShow", produces = "application/json")
public void toggleMenuBarShow(BoaUser authUserWithDept, Integer id) {
UserCurrentRole userCurrentRole = userCurrentRoleService.findById(authUserWithDept.getId())
.orElseThrow(() -> new com.yunhai.platform.apistd.BizException(com.yunhai.platform.utils.exception.ErrorCode.INTERNAL_SERVER_ERROR));
menuBarService.toggleMenuBarShow(id, userCurrentRole.getSchId());
}
@PostMapping(value = "saveMenuBarOrderNum", produces = "application/json")
public void saveMenuBarOrderNum(BoaUser authUserWithDept, @RequestBody Map<String, Integer> params) {
Integer id = params.get("id"),
orderNum = params.get("orderNum");
menuBarService.saveMenuBarOrderNum(id, orderNum);
}
@PostMapping(value = "deleteMenuBar", produces = "application/json")
public void deleteMenuBar(BoaUser authUserWithDept, Integer id) {
menuBarService.deleteMenuBar(id);
}
}