Skip to content

Commit

Permalink
refactor: 迁移能力开放模块到插件模块,重构拆分 liquibase 脚本结构
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Oct 27, 2024
1 parent f774183 commit aadaa5b
Show file tree
Hide file tree
Showing 47 changed files with 554 additions and 628 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import cn.hutool.db.meta.Column;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
Expand Down Expand Up @@ -51,6 +52,12 @@ public class FieldConfigDO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;

/**
* ID
*/
@TableId
private Long id;

/**
* 表名称
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,10 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>top.continew</groupId>
<artifactId>continew-admin</artifactId>
<artifactId>continew-admin-plugins</artifactId>
<version>${revision}</version>
</parent>

<artifactId>continew-admin-open</artifactId>
<description>能力开放模块(包括应用管理、API开放授权、API开发等)</description>

<dependencies>
<!-- 公共模块(存放公共工具类,公共配置等) -->
<dependency>
<groupId>top.continew</groupId>
<artifactId>continew-admin-common</artifactId>
</dependency>
</dependencies>

<description>能力开放插件(包括应用管理、API开放授权、API开发等)</description>
</project>
3 changes: 2 additions & 1 deletion continew-admin-plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
<description>插件模块(存放代码生成、任务调度等扩展模块)</description>

<modules>
<module>continew-admin-generator</module>
<module>continew-admin-job</module>
<module>continew-admin-open</module>
<module>continew-admin-generator</module>
</modules>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @since 2023/8/20 10:55
*/
@Data
@TableName(value = "sys_notice",autoResultMap = true)
@TableName(value = "sys_notice", autoResultMap = true)
public class NoticeDO extends BaseDO {

@Serial
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

Expand All @@ -38,6 +39,12 @@ public class UserSocialDO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;

/**
* ID
*/
@TableId
private Long id;

/**
* 用户 ID
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ public class UserQuery implements Serializable {
/**
* 用户 IDS
*/
@Schema(description = "用户 ID数组",example = "[1,2,3]")
@Schema(description = "用户 ID数组", example = "[1,2,3]")
private List<Long> userIds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ public class NoticeReq extends BaseReq {
/**
* 通知范围
*/
@Schema(description = "通知范围(1.所有人 2.指定用户)",example = "1")
@Schema(description = "通知范围(1.所有人 2.指定用户)", example = "1")
@NotNull(message = "通知范围不能为空")
private Integer noticeScope;

/**
* 指定用户
*/
@Schema(description = "指定用户",example = "[1,2,3]")
@Schema(description = "指定用户", example = "[1,2,3]")
private List<String> noticeUsers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ public class NoticeDetailResp extends BaseDetailResp {
/**
* 通知范围
*/
@Schema(description = "通知范围(1.所有人 2.指定用户)",example = "1")
@Schema(description = "通知范围(1.所有人 2.指定用户)", example = "1")
private Integer noticeScope;

/**
* 指定用户
*/
@Schema(description = "指定用户",example = "[1,2,3]")
@Schema(description = "指定用户", example = "[1,2,3]")
private List<String> noticeUsers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,15 @@ public NoticeStatusEnum getStatus() {
return NoticeStatusEnum.getStatus(effectiveTime, terminateTime);
}


/**
* 通知范围
*/
@Schema(description = "通知范围(1.所有人 2.指定用户)",example = "1")
@Schema(description = "通知范围(1.所有人 2.指定用户)", example = "1")
private Integer noticeScope;

/**
* 指定用户
*/
@Schema(description = "指定用户",example = "[1,2,3]")
@Schema(description = "指定用户", example = "[1,2,3]")
private List<String> noticeUsers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public interface DeptService extends BaseService<DeptResp, DeptResp, DeptQuery,
/**
* 部门用户树
*
* @param query 部门查询条件
* @param query 部门查询条件
* @param sortQuery 排序条件
* @param isSimple 是否只返回简单部门树
* @param isSimple 是否只返回简单部门树
* @return 部门数量
*/
List<Tree<String>> treeWithUsers(DeptQuery query, SortQuery sortQuery, boolean isSimple);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package top.continew.admin.system.service;

import top.continew.admin.system.model.entity.UserDO;
import top.continew.admin.system.model.entity.UserRoleDO;

import java.util.List;
Expand All @@ -41,11 +40,12 @@ public interface UserRoleService {
/**
* 关联用户
*
* @param roleId 角色id
* @param roleId 角色id
* @param userIds 用户id列表
* @return 是否新增成功(true:成功;false:无变更/失败)
*/
boolean bindUserIds(Long roleId,List<Long> userIds);
boolean bindUserIds(Long roleId, List<Long> userIds);

/**
* 根据用户 ID 删除
*
Expand All @@ -60,8 +60,6 @@ public interface UserRoleService {
*/
void saveBatch(List<UserRoleDO> list);



/**
* 根据用户 ID 查询
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,56 +105,60 @@ public List<Tree<String>> treeWithUsers(DeptQuery query, SortQuery sortQuery, bo
// 创建一个部门ID到用户的映射
UserQuery userQuery = new UserQuery();
userQuery.setStatus(DisEnableStatusEnum.ENABLE);
Map<Long, List<UserResp>> userMap = userService.list(userQuery, null).stream()
.collect(Collectors.groupingBy(UserResp::getDeptId));
Map<Long, List<UserResp>> userMap = userService.list(userQuery, null)
.stream()
.collect(Collectors.groupingBy(UserResp::getDeptId));

String rootId = "dept_0";

return TreeUtil.build(list, rootId, treeNodeConfig, (node, tree) -> {
Long departmentId = ReflectUtil.invoke(node, CharSequenceUtil.genGetter(treeField.value()), new Object[0]);
Long departmentId = ReflectUtil.invoke(node, CharSequenceUtil.genGetter(treeField
.value()), new Object[0]);
String uniqueDeptId = "dept_" + departmentId;
tree.setId(uniqueDeptId);
Long parentId = ReflectUtil.invoke(node, CharSequenceUtil.genGetter(treeField.parentIdKey()), new Object[0]);
Long parentId = ReflectUtil.invoke(node, CharSequenceUtil.genGetter(treeField
.parentIdKey()), new Object[0]);
tree.setParentId(parentId != null ? "dept_" + parentId : null);
tree.setName(ReflectUtil.invoke(node, CharSequenceUtil.genGetter(treeField.nameKey()), new Object[0]));
tree.setWeight(ReflectUtil.invoke(node, CharSequenceUtil.genGetter(treeField.weightKey()), new Object[0]));
tree.setWeight(ReflectUtil.invoke(node, CharSequenceUtil.genGetter(treeField
.weightKey()), new Object[0]));
tree.putExtra("origId", departmentId);
tree.putExtra("isUser", false);

// 添加用户信息到树节点
if (userMap.containsKey(departmentId)) {
List<UserResp> userList = userMap.get(departmentId);
List<Tree<String>> userTrees = userList.stream()
.map(user -> {
Tree<String> userTree = new Tree<>();
String uniqueUserId = "user_" + user.getId();
String userAliasName = user.getUsername() + "(" + user.getNickname() + ")";
userTree.setId(uniqueUserId);
userTree.setParentId(uniqueDeptId);
userTree.setName(userAliasName);
userTree.setWeight(0);
userTree.putExtra("origId", user.getId()); // 添加原始用户ID
userTree.putExtra("isUser", true); // 添加原始用户ID
return userTree;
})
.collect(Collectors.toList());
List<Tree<String>> userTrees = userList.stream().map(user -> {
Tree<String> userTree = new Tree<>();
String uniqueUserId = "user_" + user.getId();
String userAliasName = user.getUsername() + "(" + user.getNickname() + ")";
userTree.setId(uniqueUserId);
userTree.setParentId(uniqueDeptId);
userTree.setName(userAliasName);
userTree.setWeight(0);
userTree.putExtra("origId", user.getId()); // 添加原始用户ID
userTree.putExtra("isUser", true); // 添加原始用户ID
return userTree;
}).collect(Collectors.toList());
tree.setChildren(userTrees);
}

if (!isSimple) {
List<Field> fieldList = ReflectUtils.getNonStaticFields(this.getListClass());
fieldList.removeIf((f) -> {
return CharSequenceUtil.equalsAnyIgnoreCase(f.getName(), new CharSequence[]{treeField.value(), treeField.parentIdKey(), treeField.nameKey(), treeField.weightKey(), treeField.childrenKey()});
return CharSequenceUtil.equalsAnyIgnoreCase(f.getName(), new CharSequence[] {treeField.value(),
treeField.parentIdKey(), treeField.nameKey(), treeField.weightKey(), treeField
.childrenKey()});
});
fieldList.forEach((f) -> {
tree.putExtra(f.getName(), ReflectUtil.invoke(node, CharSequenceUtil.genGetter(f.getName()), new Object[0]));
tree.putExtra(f.getName(), ReflectUtil.invoke(node, CharSequenceUtil.genGetter(f
.getName()), new Object[0]));
});
}
});
}
}


@Override
protected void beforeAdd(DeptReq req) {
String name = req.getName();
Expand All @@ -180,13 +184,13 @@ protected void beforeUpdate(DeptReq req, Long id) {
if (ObjectUtil.notEqual(newStatus, oldDept.getStatus())) {
List<DeptDO> children = this.listChildren(id);
long enabledChildrenCount = children.stream()
.filter(d -> DisEnableStatusEnum.ENABLE.equals(d.getStatus()))
.count();
.filter(d -> DisEnableStatusEnum.ENABLE.equals(d.getStatus()))
.count();
CheckUtils.throwIf(DisEnableStatusEnum.DISABLE
.equals(newStatus) && enabledChildrenCount > 0, "禁用 [{}] 前,请先禁用其所有下级部门", oldName);
.equals(newStatus) && enabledChildrenCount > 0, "禁用 [{}] 前,请先禁用其所有下级部门", oldName);
DeptDO oldParentDept = this.getByParentId(oldParentId);
CheckUtils.throwIf(DisEnableStatusEnum.ENABLE.equals(newStatus) && DisEnableStatusEnum.DISABLE
.equals(oldParentDept.getStatus()), "启用 [{}] 前,请先启用其所有上级部门", oldName);
.equals(oldParentDept.getStatus()), "启用 [{}] 前,请先启用其所有上级部门", oldName);
}
// 变更上级部门
if (ObjectUtil.notEqual(req.getParentId(), oldParentId)) {
Expand All @@ -201,12 +205,12 @@ protected void beforeUpdate(DeptReq req, Long id) {
@Override
protected void beforeDelete(List<Long> ids) {
List<DeptDO> list = baseMapper.lambdaQuery()
.select(DeptDO::getName, DeptDO::getIsSystem)
.in(DeptDO::getId, ids)
.list();
.select(DeptDO::getName, DeptDO::getIsSystem)
.in(DeptDO::getId, ids)
.list();
Optional<DeptDO> isSystemData = list.stream().filter(DeptDO::getIsSystem).findFirst();
CheckUtils.throwIf(isSystemData::isPresent, "所选部门 [{}] 是系统内置部门,不允许删除", isSystemData.orElseGet(DeptDO::new)
.getName());
.getName());
CheckUtils.throwIf(this.countChildren(ids) > 0, "所选部门存在下级部门,不允许删除");
CheckUtils.throwIf(userService.countByDeptIds(ids) > 0, "所选部门存在用户关联,请解除关联后重试");
// 删除角色和部门关联
Expand All @@ -223,10 +227,10 @@ protected void beforeDelete(List<Long> ids) {
*/
private boolean isNameExists(String name, Long parentId, Long id) {
return baseMapper.lambdaQuery()
.eq(DeptDO::getName, name)
.eq(DeptDO::getParentId, parentId)
.ne(null != id, DeptDO::getId, id)
.exists();
.eq(DeptDO::getName, name)
.eq(DeptDO::getParentId, parentId)
.ne(null != id, DeptDO::getId, id)
.exists();
}

/**
Expand Down Expand Up @@ -264,8 +268,8 @@ private Long countChildren(List<Long> ids) {
}
DatabaseType databaseType = MetaUtils.getDatabaseTypeOrDefault(dataSource, DatabaseType.MYSQL);
return ids.stream()
.mapToLong(id -> baseMapper.lambdaQuery().apply(databaseType.findInSet(id, "ancestors")).count())
.sum();
.mapToLong(id -> baseMapper.lambdaQuery().apply(databaseType.findInSet(id, "ancestors")).count())
.sum();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class NoticeServiceImpl extends BaseServiceImpl<NoticeMapper, NoticeDO, N

@Override
public List<DashboardNoticeResp> listDashboard() {
Long userId = UserContextHolder.isAdmin()? null: UserContextHolder.getUserId();
Long userId = UserContextHolder.isAdmin() ? null : UserContextHolder.getUserId();
return baseMapper.selectDashboardList(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import top.continew.admin.common.enums.DataScopeEnum;
import top.continew.admin.system.mapper.RoleMapper;
import top.continew.admin.system.model.entity.RoleDO;
import top.continew.admin.system.model.entity.UserDO;
import top.continew.admin.system.model.query.RoleQuery;
import top.continew.admin.system.model.req.RoleReq;
import top.continew.admin.system.model.resp.MenuResp;
Expand Down Expand Up @@ -199,8 +198,6 @@ public int countByNames(List<String> roleNames) {
return (int)this.count(Wrappers.<RoleDO>lambdaQuery().in(RoleDO::getName, roleNames));
}



/**
* 名称是否存在
*
Expand Down
Loading

0 comments on commit aadaa5b

Please sign in to comment.