增加了mongo-menu模块
This commit is contained in:
parent
f5816eb60b
commit
7f592e05b0
@ -0,0 +1,17 @@
|
|||||||
|
package ink.wgink.interfaces.init;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: IInitMongoData
|
||||||
|
* @Description: 初始化mongo数据
|
||||||
|
* @Author: wanggeng
|
||||||
|
* @Date: 2022/5/24 20:57
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
public interface IInitMongoData {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化 mongo 数据
|
||||||
|
*/
|
||||||
|
void init();
|
||||||
|
|
||||||
|
}
|
@ -125,4 +125,23 @@ public interface IMenuBaseService {
|
|||||||
*/
|
*/
|
||||||
List<String> listMenuIdByUser(Map<String, Object> params);
|
List<String> listMenuIdByUser(Map<String, Object> params);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统菜单列表
|
||||||
|
*
|
||||||
|
* @param systemMenuId 系统菜单
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<MenuDTO> listSystemMenu(String systemMenuId);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统菜单列表
|
||||||
|
*
|
||||||
|
* @param systemMenuId 系统菜单ID
|
||||||
|
* @param selectedMenuIds 选中的菜单ID
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<MenuDTO> listSystemMenu(String systemMenuId, List<String> selectedMenuIds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
package ink.wgink.interfaces.menu;
|
||||||
|
|
||||||
|
import ink.wgink.pojo.dtos.menu.MenuDTO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: IMongoMenuService
|
||||||
|
* @Description: mongo菜单
|
||||||
|
* @Author: wanggeng
|
||||||
|
* @Date: 2022/5/24 20:54
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
public interface IMongoMenuService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新全部系统菜单
|
||||||
|
*/
|
||||||
|
void updateAllSystemMenu();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*
|
||||||
|
* @param menuIds
|
||||||
|
*/
|
||||||
|
void delete(List<String> menuIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新
|
||||||
|
*
|
||||||
|
* @param menuId
|
||||||
|
*/
|
||||||
|
void update(String menuId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 详情
|
||||||
|
*
|
||||||
|
* @param menuId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
MenuDTO get(String menuId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 详情
|
||||||
|
*
|
||||||
|
* @param menuCode
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
MenuDTO getByCode(String menuCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统子菜单列表
|
||||||
|
*
|
||||||
|
* @param systemMenuId 系统菜单ID
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<MenuDTO> listSystemSubMenus(String systemMenuId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统子菜单列表
|
||||||
|
*
|
||||||
|
* @param systemMenuId 系统菜单ID
|
||||||
|
* @param selectedMenuIds 选择的菜单ID
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<MenuDTO> listSystemSubMenus(String systemMenuId, List<String> selectedMenuIds);
|
||||||
|
|
||||||
|
}
|
@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModel;
|
|||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -161,7 +162,7 @@ public class MenuDTO implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<MenuDTO> getSubMenus() {
|
public List<MenuDTO> getSubMenus() {
|
||||||
return subMenus;
|
return subMenus == null ? new ArrayList<>() : subMenus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSubMenus(List<MenuDTO> subMenus) {
|
public void setSubMenus(List<MenuDTO> subMenus) {
|
||||||
|
@ -86,9 +86,9 @@ public class IndexRouteController {
|
|||||||
// 管理员
|
// 管理员
|
||||||
List<String> menuIds = roleMenuBaseService.listMenuId(ISystemConstant.ADMIN);
|
List<String> menuIds = roleMenuBaseService.listMenuId(ISystemConstant.ADMIN);
|
||||||
if (menuIds.isEmpty()) {
|
if (menuIds.isEmpty()) {
|
||||||
menus = menuBaseService.listAllByParentId(IMenuBaseService.MENU_UNIFIED_USER);
|
menus = menuBaseService.listSystemMenu(IMenuBaseService.MENU_UNIFIED_USER);
|
||||||
} else {
|
} else {
|
||||||
menus = menuBaseService.listAllByParentIdAndIds(IMenuBaseService.MENU_UNIFIED_USER, menuIds);
|
menus = menuBaseService.listSystemMenu(IMenuBaseService.MENU_UNIFIED_USER, menuIds);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 普通用户
|
// 普通用户
|
||||||
@ -101,7 +101,7 @@ public class IndexRouteController {
|
|||||||
roleIds.add(roleSimpleDTO.getRoleId());
|
roleIds.add(roleSimpleDTO.getRoleId());
|
||||||
}
|
}
|
||||||
List<String> menuIds = roleMenuBaseService.listMenuId(roleIds);
|
List<String> menuIds = roleMenuBaseService.listMenuId(roleIds);
|
||||||
menus = menuBaseService.listAllByParentIdAndIds(IMenuBaseService.MENU_UNIFIED_USER, menuIds);
|
menus = menuBaseService.listSystemMenu(IMenuBaseService.MENU_UNIFIED_USER, menuIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mv.addObject("menus", menus);
|
mv.addObject("menus", menus);
|
||||||
|
@ -51,13 +51,13 @@ public class OAuth2ClientMenuServiceImpl extends DefaultBaseService implements I
|
|||||||
menuIds = roleMenuBaseService.listMenuId(ISystemConstant.ADMIN);
|
menuIds = roleMenuBaseService.listMenuId(ISystemConstant.ADMIN);
|
||||||
// 管理员菜单为空,加载全部
|
// 管理员菜单为空,加载全部
|
||||||
if (menuIds.isEmpty()) {
|
if (menuIds.isEmpty()) {
|
||||||
return menuBaseService.listAllByParentId(oAuth2ClientPO.getMenuId());
|
return menuBaseService.listSystemMenu(oAuth2ClientPO.getMenuId());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 其他角色菜单
|
// 其他角色菜单
|
||||||
menuIds = roleMenuBaseService.listMenuId(roleIds);
|
menuIds = roleMenuBaseService.listMenuId(roleIds);
|
||||||
}
|
}
|
||||||
return menuBaseService.listAllByParentIdAndIds(oAuth2ClientPO.getMenuId(), menuIds);
|
return menuBaseService.listSystemMenu(oAuth2ClientPO.getMenuId(), menuIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ink.wgink.mongo.login.startup;
|
package ink.wgink.mongo.login.init;
|
||||||
|
|
||||||
|
import ink.wgink.interfaces.init.IInitMongoData;
|
||||||
import ink.wgink.interfaces.user.mongo.IMongoLoginUserService;
|
import ink.wgink.interfaces.user.mongo.IMongoLoginUserService;
|
||||||
import ink.wgink.properties.ServerProperties;
|
import ink.wgink.properties.ServerProperties;
|
||||||
import ink.wgink.service.user.service.IUserService;
|
import ink.wgink.service.user.service.IUserService;
|
||||||
@ -8,24 +9,22 @@ import ink.wgink.util.thread.CachedThreadPoolUtil;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
|
||||||
import org.springframework.boot.ApplicationRunner;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName: MongoLoginStartUp
|
* @ClassName: InitLoginUser
|
||||||
* @Description: mongo启动
|
* @Description: 初始化登录用户
|
||||||
* @Author: wanggeng
|
* @Author: wanggeng
|
||||||
* @Date: 2022/5/19 16:25
|
* @Date: 2022/5/24 20:59
|
||||||
* @Version: 1.0
|
* @Version: 1.0
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class MongoLoginStartUp implements ApplicationRunner {
|
public class InitMongoLoginUser implements IInitMongoData {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(MongoLoginStartUp.class);
|
private static final Logger LOG = LoggerFactory.getLogger(InitMongoLoginUser.class);
|
||||||
@Autowired
|
@Autowired
|
||||||
private ServerProperties serverProperties;
|
private ServerProperties serverProperties;
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -34,24 +33,24 @@ public class MongoLoginStartUp implements ApplicationRunner {
|
|||||||
private IUserService userService;
|
private IUserService userService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ApplicationArguments args) throws Exception {
|
public void init() {
|
||||||
if (serverProperties.getMasterNode()) {
|
if (serverProperties.getMasterNode()) {
|
||||||
LOG.debug("master-node: {}" + serverProperties.getMasterNode());
|
LOG.debug("MASTER-NODE: {}" + serverProperties.getMasterNode());
|
||||||
CachedThreadPoolUtil.execute(() -> {
|
CachedThreadPoolUtil.execute(() -> {
|
||||||
// 初始化所有账号内容
|
// 初始化所有账号内容
|
||||||
System.out.println("**************************");
|
System.out.println("***************************");
|
||||||
System.out.println("** LoginUser Init Start **");
|
System.out.println("** LOGIN USER INIT START **");
|
||||||
System.out.println("**************************");
|
System.out.println("***************************");
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
Map<String, Object> params = new HashMap<>(0);
|
Map<String, Object> params = new HashMap<>(0);
|
||||||
userService.listPO(params).forEach(userPO -> {
|
userService.listPO(params).forEach(userPO -> {
|
||||||
mongoLoginUserService.update(UserUtil.createLoginUser(userPO));
|
mongoLoginUserService.update(UserUtil.createLoginUser(userPO));
|
||||||
});
|
});
|
||||||
long endTime = System.currentTimeMillis();
|
long endTime = System.currentTimeMillis();
|
||||||
System.out.println("**************************");
|
System.out.println("*************************");
|
||||||
System.out.println("** LoginUser Init End **");
|
System.out.println("** LOGIN USER INIT END **");
|
||||||
System.out.println("**************************");
|
System.out.println("*************************");
|
||||||
LOG.debug("LoginUser init used time: {}ms", (endTime - startTime) / 1000L);
|
LOG.debug("LOGIN USER INIT USED TIME: {}ms", (endTime - startTime) / 1000L);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
28
mongo-menu/pom.xml
Normal file
28
mongo-menu/pom.xml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>wg-basic</artifactId>
|
||||||
|
<groupId>ink.wgink</groupId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>mongo-menu</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.data</groupId>
|
||||||
|
<artifactId>spring-data-mongodb</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ink.wgink</groupId>
|
||||||
|
<artifactId>service-menu</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,240 @@
|
|||||||
|
package ink.wgink.mongo.menu.service.impl;
|
||||||
|
|
||||||
|
import ink.wgink.common.base.DefaultBaseService;
|
||||||
|
import ink.wgink.exceptions.SearchException;
|
||||||
|
import ink.wgink.interfaces.menu.IMongoMenuService;
|
||||||
|
import ink.wgink.module.menu.service.IMenuService;
|
||||||
|
import ink.wgink.pojo.dtos.menu.MenuDTO;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: MongoMenuServiceImpl
|
||||||
|
* @Description: mongo菜单,为了提升首页菜单的加载速度
|
||||||
|
* @Author: wanggeng
|
||||||
|
* @Date: 2022/5/24 20:55
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class MongoMenuServiceImpl extends DefaultBaseService implements IMongoMenuService {
|
||||||
|
|
||||||
|
private static final String COLLECTION_NAME = "systemMenu";
|
||||||
|
@Autowired
|
||||||
|
private MongoTemplate mongoTemplate;
|
||||||
|
@Autowired
|
||||||
|
private IMenuService menuService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateAllSystemMenu() {
|
||||||
|
// 清空集合
|
||||||
|
mongoTemplate.dropCollection(COLLECTION_NAME);
|
||||||
|
List<MenuDTO> systemMenus = menuService.listByParentId("0");
|
||||||
|
systemMenus.forEach(systemMenu -> {
|
||||||
|
List<MenuDTO> subSystemMenus = menuService.listAllByParentId(systemMenu.getMenuId());
|
||||||
|
systemMenu.setSubMenus(subSystemMenus);
|
||||||
|
mongoTemplate.save(systemMenu, COLLECTION_NAME);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(List<String> menuIds) {
|
||||||
|
menuIds = new ArrayList<>(menuIds);
|
||||||
|
List<MenuDTO> menuDTOS = mongoTemplate.findAll(MenuDTO.class, COLLECTION_NAME);
|
||||||
|
for (MenuDTO systemMenu : menuDTOS) {
|
||||||
|
IsFinished isFinished = new IsFinished();
|
||||||
|
removeMenu(systemMenu, menuIds, isFinished);
|
||||||
|
updateSystemMenu(systemMenu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(String menuId) {
|
||||||
|
MenuDTO menuDTO = menuService.get(menuId);
|
||||||
|
if (menuDTO == null) {
|
||||||
|
throw new SearchException("菜单更新失败,新增菜单不存在");
|
||||||
|
}
|
||||||
|
// 得到根节点菜单编码
|
||||||
|
String systemMenuCode = menuDTO.getMenuCode().substring(0, 4);
|
||||||
|
MenuDTO systemMenuDTO = getByCode(systemMenuCode);
|
||||||
|
if (systemMenuDTO == null) {
|
||||||
|
throw new SearchException("菜单更新失败,系统菜单不存在");
|
||||||
|
}
|
||||||
|
IsFinished isFinished = new IsFinished();
|
||||||
|
// 重新获取上级菜单(带子集)
|
||||||
|
MenuDTO parentMenuDTO = menuService.getAll(menuDTO.getMenuParentId());
|
||||||
|
if (parentMenuDTO == null) {
|
||||||
|
throw new SearchException("菜单更新失败,新增菜单上级菜单不存在");
|
||||||
|
}
|
||||||
|
// 递归找到要更新的节点
|
||||||
|
setUpdateMenu(systemMenuDTO, parentMenuDTO, isFinished);
|
||||||
|
updateSystemMenu(systemMenuDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MenuDTO get(String menuId) {
|
||||||
|
return mongoTemplate.findOne(new Query().addCriteria(Criteria.where("menuId").is(menuId)), MenuDTO.class, COLLECTION_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MenuDTO getByCode(String menuCode) {
|
||||||
|
return mongoTemplate.findOne(new Query().addCriteria(Criteria.where("menuCode").is(menuCode)), MenuDTO.class, COLLECTION_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MenuDTO> listSystemSubMenus(String systemMenuId) {
|
||||||
|
MenuDTO menuDTO = get(systemMenuId);
|
||||||
|
if (menuDTO == null) {
|
||||||
|
throw new SearchException("系统菜单不存在");
|
||||||
|
}
|
||||||
|
return menuDTO.getSubMenus();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MenuDTO> listSystemSubMenus(String systemMenuId, List<String> selectedMenuIds) {
|
||||||
|
MenuDTO systemMenuDTO = get(systemMenuId);
|
||||||
|
if (systemMenuDTO == null) {
|
||||||
|
throw new SearchException("系统菜单不存在");
|
||||||
|
}
|
||||||
|
IsFinished isFinished = new IsFinished();
|
||||||
|
return listSelectedMenu(systemMenuDTO, selectedMenuIds, isFinished);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归获取选中的菜单列表
|
||||||
|
*
|
||||||
|
* @param menu
|
||||||
|
* @param selectedMenuIds
|
||||||
|
* @param isFinished
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private List<MenuDTO> listSelectedMenu(MenuDTO menu, List<String> selectedMenuIds, IsFinished isFinished) {
|
||||||
|
List<MenuDTO> selectedMenus = new ArrayList<>();
|
||||||
|
for (MenuDTO subMenu : menu.getSubMenus()) {
|
||||||
|
boolean isSelected = false;
|
||||||
|
for (int i = 0; i < selectedMenuIds.size(); i++) {
|
||||||
|
if (StringUtils.equals(subMenu.getMenuId(), selectedMenuIds.get(i))) {
|
||||||
|
isSelected = true;
|
||||||
|
i--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 菜单被选中
|
||||||
|
if (isSelected) {
|
||||||
|
MenuDTO menuDTO = new MenuDTO();
|
||||||
|
BeanUtils.copyProperties(subMenu, menuDTO);
|
||||||
|
List<MenuDTO> subSelectedMenus = listSelectedMenu(subMenu, selectedMenuIds, isFinished);
|
||||||
|
menuDTO.setSubMenus(subSelectedMenus);
|
||||||
|
selectedMenus.add(subMenu);
|
||||||
|
}
|
||||||
|
if (selectedMenuIds.isEmpty()) {
|
||||||
|
isFinished.setFinished(true);
|
||||||
|
}
|
||||||
|
if (isFinished.getFinished()) {
|
||||||
|
return selectedMenus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return selectedMenus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除系统菜单
|
||||||
|
*
|
||||||
|
* @param menuIds
|
||||||
|
*/
|
||||||
|
public void deleteSystemMenu(List<String> menuIds) {
|
||||||
|
mongoTemplate.remove(new Query().addCriteria(Criteria.where("menuId").in(menuIds)), COLLECTION_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除菜单
|
||||||
|
*
|
||||||
|
* @param menuDTO
|
||||||
|
* @param removeMenuIds
|
||||||
|
* @param isFinished
|
||||||
|
*/
|
||||||
|
private void removeMenu(MenuDTO menuDTO, List<String> removeMenuIds, IsFinished isFinished) {
|
||||||
|
List<MenuDTO> subMenus = menuDTO.getSubMenus();
|
||||||
|
for (int i = 0; i < subMenus.size(); i++) {
|
||||||
|
MenuDTO subMenu = subMenus.get(i);
|
||||||
|
boolean isRemove = false;
|
||||||
|
for (int j = 0; j < removeMenuIds.size(); j++) {
|
||||||
|
if (StringUtils.equals(subMenu.getMenuId(), removeMenuIds.get(j))) {
|
||||||
|
// 存在
|
||||||
|
subMenus.remove(i);
|
||||||
|
removeMenuIds.remove(j);
|
||||||
|
j--;
|
||||||
|
isRemove = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (removeMenuIds.isEmpty()) {
|
||||||
|
isFinished.setFinished(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isFinished.getFinished()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isRemove) {
|
||||||
|
removeMenu(subMenu, removeMenuIds, isFinished);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新系统菜单
|
||||||
|
*
|
||||||
|
* @param systemMenuDTO
|
||||||
|
*/
|
||||||
|
private void updateSystemMenu(MenuDTO systemMenuDTO) {
|
||||||
|
// 删除原有
|
||||||
|
deleteSystemMenu(Arrays.asList(systemMenuDTO.getMenuId()));
|
||||||
|
mongoTemplate.save(systemMenuDTO, COLLECTION_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新菜单
|
||||||
|
*
|
||||||
|
* @param parentMenu
|
||||||
|
* @param updateMenu
|
||||||
|
* @param isFinished
|
||||||
|
*/
|
||||||
|
private void setUpdateMenu(MenuDTO parentMenu, MenuDTO updateMenu, IsFinished isFinished) {
|
||||||
|
if (StringUtils.equals(parentMenu.getMenuId(), updateMenu.getMenuId())) {
|
||||||
|
BeanUtils.copyProperties(updateMenu, parentMenu);
|
||||||
|
isFinished.setFinished(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<MenuDTO> subMenus = parentMenu.getSubMenus();
|
||||||
|
for (MenuDTO subMenu : subMenus) {
|
||||||
|
setUpdateMenu(subMenu, updateMenu, isFinished);
|
||||||
|
if (isFinished.getFinished()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否完成
|
||||||
|
*/
|
||||||
|
private class IsFinished {
|
||||||
|
private Boolean isFinished = false;
|
||||||
|
|
||||||
|
public Boolean getFinished() {
|
||||||
|
return isFinished;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFinished(Boolean finished) {
|
||||||
|
isFinished = finished;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
package ink.wgink.mongo.menu.service.init;
|
||||||
|
|
||||||
|
import ink.wgink.interfaces.init.IInitMongoData;
|
||||||
|
import ink.wgink.interfaces.menu.IMongoMenuService;
|
||||||
|
import ink.wgink.properties.ServerProperties;
|
||||||
|
import ink.wgink.util.thread.CachedThreadPoolUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: InitMongoMenu
|
||||||
|
* @Description: 初始化mongo菜单
|
||||||
|
* @Author: wanggeng
|
||||||
|
* @Date: 2022/5/24 21:14
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class InitMongoMenu implements IInitMongoData {
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(InitMongoMenu.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IMongoMenuService mongoMenuService;
|
||||||
|
@Autowired
|
||||||
|
private ServerProperties serverProperties;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
if (serverProperties.getMasterNode()) {
|
||||||
|
LOG.debug("MASTER-NODE: {}" + serverProperties.getMasterNode());
|
||||||
|
CachedThreadPoolUtil.execute(() -> {
|
||||||
|
// 初始化所有账号内容
|
||||||
|
System.out.println("****************************");
|
||||||
|
System.out.println("** SYSTEM MENU INIT START **");
|
||||||
|
System.out.println("****************************");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
mongoMenuService.updateAllSystemMenu();
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
System.out.println("***************************");
|
||||||
|
System.out.println("** SYSTEM MENU INIT END **");
|
||||||
|
System.out.println("***************************");
|
||||||
|
LOG.debug("SYSTEM MENU INIT USED TIME: {}ms", (endTime - startTime) / 1000L);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,7 @@ package ink.wgink.module.menu.service;
|
|||||||
|
|
||||||
import ink.wgink.interfaces.menu.IMenuBaseService;
|
import ink.wgink.interfaces.menu.IMenuBaseService;
|
||||||
import ink.wgink.module.menu.pojo.vos.MenuVO;
|
import ink.wgink.module.menu.pojo.vos.MenuVO;
|
||||||
|
import ink.wgink.pojo.dtos.menu.MenuDTO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -80,4 +81,18 @@ public interface IMenuService extends IMenuBaseService {
|
|||||||
*/
|
*/
|
||||||
void remove(String token, List<String> ids);
|
void remove(String token, List<String> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 详情
|
||||||
|
*
|
||||||
|
* @param menuId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
MenuDTO get(String menuId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 详情(带子集)
|
||||||
|
* @param menuId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
MenuDTO getAll(String menuId);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import com.github.pagehelper.PageInfo;
|
|||||||
import ink.wgink.common.base.DefaultBaseService;
|
import ink.wgink.common.base.DefaultBaseService;
|
||||||
import ink.wgink.exceptions.SearchException;
|
import ink.wgink.exceptions.SearchException;
|
||||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||||
|
import ink.wgink.interfaces.menu.IMongoMenuService;
|
||||||
import ink.wgink.module.menu.dao.IMenuDao;
|
import ink.wgink.module.menu.dao.IMenuDao;
|
||||||
import ink.wgink.module.menu.pojo.vos.MenuVO;
|
import ink.wgink.module.menu.pojo.vos.MenuVO;
|
||||||
import ink.wgink.module.menu.service.IMenuService;
|
import ink.wgink.module.menu.service.IMenuService;
|
||||||
@ -34,6 +35,8 @@ public class MenuServiceImpl extends DefaultBaseService implements IMenuService
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IMenuDao menuDao;
|
private IMenuDao menuDao;
|
||||||
|
@Autowired(required = false)
|
||||||
|
private IMongoMenuService mongoMenuService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String saveAndReturnIdByParentIdAndNameAndUrl(String menuParentId, String menuName, String menuUrl) {
|
public String saveAndReturnIdByParentIdAndNameAndUrl(String menuParentId, String menuName, String menuUrl) {
|
||||||
@ -159,6 +162,9 @@ public class MenuServiceImpl extends DefaultBaseService implements IMenuService
|
|||||||
setAppSaveInfo(token, params);
|
setAppSaveInfo(token, params);
|
||||||
}
|
}
|
||||||
menuDao.save(params);
|
menuDao.save(params);
|
||||||
|
if (mongoMenuService != null) {
|
||||||
|
mongoMenuService.update(menuId);
|
||||||
|
}
|
||||||
return menuId;
|
return menuId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,6 +183,30 @@ public class MenuServiceImpl extends DefaultBaseService implements IMenuService
|
|||||||
setAppUpdateInfo(token, params);
|
setAppUpdateInfo(token, params);
|
||||||
}
|
}
|
||||||
menuDao.remove(params);
|
menuDao.remove(params);
|
||||||
|
if (mongoMenuService != null) {
|
||||||
|
mongoMenuService.delete(ids);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MenuDTO get(String menuId) {
|
||||||
|
Map<String, Object> params = getHashMap(2);
|
||||||
|
params.put("menuId", menuId);
|
||||||
|
return get(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MenuDTO getAll(String menuId) {
|
||||||
|
MenuDTO menuDTO = get(menuId);
|
||||||
|
if (menuDTO == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<MenuDTO> menuDTOs = listAllByParentId(menuId);
|
||||||
|
menuDTO.setSubMenus(menuDTOs);
|
||||||
|
if (!menuDTOs.isEmpty()) {
|
||||||
|
menuDTO.setParent(true);
|
||||||
|
}
|
||||||
|
return menuDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -194,6 +224,9 @@ public class MenuServiceImpl extends DefaultBaseService implements IMenuService
|
|||||||
setAppUpdateInfo(token, params);
|
setAppUpdateInfo(token, params);
|
||||||
}
|
}
|
||||||
menuDao.update(params);
|
menuDao.update(params);
|
||||||
|
if (mongoMenuService != null) {
|
||||||
|
mongoMenuService.update(menuId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -201,6 +234,22 @@ public class MenuServiceImpl extends DefaultBaseService implements IMenuService
|
|||||||
return menuDao.listIdByUser(params);
|
return menuDao.listIdByUser(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MenuDTO> listSystemMenu(String systemMenuId) {
|
||||||
|
if (mongoMenuService != null) {
|
||||||
|
return mongoMenuService.listSystemSubMenus(systemMenuId);
|
||||||
|
}
|
||||||
|
return listAllByParentId(systemMenuId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MenuDTO> listSystemMenu(String systemMenuId, List<String> selectedMenuIds) {
|
||||||
|
if (mongoMenuService != null) {
|
||||||
|
return mongoMenuService.listSystemSubMenus(systemMenuId, selectedMenuIds);
|
||||||
|
}
|
||||||
|
return listAllByParentIdAndIds(systemMenuId, selectedMenuIds);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 递归查询子菜单
|
* 递归查询子菜单
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user