Browse Source

refactor(online): 权限字异步任务改为声明式管理并解耦Mapper依赖

- 新增 OnlineAsyncConfig 配置专用线程池 permCodeTaskExecutor
- 权限字生成与清理方法改用 @Async 和 @Transactional 注解替代手动线程池提交
- 将外部 OnlineSysPermCode* Mapper 引用替换为模块内部精简的 SysPermCode* Mapper
- 新增 SysPermCodeMapper、SysPermCodePermMapper、SysPermMapper、SysPermModuleMapper 接口
- 在 OnlineAutoConfig 中通过 @Import 引入异步配置
feature/2026-07-ccc-dev
chenchuchuan 2 months ago
parent
commit
8b98a7581d
  1. 36
      common/common-online/src/main/java/apelet/common/online/config/OnlineAsyncConfig.java
  2. 2
      common/common-online/src/main/java/apelet/common/online/config/OnlineAutoConfig.java
  3. 14
      common/common-online/src/main/java/apelet/common/online/upms/dao/SysPermCodeMapper.java
  4. 14
      common/common-online/src/main/java/apelet/common/online/upms/dao/SysPermCodePermMapper.java
  5. 14
      common/common-online/src/main/java/apelet/common/online/upms/dao/SysPermMapper.java
  6. 14
      common/common-online/src/main/java/apelet/common/online/upms/dao/SysPermModuleMapper.java
  7. 15
      common/common-online/src/main/java/apelet/common/online/upms/service/impl/OnlinePermCodeServiceImpl.java

36
common/common-online/src/main/java/apelet/common/online/config/OnlineAsyncConfig.java

@ -0,0 +1,36 @@
package apelet.common.online.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* common-online异步任务线程池配置。
* <p>供在线表单发布生成权限字等异步任务使用。</p>
*
* @author guifc
* @date 2023-08-04
*/
@Configuration
@EnableAsync
public class OnlineAsyncConfig {
/**
* 权限字生成/清理专用线程池。
*/
@Bean("permCodeTaskExecutor")
public ThreadPoolTaskExecutor permCodeTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(2);
executor.setMaxPoolSize(4);
executor.setQueueCapacity(100);
executor.setThreadNamePrefix("perm-code-");
// 队列满时由调用线程执行,避免丢弃任务。
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.initialize();
return executor;
}
}

2
common/common-online/src/main/java/apelet/common/online/config/OnlineAutoConfig.java

@ -1,6 +1,7 @@
package apelet.common.online.config; package apelet.common.online.config;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Import;
/** /**
* common-online模块的自动配置引导类。 * common-online模块的自动配置引导类。
@ -9,5 +10,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
* @date 2023-08-04 * @date 2023-08-04
*/ */
@EnableConfigurationProperties({OnlineProperties.class}) @EnableConfigurationProperties({OnlineProperties.class})
@Import(OnlineAsyncConfig.class)
public class OnlineAutoConfig { public class OnlineAutoConfig {
} }

14
common/common-online/src/main/java/apelet/common/online/upms/dao/SysPermCodeMapper.java

@ -0,0 +1,14 @@
package apelet.common.online.upms.dao;
import apelet.common.core.base.dao.BaseDaoMapper;
import apelet.common.online.upms.model.SysPermCode;
/**
* 权限字数据访问操作接口。
* <p>在线表单发布自动生成权限字使用,精简自 tenant-admin 的同名 Mapper。</p>
*
* @author guifc
* @date 2023-08-04
*/
public interface SysPermCodeMapper extends BaseDaoMapper<SysPermCode> {
}

14
common/common-online/src/main/java/apelet/common/online/upms/dao/SysPermCodePermMapper.java

@ -0,0 +1,14 @@
package apelet.common.online.upms.dao;
import apelet.common.core.base.dao.BaseDaoMapper;
import apelet.common.online.upms.model.SysPermCodePerm;
/**
* 权限字与权限资源关系数据访问操作接口。
* <p>在线表单发布自动生成权限字使用,精简自 tenant-admin 的同名 Mapper。</p>
*
* @author guifc
* @date 2023-08-04
*/
public interface SysPermCodePermMapper extends BaseDaoMapper<SysPermCodePerm> {
}

14
common/common-online/src/main/java/apelet/common/online/upms/dao/SysPermMapper.java

