【7.3.2】【menu】菜单资源表的资源编码跟随系统编码更新

pull/43/MERGE
fengshuonan 2022-11-16 23:36:04 +08:00
parent 429bde8295
commit d03643f4b5
4 changed files with 64 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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