refactor: 重构内部 API 依赖模式(降低耦合,公众号投票结论),在 common 模块新增 api 包,在对应 biz 模块增加实现

This commit is contained in:
2025-07-26 10:24:25 +08:00
parent 3af43ef6c7
commit 7f0059984d
30 changed files with 781 additions and 128 deletions

View File

@@ -0,0 +1,37 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.common.api.system;
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
import java.util.List;
/**
* 字典业务 API
*
* @author Charles7c
* @since 2025/7/26 10:16
*/
public interface DictApi {
/**
* 查询字典列表
*
* @return 字典列表(包含枚举字典列表)
*/
List<LabelValueResp> listAll();
}

View File

@@ -14,19 +14,19 @@
* limitations under the License.
*/
package top.continew.admin.common.service;
package top.continew.admin.common.api.system;
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
import java.util.List;
/**
* 公共字典项业务接口
* 字典项业务 API
*
* @author Charles7c
* @since 2025/4/9 20:17
*/
public interface CommonDictItemService {
public interface DictItemApi {
/**
* 根据字典编码查询

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.common.api.system;
import cn.hutool.core.lang.tree.Tree;
import java.util.List;
/**
* 菜单业务 API
*
* @author Charles7c
* @since 2025/7/26 9:53
*/
public interface MenuApi {
/**
* 查询树结构列表
*
* @param excludeMenuIds 排除的菜单 ID 列表
* @return 树结构列表
*/
List<Tree<Long>> listTree(List<Long> excludeMenuIds);
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.common.api.system;
/**
* 角色业务 API
*
* @author Charles7c
* @since 2025/7/26 9:39
*/
public interface RoleApi {
/**
* 根据编码查询 ID
*
* @param code 编码
* @return 角色 ID
*/
Long getIdByCode(String code);
/**
* 更新用户上下文
*
* @param roleId 角色 ID
*/
void updateUserContext(Long roleId);
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.common.api.system;
import java.util.List;
import java.util.Set;
/**
* 角色和菜单关联业务 API
*
* @author Charles7c
* @since 2025/7/26 9:39
*/
public interface RoleMenuApi {
/**
* 根据菜单 ID 列表查询角色 ID 列表
*
* @param menuIds 菜单 ID 列表Not In
* @return 角色 ID 列表
*/
Set<Long> listRoleIdByNotInMenuIds(List<Long> menuIds);
/**
* 根据角色 ID 列表查询菜单 ID 列表
*
* @param roleIds 角色 ID 列表
* @return 菜单 ID 列表
*/
List<Long> listMenuIdByRoleIds(List<Long> roleIds);
/**
* 根据菜单 ID 列表删除
*
* @param menuIds 菜单 ID 列表Not In
*/
void deleteByNotInMenuIds(List<Long> menuIds);
/**
* 新增
*
* @param menuIds 菜单 ID 列表
* @param roleId 角色 ID
* @return 是否新增成功true成功false无变更/失败)
*/
boolean add(List<Long> menuIds, Long roleId);
}

View File

@@ -14,19 +14,19 @@
* limitations under the License.
*/
package top.continew.admin.common.service;
package top.continew.admin.common.api.system;
import cn.crane4j.annotation.ContainerMethod;
import cn.crane4j.annotation.MappingType;
import top.continew.admin.common.constant.ContainerConstants;
/**
* 公共用户业务接口
* 用户业务 API
*
* @author Charles7c
* @since 2025/1/9 20:17
*/
public interface CommonUserService {
public interface UserApi {
/**
* 根据 ID 查询昵称
@@ -40,4 +40,12 @@ public interface CommonUserService {
*/
@ContainerMethod(namespace = ContainerConstants.USER_NICKNAME, type = MappingType.ORDER_OF_KEYS)
String getNicknameById(Long id);
/**
* 重置密码
*
* @param newPassword 新密码
* @param id ID
*/
void resetPassword(String newPassword, Long id);
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.common.api.tenant;
import java.util.List;
/**
* 套餐和菜单关联业务 API
*
* @author Charles7c
* @since 2025/7/23 21:13
*/
public interface PackageMenuApi {
/**
* 根据套餐 ID 查询
*
* @param packageId 套餐 ID
* @return 菜单 ID 列表
*/
List<Long> listMenuIdsByPackageId(Long packageId);
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.common.api.tenant;
/**
* 租户业务 API
*
* @author Charles7c
* @since 2025/7/23 21:13
*/
public interface TenantApi {
/**
* 绑定租户管理员用户
*
* @param tenantId 租户 ID
* @param userId 用户 ID
*/
void bindAdminUser(Long tenantId, Long userId);
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.common.api.tenant;
import top.continew.admin.common.model.dto.TenantDTO;
/**
* 租户数据 API
*
* @author 小熊
* @author Charles7c
* @since 2024/12/2 20:08
*/
public interface TenantDataApi {
/**
* 初始化数据
*
* @param tenant 租户信息
*/
void init(TenantDTO tenant);
/**
* 清除数据
*/
void clear();
}

View File

@@ -24,7 +24,7 @@ import cn.idev.excel.metadata.GlobalConfiguration;
import cn.idev.excel.metadata.data.ReadCellData;
import cn.idev.excel.metadata.data.WriteCellData;
import cn.idev.excel.metadata.property.ExcelContentProperty;
import top.continew.admin.common.service.CommonDictItemService;
import top.continew.admin.common.api.system.DictItemApi;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
@@ -86,7 +86,7 @@ public class ExcelDictConverter implements Converter<Object> {
if (dictExcelProperty == null) {
throw new IllegalArgumentException("Excel 字典转换器异常:请为字段添加 @DictExcelProperty 注解");
}
CommonDictItemService dictItemService = SpringUtil.getBean(CommonDictItemService.class);
return dictItemService.listByDictCode(dictExcelProperty.value());
DictItemApi dictItemApi = SpringUtil.getBean(DictItemApi.class);
return dictItemApi.listByDictCode(dictExcelProperty.value());
}
}

View File

@@ -20,7 +20,7 @@ import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.extra.spring.SpringUtil;
import top.continew.admin.common.service.CommonUserService;
import top.continew.admin.common.api.system.UserApi;
import top.continew.starter.core.util.ExceptionUtils;
/**
@@ -177,7 +177,7 @@ public class UserContextHolder {
* @return 用户昵称
*/
public static String getNickname(Long userId) {
return ExceptionUtils.exToNull(() -> SpringUtil.getBean(CommonUserService.class).getNicknameById(userId));
return ExceptionUtils.exToNull(() -> SpringUtil.getBean(UserApi.class).getNicknameById(userId));
}
/**

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.common.model.dto;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* 租户信息
*
* @author Charles7c
* @since 2025/7/23 21:05
*/
@Data
public class TenantDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* ID
*/
private Long id;
/**
* 名称
*/
private String name;
/**
* 管理员用户名
*/
private String username;
/**
* 管理员密码
*/
private String password;
/**
* 套餐 ID
*/
private Long packageId;
}