# cobra **Repository Path**: peekpop/cobra ## Basic Information - **Project Name**: cobra - **Description**: cobra是一套电商系统,包括前台商城系统及后台管理系统,使用Gradle构建,基于Java8+、SpringBoot2.2.7.RELEASE、SpringCloud Hoxton.SR5、SpringCloud Alibaba 2.2.1.RELEASE、MyBatis3.3.1等核心技术体系实现的一套分布式微服务架构,包含OAuth2.0/jwt权限认证、分布式事务、熔断降级、分布式锁、链路追踪、MQ等,支持Docker容器化部署、持续继承等敏捷开发。 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2020-06-12 - **Last Updated**: 2023-06-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # cobra #### 介绍 cobra是一套电商系统,包括前台商城系统及后台管理系统,使用Gradle构建,基于Java8+、SpringBoot2.2.8.RELEASE、SpringCloud Hoxton.SR5、SpringCloud Alibaba 2.2.1.RELEASE、MyBatis3.3.1等核心技术体系实现的一套分布式微服务架构,包含OAuth2.0/jwt权限认证、分布式事务、熔断降级、分布式锁、链路追踪、MQ等,支持Docker容器化部署、持续继承等敏捷开发。 #### 软件架构 软件架构说明 #### 安装教程 1. xxxx 2. xxxx 3. xxxx #### 使用说明 1. xxxx 2. xxxx 3. xxxx #### 项目常用软件 1. SwitchHosts 2. xshell/xftp 3. VirtualBox 4. seata 5. nacos 6. navicat 7. sentinel 8. vue-devtools 9. MySQL #### 模块说明 cobra -- 父项目,公共依赖 │ ├─biz -- 业务模块一级工程 │ │ ├─cobra-gateway -- api网关[8888] │ │ ├─cobra-uaa -- 认证中心[8801] │ │ ├─cobra-userVO -- 用户服务[8811] │ │ ├─cobra-dal -- 数据统一访问服务[8815] │ │ ├─cobra-admin -- 后台管理服务[8807] │ │ ├─cobra-portal -- 前端管理服务[8881] │ ├─common -- 通用模块一级工程 │ │ ├─common-api-client -- 封装Feign操作逻辑 │ │ ├─common-cache -- 封装Redis通用操作逻辑 │ │ ├─common-core -- 封装通用操作逻辑 │ │ ├─common-security -- 封装springsecurity常用操作逻辑 │ │ ├─common-swagger -- 封装swagger通用操作逻辑 │ │ ├─common-config -- 封装配置信息 #### SPU和SKU概念 > **SPU = Standard Product Unit (标准产品单温)** - 概念 : SPU 是商品信息聚合的最小单位,是一组可复用、易检索的标准化信息的集合,该集合描述了一个产品的特性。 - 通俗点讲,属性值、特性相同的货品就可以称为一个 SPU ==同款商品的公共属性抽取== 例如:**华为P30 就是一个 SPU** > **SKU=stock keeping unit( 库存量单位)** - SKU 即库存进出计量的单位, 可以是以件、盒、托盘等为单位。 - SKU 是物理上不可分割的最小存货单元。在使用时要根据不同业态,不同管理模式来处理。 - 在服装、鞋类商品中使用最多最普遍。 例如:**华为P30 红色 64G 就是一个 SKU** ==某个库存单位的商品独有属性(某个商品的独有属性)== #### 领域模型介绍 - entity: xxxDO对应数据库表结构,一般为表名称; - model: xxxVO展示对象,一般为网页名称; - dto: xxxDTO用于数据传递(接口入参和接口返回值都可以),一般为业务领域相关名称。 ```java // controller层: public List getUsers(UserDTO userDto); // Service层: List getUsers(UserDTO userDto); // DAO层: List getUsers(UserDO userDo); ``` #### 项目细节配置 ##### build.gradle配置文件 ```groovy // 配置gradle脚本执行时所需的依赖 buildscript { repositories { // 本地仓库 mavenLocal() // 阿里云Maven远程仓库 maven { url "http://maven.aliyun.com/nexus/content/groups/public" } // maven中央仓库 mavenCentral() // 和maven中央仓库一样的另一个依赖管理仓库,主要是java jcenter() } // 版本管理 ext { set('springBootAdminVersion', "2.2.3") } // 相关依赖 dependencies { //spring-boot插件 classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootAdminVersion}") } } // 定义插件及版本 plugins { // springboot插件 id 'org.springframework.boot' version '2.2.7.RELEASE' // 实现maven统一管理 id 'io.spring.dependency-management' version '1.0.9.RELEASE' } // 所有项目通用配置 包括rootProject allprojects { // java插件 apply plugin: 'java' // idea插件 apply plugin: 'idea' // 版本管理插件 apply plugin: 'io.spring.dependency-management' // springboot插件 apply plugin: 'org.springframework.boot' group = 'com.assuse.cobra' version = '1.0.0-SNAPSHOT' sourceCompatibility = '1.8' // 定义仓库 repositories { // 本地仓库 mavenLocal() // 阿里云Maven远程仓库 maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } // maven中央仓库 mavenCentral() // 和maven中央仓库一样的另一个依赖管理仓库,主要是java jcenter() } // 下载gradle的源码 idea { module { downloadJavadoc = true downloadSources = true } } } // 所有子项目通用配置 不包括rootProject subprojects { // 版本管理 ext { set('springBootAdminVersion', "2.2.3") set('springCloudAlibabaVersion', "2.2.1.RELEASE") set('springCloudVersion', "Hoxton.SR5") set('druidVersion', "1.1.20") } // springboot、cloud及alibaba-cloud版本管理 dependencyManagement { // 导入maven依赖管理的bom imports { mavenBom "de.codecentric:spring-boot-admin-dependencies:${springBootAdminVersion}" mavenBom "com.alibaba.cloud:spring-cloud-alibaba-dependencies:${springCloudAlibabaVersion}" mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" } } /* * 此处为所有模块的公共依赖
* 注意:此处有些依赖不在指定版本,已经由上面的dependencyManagement管理 **/ dependencies { runtimeOnly 'mysql:mysql-connector-java' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' implementation 'org.springframework.cloud:spring-cloud-starter-openfeign' compile "com.alibaba:druid:${druidVersion}" } // 全局设置依赖 configurations { developmentOnly runtimeClasspath { extendsFrom developmentOnly } compileOnly { extendsFrom annotationProcessor } } // 配置junit test { useJUnitPlatform() } /** * 根据环境打包默认dev开发环境,命令:./gradlew -x test clean bootJar -Denv=dev */ /* def env = System.getProperty("env") ?: "dev" processResources { filter ReplaceTokens, tokens: [env: env] }*/ } ``` ##### 集成Swagger2 1. 引入依赖 ```groovy ext{ set('swagger2Version',"2.9.2") set('swagger2UIVersion',"2.9.2") } dependencies { compile "io.springfox:springfox-swagger2:${swagger2Version}" compile "io.springfox:springfox-swagger-ui:${swagger2UIVersion}" } ``` 2. 编写Swagger2ApiConfig配置类 ```java @Configuration @EnableSwagger2 public class Swagger2Config implements WebMvcConfigurer { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) // 返回一个ApiSelectorBuilder实例控制哪些接口暴露给Swagger .select() // 加了 ApiOperation注解的类,才生成接口文档 .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) // 指定包下的类,才生成接口文档 // .apis(RequestHandlerSelectors.basePackage("com.assuse.cobra.controller")) .paths(PathSelectors.any()) .build(); } /** * 构建API基本信息 * * @return ApiInfo */ private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("Cobra商城") .description("Cobra前端文档") .termsOfServiceUrl("https://www.cobra.com") .contact("cobra") .version("1.0.0") .build(); } } ``` ##### MySQL驱动设置(springboot2.2+) - MySQL8.0驱动应选择```com.mysql.cj.jdbc.Driver``` - url应加上```serverTimezone=GMT%2B8``` ##### 常用依赖解释 - spring-cloud-starter-oauth2:它是```spring-cloud-starter-security、spring-security-oauth2、spring-security-jwt```这3个依赖的整合; ##### Spring Security详解 1 Spring Security中HttpSecurity和WebSecurity的区别? - WebSecurity不仅通过HttpSecurity定义某些请求的安全控制,也通过其他方式定义其他某些请求可以忽略安全控制; - HttpSecurity仅用于定义需要安全控制的请求(当然HttpSecurity也可以指定某些请求不需要安全控制); - 可以认为HttpSecurity是WebSecurity的一部分,WebSecurity是包含HttpSecurity的更大的一个概念; - 构建目标不同: - WebSecurity构建目标是整个Spring Security安全过滤器FilterChainProxy; - HttpSecurity构建目标仅仅是FilterChainProxy中的一个SecurityFilterChain. 2 Spring Security常用方法详解: 链接地址: https://blog.csdn.net/beeworkshop/article/details/104891562?utm_medium=distribute.pc_relevant_bbs_down.none-task-blog-baidujs-1.nonecase&depth_1-utm_source=distribute.pc_relevant_bbs_down.none-task-blog-baidujs-1.nonecase | 表达式 | 描述 | | :------| :------ | | hasRole([role]) | 当前用户是否拥有指定角色 | | hasAnyRole([role1,role2]) | 多个角色是一个以逗号分隔的字符串,如果当前用户拥有指定角色中的任意一个则返回true | | hasAuthority([auth]) | 等同于hasRole | | hasAnyAuthority([auth1, auth2]) | 等同于hasAnyRole | | Principle() | 代表当前用户的principle对象 | | authentication() | 直接从SecurityContext获取的当前Authentication对象 | | permitAll() | 总是返回true,表示允许所有访问 | | denyAll() | 总是返回false,表示拒绝所有的访问 | | isAnonymous() | 当前用户是否是一个匿名用户 | | isRememberMe() | 表示当前用户是否通过Remember-Me自动登录的 | | isAuthenticated() | 表示当前用户是否已经登录认证成功了 | | isFullyAuthenticated() | 如果当前用户既不是一个匿名用户又不是通过Remember-Me自动登录的则返回true | | hasPermission() | 使用扩展表达式需要实现PermissionEvaluator接口 | | anonymous() | 允许匿名用户访问 | | antMatchers() | 保护多个URL地址 | | antMatcher() | 保护一个URL地址 | ||| ||| ||| ||| ||| ||| #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 码云特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目 5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)