@@ -0,0 +1,92 @@
|
||||
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) {
|
||||
UserCurrentRole userCurrentRole = userCurrentRoleService.findById(authUserWithDept.getId())
|
||||
.orElseThrow(() -> new com.yunhai.platform.apistd.BizException(com.yunhai.platform.utils.exception.ErrorCode.INTERNAL_SERVER_ERROR));
|
||||
return menuBarService.getMenuBarList(userCurrentRole.getSchId());
|
||||
}
|
||||
|
||||
@GetMapping("getMenuBarList")
|
||||
public List<Map> getMenuBarList(BoaUser authUserWithDept) {
|
||||
List<Map> result = new ArrayList<>();
|
||||
UserCurrentRole userCurrentRole = userCurrentRoleService.findById(authUserWithDept.getId())
|
||||
.orElseThrow(() -> new com.yunhai.platform.apistd.BizException(com.yunhai.platform.utils.exception.ErrorCode.INTERNAL_SERVER_ERROR));
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user