@ -0,0 +1,14 @@
package apelet.common.online.upms.dao;
import apelet.common.core.base.dao.BaseDaoMapper;
import apelet.common.online.upms.model.SysPerm;
/**
* 权限资源数据访问操作接口。
* <p>在线表单发布自动生成权限字使用,精简自 tenant-admin 的同名 Mapper。</p>
*
* @author guifc
* @date 2023-08-04
*/
public interface SysPermMapper extends BaseDaoMapper<SysPerm> {
}

14
common/common-online/src/main/java/apelet/common/online/upms/dao/SysPermModuleMapper.java

@ -0,0 +1,14 @@
package apelet.common.online.upms.dao;
import apelet.common.core.base.dao.BaseDaoMapper;
import apelet.common.online.upms.model.SysPermModule;
/**
* 权限模块数据访问操作接口。
* <p>在线表单发布自动生成权限字使用,精简自 tenant-admin 的同名 Mapper。</p>
*
* @author guifc
* @date 2023-08-04
*/
public interface SysPermModuleMapper extends BaseDaoMapper<SysPermModule> {
}

15
common/common-online/src/main/java/apelet/common/online/upms/service/impl/OnlinePermCodeServiceImpl.java

@ -11,10 +11,10 @@ import apelet.common.online.dao.OnlinePageMapper;
import apelet.common.online.dao.OnlineTableMapper; import apelet.common.online.dao.OnlineTableMapper;
import apelet.common.online.model.OnlinePage; import apelet.common.online.model.OnlinePage;
import apelet.common.online.model.OnlineTable; import apelet.common.online.model.OnlineTable;
import apelet.common.online.upms.dao.OnlineSysPermCodeMapper; import apelet.common.online.upms.dao.SysPermCodeMapper;
import apelet.common.online.upms.dao.OnlineSysPermCodePermMapper; import apelet.common.online.upms.dao.SysPermCodePermMapper;
import apelet.common.online.upms.dao.OnlineSysPermMapper; import apelet.common.online.upms.dao.SysPermMapper;
import apelet.common.online.upms.dao.OnlineSysPermModuleMapper; import apelet.common.online.upms.dao.SysPermModuleMapper;
import apelet.common.online.upms.model.SysPerm; import apelet.common.online.upms.model.SysPerm;
import apelet.common.online.upms.model.SysPermCode; import apelet.common.online.upms.model.SysPermCode;
import apelet.common.online.upms.model.SysPermCodePerm; import apelet.common.online.upms.model.SysPermCodePerm;
@ -27,7 +27,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
import java.util.*; import java.util.*;
@ -86,12 +88,15 @@ public class OnlinePermCodeServiceImpl implements OnlinePermCodeService {
private OnlineSysPermCodeMapper onlineSysPermCodeMapper; private OnlineSysPermCodeMapper onlineSysPermCodeMapper;
@Autowired @Autowired
private OnlineSysPermCodePermMapper onlineSysPermCodePermMapper; private OnlineSysPermCodePermMapper onlineSysPermCodePermMapper;
@Autowired @Autowired
private IdGeneratorWrapper idGenerator; private IdGeneratorWrapper idGenerator;
/** /**
* 发布后异步生成权限字,先生成前先清理旧数据保证幂等。 * 发布后异步生成权限字,先生成前先清理旧数据保证幂等。
*/ */
@Async("permCodeTaskExecutor")
@Transactional(rollbackFor = Exception.class)
@Override @Override
public void genPermCodeByPageId(Long pageId, Long userId) { public void genPermCodeByPageId(Long pageId, Long userId) {
permCodeExecutor.execute(() -> { permCodeExecutor.execute(() -> {
@ -110,6 +115,8 @@ public class OnlinePermCodeServiceImpl implements OnlinePermCodeService {
/** /**
* 删除表单后异步清理权限字相关数据。 * 删除表单后异步清理权限字相关数据。
*/ */
@Async("permCodeTaskExecutor")
@Transactional(rollbackFor = Exception.class)
@Override @Override
public void removePermCodeByPageCode(String pageCode) { public void removePermCodeByPageCode(String pageCode) {
permCodeExecutor.execute(() -> { permCodeExecutor.execute(() -> {

Loading…
Cancel
Save