From dfd1360b2895782a4ccb860987adeedeb1254a4d Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Fri, 3 Jul 2020 23:40:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=20system=20=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 1 + system-service-project/pom.xml | 45 ++++++++ .../system-service-api}/pom.xml | 23 ++-- .../enums/SystemErrorCodeEnum.java | 109 ++++++++++++++++++ .../systemservice/rpc/oauth/OAuth2Rpc.java | 4 + .../mall/systemservice/rpc/package-info.java | 1 + .../system-service-app/pom.xml | 85 ++++++++++++++ .../SystemServiceApplication.java | 13 +++ .../config/DatabaseConfiguration.java | 28 +++++ .../config/ServiceExceptionConfiguration.java | 20 ++++ .../rpc/oauth/OAuth2RpcImpl.java | 7 ++ .../mall/systemservice/rpc/package-info.java | 1 + .../src/main/resources/application-dev.yaml | 20 ++++ .../src/main/resources/application-local.yaml | 20 ++++ .../src/main/resources/application.yaml | 37 ++++++ user/pom.xml | 1 - .../user/application/UserApplication.java | 24 ---- .../src/main/resources/application.yaml | 8 -- 18 files changed, 403 insertions(+), 44 deletions(-) create mode 100644 system-service-project/pom.xml rename {user/user-application => system-service-project/system-service-api}/pom.xml (58%) create mode 100644 system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/enums/SystemErrorCodeEnum.java create mode 100644 system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/oauth/OAuth2Rpc.java create mode 100644 system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/package-info.java create mode 100644 system-service-project/system-service-app/pom.xml create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/SystemServiceApplication.java create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/config/DatabaseConfiguration.java create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/config/ServiceExceptionConfiguration.java create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/oauth/OAuth2RpcImpl.java create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/package-info.java create mode 100644 system-service-project/system-service-app/src/main/resources/application-dev.yaml create mode 100644 system-service-project/system-service-app/src/main/resources/application-local.yaml create mode 100644 system-service-project/system-service-app/src/main/resources/application.yaml delete mode 100644 user/user-application/src/main/java/cn/iocoder/mall/user/application/UserApplication.java delete mode 100644 user/user-application/src/main/resources/application.yaml diff --git a/pom.xml b/pom.xml index 96eaf43d9..0928ad1a2 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,7 @@ user-service-project user-web-app + system-service-project pom diff --git a/system-service-project/pom.xml b/system-service-project/pom.xml new file mode 100644 index 000000000..bc920f5ac --- /dev/null +++ b/system-service-project/pom.xml @@ -0,0 +1,45 @@ + + + + onemall + cn.iocoder.mall + 1.0-SNAPSHOT + + 4.0.0 + + system-service-project + pom + + system-service-api + system-service-app + + + + + + + cn.iocoder.mall + mall-dependencies + 1.0-SNAPSHOT + pom + import + + + + cn.iocoder.mall + common-framework + 1.0-SNAPSHOT + + + + + cn.iocoder.mall + system-service-api + 1.0-SNAPSHOT + + + + + diff --git a/user/user-application/pom.xml b/system-service-project/system-service-api/pom.xml similarity index 58% rename from user/user-application/pom.xml rename to system-service-project/system-service-api/pom.xml index 2ad3fbe84..9d0ae27b5 100644 --- a/user/user-application/pom.xml +++ b/system-service-project/system-service-api/pom.xml @@ -3,28 +3,29 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - user + system-service-project cn.iocoder.mall 1.0-SNAPSHOT 4.0.0 - user-application - + system-service-api - cn.iocoder.mall - user-rest - 1.0-SNAPSHOT - - - cn.iocoder.mall - user-rpc - 1.0-SNAPSHOT + common-framework + + + javax.validation + validation-api + + + org.projectlombok + lombok + diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/enums/SystemErrorCodeEnum.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/enums/SystemErrorCodeEnum.java new file mode 100644 index 000000000..76fd3f68b --- /dev/null +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/enums/SystemErrorCodeEnum.java @@ -0,0 +1,109 @@ +package cn.iocoder.mall.systemservice.enums; + +import cn.iocoder.common.framework.util.ServiceExceptionUtil; + +/** + * 错误码枚举类 + * + * system 系统,使用 1-002-000-000 段 + */ +public enum SystemErrorCodeEnum implements ServiceExceptionUtil.Enumerable { + + // ========== OAUTH2 模块 ========== + OAUTH2_UNKNOWN(1001001000, "未知错误"), // 预留 + // 预留 1001001001 ~ 1001001099 错误码,方便前端 + OAUTH2_ACCESS_TOKEN_NOT_FOUND(1001001001, "访问令牌不存在"), + OAUTH2_ACCESS_TOKEN_TOKEN_EXPIRED(1001001002, "访问令牌已过期"), + OAUTH2_ACCESS_TOKEN_INVALID(1001001003, "访问令牌已失效"), + OAUTH2_NOT_AUTHENTICATE(1001001004, "账号未登陆"), + OAUTH2_REFRESH_TOKEN_NOT_FOUND(1001001005, "刷新令牌不存在"), + OAUTH_REFRESH_TOKEN_EXPIRED(1001001006, "访问令牌已过期"), + OAUTH_REFRESH_TOKEN_INVALID(1001001007, "刷新令牌已失效"), + // 其它 1001001100 开始 + OAUTH2_ACCOUNT_NOT_FOUND(1001001100, "账号不存在"), + OAUTH2_ACCOUNT_PASSWORD_ERROR(1001001101, "密码不正确"), + + // ========== 管理员模块 1002002000 ========== + ADMIN_NOT_FOUND(1002002000, "管理员不存在"), +// 废弃 ADMIN_USERNAME_NOT_REGISTERED(1002002000, "账号不存在"), +// 废弃 ADMIN_PASSWORD_ERROR(1002002001, "密码不正确"), +// ADMIN_IS_DISABLE(1002002002, "账号被禁用"), +// ADMIN_USERNAME_EXISTS(1002002002, "账号已经存在"), +// ADMIN_STATUS_EQUALS(1002002003, "账号已经是该状态"), +// ADMIN_DELETE_ONLY_DISABLE(1002002004, "只有关闭的账号才可以删除"), +// ADMIN_ADMIN_STATUS_CAN_NOT_UPDATE(1002002005, "管理员的账号状态不允许变更"), +// ADMIN_ASSIGN_ROLE_NOT_EXISTS(1002002006, "分配员工角色时,有角色不存在"), +// ADMIN_ADMIN_CAN_NOT_UPDATE(1002002008, "管理员的账号不允许变更"), + + // ========== 资源模块 1002003000 ========== + RESOURCE_NAME_DUPLICATE(1002003000, "已经存在该名字的资源"), + RESOURCE_PARENT_NOT_EXISTS(1002003001, "父资源不存在"), + RESOURCE_PARENT_ERROR(1002003002, "不能设置自己为父资源"), + RESOURCE_NOT_EXISTS(1002003003, "资源不存在"), + RESOURCE_EXISTS_CHILDREN(1002003004, "存在子资源,无法删除"), + RESOURCE_PARENT_NOT_MENU(1002003005, "父资源的类型必须是菜单"), + + // ========== 角色模块 1002004000 ========== + ROLE_NOT_EXISTS(1002004000, "角色不存在"), + ROLE_NAME_DUPLICATE(1002004001, "已经存在名为【{}}】的角色"), + ROLE_CODE_DUPLICATE(1002004002, "已经存在编码为【{}}】的角色"), + ROLE_CAN_NOT_UPDATE_SYSTEM_TYPE_ROLE(1002004004, "不能修改类型为系统内置的角色"), + ROLE_CAN_NOT_DELETE_SYSTEM_TYPE_ROLE(1002004005, "不能删除类型为系统内置的角色"), + + // ========== 数据字典模块 1002005000 ========== +// DATA_DICT_EXISTS(1002005000, "该数据字典已经存在"), +// DATA_DICT_NOT_EXISTS(1002005001, "该数据字典不存在"), + + // ========== 短信模板 1002006000 ========== + SMS_PLATFORM_FAIL(1002006000, "短信平台调用失败【具体错误会动态替换】"), + SMS_SIGN_NOT_EXISTENT(1002006001, "短信签名不存在"), + SMS_SIGN_IS_EXISTENT(1002006002, "短信签名已存在"), + SMS_TEMPLATE_NOT_EXISTENT(1002006020, "短信签名不存在"), + SMS_TEMPLATE_IS_EXISTENT(1002006021, "短信签名不存在"), + SMS_NOT_SEND_CLIENT(1002006030, "短信没有发送的client"), + + // ========== 部门模块 1002007000 ========== +// DEPT_SAME_LEVEL_NAME_EXITS(1002007001,"当前级别部门名字已存在"), +// DEPT_PARENT_NOT_EXITS(1002007002,"父级部门不存在"), +// DEPT_NOT_EXITS(1002007003, "当前部门不存在"), +// DEPT_EXITS_CHILDREN(1002007004, "当前部门存在子部门"), +// DEPT_PARENT_NOT_LEGAL(1002007005, "父级部门不合法"), + + // ========== 授权模块 1002008000 ========== + AUTHORIZATION_PERMISSION_DENY(1002008001, "没有该操作权限"), + AUTHORIZATION_DEMO_PERMISSION_DENY(1002008002, "演示账号,暂不允许写操作。欢迎加入我们的交流群:http://t.cn/EKEr5WE"), + AUTHORIZATION_ROLE_ASSIGN_RESOURCE_NOT_EXISTS(1002004001, "分配角色资源时,有资源不存在"), + + // ========== 错误码模块 1002009000 ========== + ERROR_CODE_NOT_EXISTS(1002009000, "错误码不存在"), + ERROR_CODE_DUPLICATE(1002009001, "已经存在编码为【{}}】的错误码"), + ERROR_CAN_NOT_UPDATE_SYSTEM_TYPE_ERROR(1002004003, "不能修改类型为系统内置的错误码"), + ; + + + private final int code; + private final String message; + + SystemErrorCodeEnum(int code, String message) { + this.code = code; + this.message = message; + } + + @Override + public int getCode() { + return code; + } + + @Override + public String getMessage() { + return message; + } + + // TODO: 2020-05-22 封装成start的时候,直接在start中定义一个统一的枚举,从中取值; + @Override + public int getGroup() { + return 0; + } + + +} diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/oauth/OAuth2Rpc.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/oauth/OAuth2Rpc.java new file mode 100644 index 000000000..fcfacb25d --- /dev/null +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/oauth/OAuth2Rpc.java @@ -0,0 +1,4 @@ +package cn.iocoder.mall.systemservice.rpc.oauth; + +public interface OAuth2Rpc { +} diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/package-info.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/package-info.java new file mode 100644 index 000000000..e75b646bd --- /dev/null +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.mall.systemservice.rpc; diff --git a/system-service-project/system-service-app/pom.xml b/system-service-project/system-service-app/pom.xml new file mode 100644 index 000000000..506947a42 --- /dev/null +++ b/system-service-project/system-service-app/pom.xml @@ -0,0 +1,85 @@ + + + + system-service-project + cn.iocoder.mall + 1.0-SNAPSHOT + + 4.0.0 + + system-service-service + + + + com.alibaba.cloud + spring-cloud-starter-dubbo + + + + + cn.iocoder.mall + system-service-api + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + mysql + mysql-connector-java + + + + org.springframework + spring-tx + + + org.springframework + spring-jdbc + + + com.alibaba + druid-spring-boot-starter + + + + cn.iocoder.mall + mall-spring-boot-starter-mybatis + + + + + org.projectlombok + lombok + + + + org.mapstruct + mapstruct + + + org.mapstruct + mapstruct-jdk8 + + + + + + + + + + + + + + + + + diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/SystemServiceApplication.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/SystemServiceApplication.java new file mode 100644 index 000000000..13349c96a --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/SystemServiceApplication.java @@ -0,0 +1,13 @@ +package cn.iocoder.mall.systemservice; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SystemServiceApplication { + + public static void main(String[] args) { + SpringApplication.run(SystemServiceApplication.class, args); + } + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/config/DatabaseConfiguration.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/config/DatabaseConfiguration.java new file mode 100644 index 000000000..a83ca5f10 --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/config/DatabaseConfiguration.java @@ -0,0 +1,28 @@ +package cn.iocoder.mall.systemservice.config; + +import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector; +import com.baomidou.mybatisplus.core.injector.ISqlInjector; +import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Configuration +@MapperScan("cn.iocoder.mall.systemservice.dal.mysql.mapper") // 扫描对应的 Mapper 接口 +@EnableTransactionManagement(proxyTargetClass = true) // 启动事务管理。 +public class DatabaseConfiguration { + + // 数据库连接池 Druid + + @Bean + public ISqlInjector sqlInjector() { + return new DefaultSqlInjector(); // MyBatis Plus 逻辑删除 + } + + @Bean + public PaginationInterceptor paginationInterceptor() { + return new PaginationInterceptor(); // MyBatis Plus 分页插件 + } + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/config/ServiceExceptionConfiguration.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/config/ServiceExceptionConfiguration.java new file mode 100644 index 000000000..493f2a351 --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/config/ServiceExceptionConfiguration.java @@ -0,0 +1,20 @@ +package cn.iocoder.mall.systemservice.config; + +import cn.iocoder.common.framework.util.ServiceExceptionUtil; +import cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.event.EventListener; + +import java.util.Arrays; + +@Configuration +public class ServiceExceptionConfiguration { + + @EventListener(ApplicationReadyEvent.class) + public void initMessages() { + Arrays.stream(SystemErrorCodeEnum.values()).forEach( + item -> ServiceExceptionUtil.put(item.getCode(), item.getMessage())); + } + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/oauth/OAuth2RpcImpl.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/oauth/OAuth2RpcImpl.java new file mode 100644 index 000000000..22d4933b3 --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/oauth/OAuth2RpcImpl.java @@ -0,0 +1,7 @@ +package cn.iocoder.mall.systemservice.rpc.oauth; + +import org.apache.dubbo.config.annotation.Service; + +@Service(version = "${dubbo.provider.OAuth2Rpc.version}", validation = "false") +public class OAuth2RpcImpl implements OAuth2Rpc { +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/package-info.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/package-info.java new file mode 100644 index 000000000..e75b646bd --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.mall.systemservice.rpc; diff --git a/system-service-project/system-service-app/src/main/resources/application-dev.yaml b/system-service-project/system-service-app/src/main/resources/application-dev.yaml new file mode 100644 index 000000000..cfae12b0d --- /dev/null +++ b/system-service-project/system-service-app/src/main/resources/application-dev.yaml @@ -0,0 +1,20 @@ +spring: + # 数据源配置项 + datasource: + url: jdbc:mysql://400-infra.server.iocoder.cn:3306/mall_system?useSSL=false&useUnicode=true&characterEncoding=UTF-8 + driver-class-name: com.mysql.jdbc.Driver + username: root + password: 3WLiVUBEwTbvAfsh + # Spring Cloud 配置项 + cloud: + nacos: + # Spring Cloud Nacos Discovery 配置项 + discovery: + server-addr: 400-infra.server.iocoder.cn:8848 # Nacos 服务器地址 + namespace: dev # Nacos 命名空间 + +# Dubbo 配置项 +dubbo: + # Dubbo 注册中心 + registry: + address: spring-cloud://400-infra.server.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址 diff --git a/system-service-project/system-service-app/src/main/resources/application-local.yaml b/system-service-project/system-service-app/src/main/resources/application-local.yaml new file mode 100644 index 000000000..bf97cae95 --- /dev/null +++ b/system-service-project/system-service-app/src/main/resources/application-local.yaml @@ -0,0 +1,20 @@ +spring: + # 数据源配置项 + datasource: + url: jdbc:mysql://400-infra.server.iocoder.cn:3306/mall_system?useSSL=false&useUnicode=true&characterEncoding=UTF-8 + driver-class-name: com.mysql.jdbc.Driver + username: root + password: 3WLiVUBEwTbvAfsh + # Spring Cloud 配置项 + cloud: + nacos: + # Spring Cloud Nacos Discovery 配置项 + discovery: + server-addr: 400-infra.server.iocoder.cn:8848 # Nacos 服务器地址 + namespace: local # Nacos 命名空间 + +# Dubbo 配置项 +dubbo: + # Dubbo 注册中心 + registry: + address: spring-cloud://400-infra.server.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址 diff --git a/system-service-project/system-service-app/src/main/resources/application.yaml b/system-service-project/system-service-app/src/main/resources/application.yaml new file mode 100644 index 000000000..d3840c46d --- /dev/null +++ b/system-service-project/system-service-app/src/main/resources/application.yaml @@ -0,0 +1,37 @@ +spring: + # Application 的配置项 + application: + name: system-service + # Profile 的配置项 + profiles: + active: local + +# MyBatis Plus 配置项 +mybatis-plus: + configuration: + map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。 + global-config: + db-config: + id-type: auto + logic-delete-value: 1 # 逻辑已删除值(默认为 1) + logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) + mapper-locations: classpath*:mapper/*.xml + type-aliases-package: cn.iocoder.mall.systemservice.dal.mysql.dataobject + +# Dubbo 配置项 +dubbo: + # Spring Cloud Alibaba Dubbo 专属配置 + cloud: + subscribed-services: '' # 设置订阅的应用列表,默认为 * 订阅所有应用 + # Dubbo 提供者的协议 + protocol: + name: dubbo + port: -1 + # Dubbo 提供服务的扫描基础包 + scan: + base-packages: cn.iocoder.mall.systemservice.rpc + # Dubbo 服务提供者的配置 + provider: + filter: -exception + OAuth2Rpc: + version: 1.0.0 diff --git a/user/pom.xml b/user/pom.xml index 6418775b8..a4d6449cd 100644 --- a/user/pom.xml +++ b/user/pom.xml @@ -15,7 +15,6 @@ - user-application user-rest user-rpc user-rpc-api diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/UserApplication.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/UserApplication.java deleted file mode 100644 index 3f2c76258..000000000 --- a/user/user-application/src/main/java/cn/iocoder/mall/user/application/UserApplication.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.mall.user.application; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.context.config.ConfigFileApplicationListener; - -@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.system"}) -public class UserApplication { - - /** - * 设置需要读取的配置文件的名字。 - * 基于 {@link org.springframework.boot.context.config.ConfigFileApplicationListener#CONFIG_NAME_PROPERTY} 实现。 - */ - private static final String CONFIG_NAME_VALUE = "biz,rest,rpc,application"; - - public static void main(String[] args) { - // 设置环境变量 - System.setProperty(ConfigFileApplicationListener.CONFIG_NAME_PROPERTY, CONFIG_NAME_VALUE); - - // 启动 Spring Boot 应用 - SpringApplication.run(UserApplication.class, args); - } - -} diff --git a/user/user-application/src/main/resources/application.yaml b/user/user-application/src/main/resources/application.yaml deleted file mode 100644 index d4ef580c6..000000000 --- a/user/user-application/src/main/resources/application.yaml +++ /dev/null @@ -1,8 +0,0 @@ -spring: - # Application 的配置项 - application: - name: user-application - # Profile 的配置项 - profiles: - active: local -