mirror of https://gitee.com/stylefeng/roses
【7.3.2】【menu】菜单资源表的资源编码跟随系统编码更新
parent
429bde8295
commit
d03643f4b5
|
@ -0,0 +1,37 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.menu.listener;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.stylefeng.roses.kernel.rule.listener.ApplicationStartedListener;
|
||||
import cn.stylefeng.roses.kernel.system.modular.menu.service.SysMenuResourceService;
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
|
||||
/**
|
||||
* 监听项目启动,进行menu_resource表的资源名称前缀修改
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/11/16 23:05
|
||||
*/
|
||||
public class MenuResourceUpdateListener extends ApplicationStartedListener implements Ordered {
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Ordered.LOWEST_PRECEDENCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventCallback(ApplicationStartedEvent event) {
|
||||
|
||||
SysMenuResourceService sysMenuResourceService = SpringUtil.getBean(SysMenuResourceService.class);
|
||||
|
||||
// 获取environment参数
|
||||
ConfigurableEnvironment environment = event.getApplicationContext().getEnvironment();
|
||||
String springApplicationName = environment.getProperty("spring.application.name");
|
||||
|
||||
// 获取所有menu_resource表记录
|
||||
sysMenuResourceService.updateNewAppCode(springApplicationName);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -57,4 +57,12 @@ public interface SysMenuResourceService extends IService<SysMenuResource> {
|
|||
*/
|
||||
void addMenuResourceBind(SysMenuResourceRequest sysMenuResourceRequest);
|
||||
|
||||
/**
|
||||
* 更新本表的所有资源编码,改为新的应用code前缀
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/11/16 23:13
|
||||
*/
|
||||
void updateNewAppCode(String newAppCode);
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.menu.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.rule.util.GunsResourceCodeUtil;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.menu.SysMenuResourceRequest;
|
||||
import cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenuResource;
|
||||
import cn.stylefeng.roses.kernel.system.modular.menu.mapper.SysMenuResourceMapper;
|
||||
|
@ -91,4 +92,20 @@ public class SysMenuResourceServiceImpl extends ServiceImpl<SysMenuResourceMappe
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNewAppCode(String newAppCode) {
|
||||
|
||||
// 获取所有菜单资源表信息
|
||||
List<SysMenuResource> list = this.list();
|
||||
|
||||
// 批量更新资源编码
|
||||
for (SysMenuResource sysMenuResource : list) {
|
||||
String newResourceCode = GunsResourceCodeUtil.replace(sysMenuResource.getResourceCode(), newAppCode);
|
||||
sysMenuResource.setResourceCode(newResourceCode);
|
||||
}
|
||||
|
||||
this.updateBatchById(list);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,3 +4,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
|||
cn.stylefeng.roses.kernel.system.starter.cache.GunsResourceMemoryCacheAutoConfiguration,\
|
||||
cn.stylefeng.roses.kernel.system.starter.cache.GunsResourceRedisCacheAutoConfiguration,\
|
||||
cn.stylefeng.roses.kernel.system.starter.GunsSystemHomeStatisticsAutoConfiguration
|
||||
org.springframework.context.ApplicationListener=\
|
||||
cn.stylefeng.roses.kernel.system.modular.menu.listener.MenuResourceUpdateListener
|
Loading…
Reference in New Issue