接口修正、成就修正、学习记录修正
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package org.xyzh.system.config;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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.Executor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* @description 异步任务配置
|
||||
* @filename AsyncConfig.java
|
||||
* @author AI
|
||||
* @copyright xyzh
|
||||
* @since 2025-11-03
|
||||
*/
|
||||
@Configuration
|
||||
@EnableAsync
|
||||
public class AsyncConfig {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AsyncConfig.class);
|
||||
|
||||
/**
|
||||
* @description 配置异步任务执行器(用于@Async和事件发布)
|
||||
* @return Executor
|
||||
* @author AI
|
||||
* @since 2025-11-03
|
||||
*/
|
||||
@Bean(name = "taskExecutor")
|
||||
public Executor taskExecutor() {
|
||||
logger.info("初始化异步任务执行器 taskExecutor");
|
||||
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
|
||||
// 核心线程数
|
||||
executor.setCorePoolSize(5);
|
||||
|
||||
// 最大线程数
|
||||
executor.setMaxPoolSize(10);
|
||||
|
||||
// 队列容量
|
||||
executor.setQueueCapacity(100);
|
||||
|
||||
// 线程名称前缀
|
||||
executor.setThreadNamePrefix("async-event-");
|
||||
|
||||
// 拒绝策略:由调用线程处理
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
|
||||
// 等待所有任务完成后再关闭线程池
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
|
||||
// 等待时间(秒)
|
||||
executor.setAwaitTerminationSeconds(60);
|
||||
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,11 +195,17 @@ public class SysDepartmentServiceImpl implements SysDepartmentService {
|
||||
|
||||
// 设置基础信息
|
||||
department.setID(IDUtils.generateID());
|
||||
department.setDeptID(IDUtils.generateID());
|
||||
String deptId = IDUtils.generateID();
|
||||
department.setDeptID(deptId);
|
||||
department.setCreator(currentUser.getID());
|
||||
department.setCreateTime(new Date());
|
||||
department.setDeleted(false);
|
||||
|
||||
// 【修复】设置dept_path
|
||||
String deptPath = buildDeptPath(department.getParentID(), deptId);
|
||||
department.setDeptPath(deptPath);
|
||||
logger.info("创建部门,设置dept_path: {}", deptPath);
|
||||
|
||||
// 插入数据库
|
||||
int result = departmentMapper.insertDept(department);
|
||||
|
||||
@@ -456,4 +462,37 @@ public class SysDepartmentServiceImpl implements SysDepartmentService {
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 构建部门路径(优化版:只查询一次父部门路径)
|
||||
* @param parentId 父部门ID
|
||||
* @param deptId 当前部门ID
|
||||
* @return String 部门路径
|
||||
* @author yslg
|
||||
* @since 2025-11-03
|
||||
*/
|
||||
private String buildDeptPath(String parentId, String deptId) {
|
||||
// 如果没有父部门,说明是根部门
|
||||
if (parentId == null || parentId.trim().isEmpty()) {
|
||||
return "/" + deptId + "/";
|
||||
}
|
||||
|
||||
try {
|
||||
// 【优化】直接通过一条简单SQL查询父部门的dept_path
|
||||
String parentPath = departmentMapper.getDeptPathByDeptId(parentId);
|
||||
|
||||
if (parentPath != null && !parentPath.trim().isEmpty()) {
|
||||
// 父部门路径 + 当前部门ID + /
|
||||
return parentPath + deptId + "/";
|
||||
} else {
|
||||
// 父部门没有dept_path,使用父部门ID构建
|
||||
logger.warn("父部门dept_path为空,parentId: {},将使用父部门ID构建路径", parentId);
|
||||
return "/" + parentId + "/" + deptId + "/";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("构建dept_path失败,parentId: {}, deptId: {}", parentId, deptId, e);
|
||||
// 发生异常时,返回简单路径
|
||||
return "/" + deptId + "/";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,9 @@ public class DatabaseAppender extends AbstractAppender {
|
||||
java.lang.reflect.Method getUsernameMethod = loginUtil.getClass().getMethod("getCurrentUsername");
|
||||
userId = (String) getUserIdMethod.invoke(null);
|
||||
username = (String) getUsernameMethod.invoke(null);
|
||||
if(username == null || username.trim().isEmpty()) {
|
||||
username = "system";
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -90,4 +90,13 @@ public interface DepartmentMapper extends BaseMapper<TbSysDept> {
|
||||
* @since 2025-09-28
|
||||
*/
|
||||
int deleteDept(TbSysDept department);
|
||||
|
||||
/**
|
||||
* @description 根据部门ID获取部门路径(不带权限过滤,仅用于构建子部门路径)
|
||||
* @param deptId 部门ID
|
||||
* @return String 部门路径
|
||||
* @author yslg
|
||||
* @since 2025-11-03
|
||||
*/
|
||||
String getDeptPathByDeptId(@Param("deptId") String deptId);
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
userInfo.setAvatar("default");
|
||||
|
||||
TbSysUserDeptRole userDeptRole = new TbSysUserDeptRole();
|
||||
userDeptRole.setID(IDUtils.generateID()); // 设置ID
|
||||
userDeptRole.setUserID(user.getID());
|
||||
userDeptRole.setDeptID("default_department");
|
||||
userDeptRole.setRoleID("freedom");
|
||||
@@ -482,51 +483,55 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
ResultDomain<UserDeptRoleVO> resultDomain = new ResultDomain<>();
|
||||
TbSysUser currentUser = LoginUtil.getCurrentUser();
|
||||
|
||||
|
||||
// 收集所有用户ID
|
||||
List<String> userIds = new ArrayList<>();
|
||||
for (TbSysUser user : userDeptRoleVO.getUsers()) {
|
||||
userIds.add(user.getID());
|
||||
}
|
||||
|
||||
logger.info("准备为 {} 个用户绑定部门角色", userIds.size());
|
||||
|
||||
// 批量删除所有涉及用户的旧绑定关系(物理删除,包括软删除的记录)
|
||||
int deleteCount = userDeptRoleMapper.deleteUserDeptRoleByUserIds(userIds);
|
||||
if (deleteCount <= 0) {
|
||||
resultDomain.fail("批量删除旧绑定记录失败:没有记录被删除");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 准备新的绑定数据
|
||||
List<TbSysUserDeptRole> userDeptRoles = new ArrayList<>();
|
||||
Date now = new Date();
|
||||
for (TbSysUser user : userDeptRoleVO.getUsers()) {
|
||||
for (TbSysUserDeptRole userDeptRole : userDeptRoleVO.getUserDeptRoles()) {
|
||||
TbSysUserDeptRole newUserDeptRole = new TbSysUserDeptRole();
|
||||
newUserDeptRole.setID(IDUtils.generateID());
|
||||
newUserDeptRole.setUserID(user.getID());
|
||||
newUserDeptRole.setDeptID(userDeptRole.getDeptID());
|
||||
newUserDeptRole.setRoleID(userDeptRole.getRoleID());
|
||||
newUserDeptRole.setCreateTime(now);
|
||||
newUserDeptRole.setCreator(currentUser.getID());
|
||||
userDeptRoles.add(newUserDeptRole);
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("准备插入 {} 条新绑定记录", userDeptRoles.size());
|
||||
|
||||
// 插入新的绑定关系
|
||||
int result = userDeptRoleMapper.bindUser(userDeptRoles);
|
||||
logger.info("成功插入 {} 条绑定记录", result);
|
||||
|
||||
if (result > 0) {
|
||||
resultDomain.success("绑定用户部门角色成功", userDeptRoleVO);
|
||||
} else {
|
||||
resultDomain.fail("绑定用户部门角色失败:没有记录被插入");
|
||||
}
|
||||
|
||||
// 【限制】检查是否只有一个部门-角色配置(一个用户只能有一个部门-角色)
|
||||
if (userDeptRoleVO.getUserDeptRoles() == null || userDeptRoleVO.getUserDeptRoles().size() != 1) {
|
||||
resultDomain.fail("每个用户只能绑定一个部门-角色,请提供且仅提供一个部门-角色配置");
|
||||
logger.warn("绑定失败:提供了 {} 个部门-角色配置,但系统限制为1个",
|
||||
userDeptRoleVO.getUserDeptRoles() != null ? userDeptRoleVO.getUserDeptRoles().size() : 0);
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 收集所有用户ID
|
||||
List<String> userIds = new ArrayList<>();
|
||||
for (TbSysUser user : userDeptRoleVO.getUsers()) {
|
||||
userIds.add(user.getID());
|
||||
}
|
||||
|
||||
logger.info("准备为 {} 个用户绑定部门角色(每个用户一个部门-角色)", userIds.size());
|
||||
|
||||
// 批量删除所有涉及用户的旧绑定关系(物理删除,包括软删除的记录)
|
||||
int deleteCount = userDeptRoleMapper.deleteUserDeptRoleByUserIds(userIds);
|
||||
logger.info("删除了 {} 条旧绑定记录", deleteCount);
|
||||
|
||||
// 准备新的绑定数据(每个用户只绑定一个部门-角色)
|
||||
List<TbSysUserDeptRole> userDeptRoles = new ArrayList<>();
|
||||
Date now = new Date();
|
||||
TbSysUserDeptRole templateDeptRole = userDeptRoleVO.getUserDeptRoles().get(0);
|
||||
|
||||
for (TbSysUser user : userDeptRoleVO.getUsers()) {
|
||||
TbSysUserDeptRole newUserDeptRole = new TbSysUserDeptRole();
|
||||
newUserDeptRole.setID(IDUtils.generateID());
|
||||
newUserDeptRole.setUserID(user.getID());
|
||||
newUserDeptRole.setDeptID(templateDeptRole.getDeptID());
|
||||
newUserDeptRole.setRoleID(templateDeptRole.getRoleID());
|
||||
newUserDeptRole.setCreateTime(now);
|
||||
newUserDeptRole.setCreator(currentUser.getID());
|
||||
userDeptRoles.add(newUserDeptRole);
|
||||
}
|
||||
|
||||
logger.info("准备插入 {} 条新绑定记录(每个用户1条)", userDeptRoles.size());
|
||||
|
||||
// 插入新的绑定关系
|
||||
int result = userDeptRoleMapper.bindUser(userDeptRoles);
|
||||
logger.info("成功插入 {} 条绑定记录", result);
|
||||
|
||||
if (result > 0) {
|
||||
resultDomain.success("绑定用户部门角色成功", userDeptRoleVO);
|
||||
} else {
|
||||
resultDomain.fail("绑定用户部门角色失败:没有记录被插入");
|
||||
}
|
||||
|
||||
return resultDomain;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,15 @@
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 根据部门ID获取部门路径(不带权限过滤,仅用于构建子部门路径) -->
|
||||
<select id="getDeptPathByDeptId" resultType="java.lang.String">
|
||||
SELECT dept_path
|
||||
FROM tb_sys_dept
|
||||
WHERE dept_id = #{deptId}
|
||||
AND deleted = 0
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 根据部门ID查询部门信息(包含父部门信息) -->
|
||||
<select id="selectDeptWithParent" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
|
||||
Reference in New Issue
Block a user