Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yxx-z authored Aug 26, 2023
0 parents commit 0b1ae04
Show file tree
Hide file tree
Showing 171 changed files with 12,071 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### IntelliJ IDEA ###
.idea

**/target/
logs/
**/**/**.iml
**/.DS_Store
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 赵日天

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
105 changes: 105 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# base-springboot

## SpringBoot开发模版

### 功能
* 注册、登录、用户详情、接口日志、ip属地、发送邮件、修改密码、找回密码、用户权限、角色、菜单、ip异常邮件提醒

***
### 准备
* jdk17
* maven3.5+
* redis
* mysql8

***
### 使用
* 数据库新建utf8mb4数据库,运行db文件夹下的db.sql文件。
* 更改application-dev.yml中mysql数据库连接配置、redis连接配置
* resources下的ip2region.xdb文件放在jar同通目录下 例:jar包放在/usr/local/business/ 则该文件同样放在该目录


***
### 框架选型:
<p>
&nbsp;&nbsp;&nbsp;&nbsp;SpringBoot + Mybatis-plus + Redis <br>
&nbsp;&nbsp;&nbsp;&nbsp;登录框架 Sa-Token <a href="https://sa-token.cc/doc.html#/" style="text-decoration: none">框架文档</a>
</p>

#### 项目结构:
```
base:
-- admin:
-- business:
-- common:
-- common-core
-- common-framework
```
common为公共包,包含core和framework两个子包:
<p>
&nbsp;&nbsp;&nbsp;&nbsp;common-core主要是自定义注解、constant、枚举类、自定义异常、properties、utils等
</p>
<p>
&nbsp;&nbsp;&nbsp;&nbsp;common-framework主要是filter、listener、日志打印、日志记录、Mybatis-plus配置、统一异常处理等
</p>
admin 为后台管理模块包,处理管理后台逻辑。
business为业务包,用来处理业务。不赘述。

****
#### 自定义注解:

@ResponseResult

<p>
&nbsp;&nbsp;&nbsp;&nbsp;用来封装返回值,可放在controller上,或者controller中的单个方法上。
</p>

@OperationLog

<p>
&nbsp;&nbsp;&nbsp;&nbsp;用来记录接口日志,包含请求接口名称、用户id、ip、入参、异常信息等,可放在controller中的单个方法上。
</p>

@ReleaseToken

<p>
&nbsp;&nbsp;&nbsp;&nbsp;用来跳过token校验,可放在controller中的单个方法上。
</p>

@SearchDate
<p>
&nbsp;&nbsp;&nbsp;&nbsp;加在Date类型上,搜索条件开始时间结束时间,自动拼接开始时间00:00:00和结束时间23:59:59
</p>

***
#### 常用utils:

LoginUtils
<p>
&nbsp;&nbsp;&nbsp;&nbsp;登录相关utils,可获取用户基本信息,角色,token等
</p>

ApiAssert
<p>
&nbsp;&nbsp;&nbsp;&nbsp;断言工具类,以断言方式抛出自定义异常
</p>

EnuUtils
<p>
&nbsp;&nbsp;&nbsp;&nbsp;枚举工具类,判断指定code是否属于指定枚举类中的数据
</p>

ApplicationUtils
<p>
&nbsp;&nbsp;&nbsp;程序工具类,可获取SpringBean,程序上下文等
</p>

TreeUtil
<p>
&nbsp;&nbsp;&nbsp;通用树状工具类
</p>

MailUtils
<p>
&nbsp;&nbsp;&nbsp;发送邮件工具
</p>
4 changes: 4 additions & 0 deletions admin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# 工程简介

# 延伸阅读

84 changes: 84 additions & 0 deletions admin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>admin</artifactId>
<name>admin</name>
<description>admin</description>

<parent>
<artifactId>base</artifactId>
<groupId>com.yxx</groupId>
<version>1.0.0</version>
</parent>

<profiles>
<profile>
<id>dev</id>
<properties>
<!-- 命名要和application-dev.yml配置文件-后面的一致 -->
<profileActive>dev</profileActive>
</properties>
<!-- 默认激活环境 -->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>prod</id>
<properties>
<profileActive>prod</profileActive>
</properties>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>com.yxx</groupId>
<artifactId>common-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.yxx</groupId>
<artifactId>common-framework</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<mainClass>com.yxx.admin.AdminApplication</mainClass>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
15 changes: 15 additions & 0 deletions admin/src/main/java/com/yxx/admin/AdminApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.yxx.admin;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages = {"com.yxx.admin", "com.yxx.common", "com.yxx.framework"})
@MapperScan("com.yxx.admin.mapper")
public class AdminApplication {

public static void main(String[] args) {
SpringApplication.run(AdminApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.yxx.admin.controller;

import com.yxx.admin.model.request.LoginReq;
import com.yxx.admin.model.response.LoginRes;
import com.yxx.admin.service.AdminUserService;
import com.yxx.common.annotation.auth.ReleaseToken;
import com.yxx.common.annotation.log.OperationLog;
import com.yxx.common.annotation.response.ResponseResult;
import com.yxx.common.utils.satoken.StpAdminUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.validation.Valid;

/**
* @author yxx
* @since 2023-05-17 10:02
*/
@Slf4j
@Validated
@ResponseResult
@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
public class AdminAuthController {
private final AdminUserService adminUserService;

/**
* 登录
*
* @param request 请求
* @return {@link LoginRes }
* @author yxx
*/
@ReleaseToken
@OperationLog(module = "鉴权模块", title = "pc登录")
@PostMapping("/login")
public LoginRes login(@Valid @RequestBody LoginReq request) {
return adminUserService.login(request);
}

/**
* 注销
*
* @author yxx
*/
@OperationLog(module = "鉴权模块", title = "pc退出")
@PostMapping("/logout")
public void logout() {
StpAdminUtil.logout();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.yxx.admin.controller;

import com.yxx.admin.model.request.*;
import com.yxx.admin.service.AdminUserService;
import com.yxx.common.annotation.auth.ReleaseToken;
import com.yxx.common.annotation.log.OperationLog;
import com.yxx.common.annotation.response.ResponseResult;
import com.yxx.common.core.model.LoginUser;
import com.yxx.common.utils.auth.LoginAdminUtils;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
* @author yxx
* @since 2022-11-12 02:07
*/
@Slf4j
@Validated
@ResponseResult
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class AdminUserController {

private final AdminUserService adminUserService;

/**
* 获取用户信息
*
* @return {@link LoginUser }
* @author yxx
*/
@OperationLog(module = "用户模块", title = "获取用户信息")
@GetMapping("/info")
public LoginUser info() {
Long userId = LoginAdminUtils.getUserId();
log.info("userId为[{}]", userId);
return LoginAdminUtils.getLoginUser();
}

/**
* 发送重置密码邮件
*
* @param req 要求事情
* @return {@link Boolean }
* @author yxx
*/
@ReleaseToken
@OperationLog(module = "用户模块", title = "发送重置密码邮件")
@PostMapping("/resetPwdEmail")
public Boolean resetPwdEmail(@Valid @RequestBody ResetPwdEmailReq req){
return adminUserService.resetPwdEmail(req);
}

/**
* 重置密码
*
* @param req 要求事情
* @return {@link Boolean }
* @author yxx
*/
@ReleaseToken
@OperationLog(module = "用户模块", title = "重置密码")
@PostMapping("/resetPwd")
public Boolean resetPwd(@Valid @RequestBody ResetPwdReq req){
return adminUserService.resetPwd(req);
}

/**
* 修改密码
*
* @param req 要求事情
* @return {@link Boolean }
* @author yxx
*/
@OperationLog(module = "用户模块", title = "修改密码")
@PostMapping("/editPwd")
public Boolean editPwd(@Valid @RequestBody EditPwdReq req){
return adminUserService.editPwd(req);
}

}
Loading

0 comments on commit 0b1ae04

Please sign in to comment.