Skip to content

Commit

Permalink
Merge branch 'gin-vue-admin_v2_dev' of
Browse files Browse the repository at this point in the history
  • Loading branch information
krank666 committed May 20, 2020
2 parents a4683dc + cfdcd3d commit 2d7c6a7
Show file tree
Hide file tree
Showing 63 changed files with 366 additions and 348 deletions.
55 changes: 27 additions & 28 deletions server/api/v1/exa_breakpoint_continue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package v1
import (
"fmt"
"gin-vue-admin/global/response"
_ "gin-vue-admin/model/response"
resp "gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
Expand All @@ -29,34 +28,34 @@ func BreakpointContinue(c *gin.Context) {
_, FileHeader, err := c.Request.FormFile("file")
if err != nil {
response.FailWithMessage(err.Error(), c)
} else {
f, err := FileHeader.Open()
if err != nil {
response.FailWithMessage(err.Error(), c)
} else {
cen, _ := ioutil.ReadAll(f)
defer f.Close()
if flag := utils.CheckMd5(cen, chunkMd5); flag {
err, file := service.FindOrCreateFile(fileMd5, fileName, chunkTotal)
if err != nil {
response.FailWithMessage(err.Error(), c)
} else {
err, pathc := utils.BreakPointContinue(cen, fileName, chunkNumber, chunkTotal, fileMd5)
if err != nil {
response.FailWithMessage(err.Error(), c)
} else {
err = service.CreateFileChunk(file.ID, pathc, chunkNumber)
if err != nil {
response.FailWithMessage(err.Error(), c)
} else {
response.OkWithMessage("切片创建成功", c)
}
}
}
} else {
}
}
return
}
f, err := FileHeader.Open()
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
defer f.Close()
cen, _ := ioutil.ReadAll(f)
if flag := utils.CheckMd5(cen, chunkMd5); !flag {
return
}
err, file := service.FindOrCreateFile(fileMd5, fileName, chunkTotal)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, pathc := utils.BreakPointContinue(cen, fileName, chunkNumber, chunkTotal, fileMd5)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}

if err = service.CreateFileChunk(file.ID, pathc, chunkNumber); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
response.OkWithMessage("切片创建成功", c)
}

// @Tags ExaFileUploadAndDownload
Expand Down
4 changes: 2 additions & 2 deletions server/api/v1/exa_file_upload_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ func UploadFile(c *gin.Context) {
if err != nil {
response.FailWithMessage(fmt.Sprintf("上传文件失败,%v", err), c)
} else {
//文件上传后拿到文件路径
// 文件上传后拿到文件路径
err, filePath, key := utils.Upload(header)
if err != nil {
response.FailWithMessage(fmt.Sprintf("接收返回值失败,%v", err), c)
} else {
//修改数据库后得到修改后的user并且返回供前端使用
// 修改数据库后得到修改后的user并且返回供前端使用
var file model.ExaFileUploadAndDownload
file.Url = filePath
file.Name = header.Filename
Expand Down
2 changes: 1 addition & 1 deletion server/api/v1/sys_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func DeleteApi(c *gin.Context) {
}
}

//条件搜索后端看此api
// 条件搜索后端看此api

// @Tags SysApi
// @Summary 分页获取API列表
Expand Down
4 changes: 2 additions & 2 deletions server/api/v1/sys_authority.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func DeleteAuthority(c *gin.Context) {
response.FailWithMessage(AuthorityIdVerifyErr.Error(), c)
return
}
//删除角色之前需要判断是否有用户正在使用此角色
// 删除角色之前需要判断是否有用户正在使用此角色
err := service.DeleteAuthority(&a)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
Expand Down Expand Up @@ -127,7 +127,7 @@ func UpdateAuthority(c *gin.Context) {
if err != nil {
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
} else {
response.OkWithData(resp.SysAuthorityResponse{authority}, c)
response.OkWithData(resp.SysAuthorityResponse{Authority: authority}, c)
}
}

Expand Down
12 changes: 6 additions & 6 deletions server/api/v1/sys_auto_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ func CreateTemp(c *gin.Context) {
var a model.AutoCodeStruct
_ = c.ShouldBindJSON(&a)
AutoCodeVerify := utils.Rules{
"Abbreviation": {utils.NotEmpty()},
"StructName": {utils.NotEmpty()},
"PackageName": {utils.NotEmpty()},
"Fields": {utils.NotEmpty()},
"Abbreviation": {utils.NotEmpty()},
"StructName": {utils.NotEmpty()},
"PackageName": {utils.NotEmpty()},
"Fields": {utils.NotEmpty()},
}
WKVerifyErr := utils.Verify(a, AutoCodeVerify)
if WKVerifyErr!=nil {
if WKVerifyErr != nil {
response.FailWithMessage(WKVerifyErr.Error(), c)
return
}
Expand Down Expand Up @@ -80,7 +80,7 @@ func CreateTemp(c *gin.Context) {
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
os.Remove("./ginvueadmin.zip")
} else {
c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", "ginvueadmin.zip")) //fmt.Sprintf("attachment; filename=%s", filename)对下载的文件重命名
c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", "ginvueadmin.zip")) // fmt.Sprintf("attachment; filename=%s", filename)对下载的文件重命名
c.Writer.Header().Add("Content-Type", "application/json")
c.Writer.Header().Add("success", "true")
c.File("./ginvueadmin.zip")
Expand Down
2 changes: 1 addition & 1 deletion server/api/v1/sys_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func AddBaseMenu(c *gin.Context) {
var menu model.SysBaseMenu
_ = c.ShouldBindJSON(&menu)
MenuVerify := utils.Rules{
"Path": {"notEmpty"},
"Path": {utils.NotEmpty()},
"ParentId": {utils.NotEmpty()},
"Name": {utils.NotEmpty()},
"Component": {utils.NotEmpty()},
Expand Down
2 changes: 1 addition & 1 deletion server/api/v1/sys_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func SetSystemConfig(c *gin.Context) {
}
}

//本方法开发中 开发者windows系统 缺少linux系统所需的包 因此搁置
// 本方法开发中 开发者windows系统 缺少linux系统所需的包 因此搁置
// @Tags system
// @Summary 设置配置文件内容
// @Security ApiKeyAuth
Expand Down
99 changes: 48 additions & 51 deletions server/api/v1/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,69 +80,66 @@ func Login(c *gin.Context) {

}

//登录以后签发jwt
// 登录以后签发jwt
func tokenNext(c *gin.Context, user model.SysUser) {
j := &middleware.JWT{
[]byte(global.GVA_CONFIG.JWT.SigningKey), // 唯一签名
SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey), // 唯一签名
}
clams := request.CustomClaims{
UUID: user.UUID,
ID: user.ID,
NickName: user.NickName,
AuthorityId: user.AuthorityId,
StandardClaims: jwt.StandardClaims{
NotBefore: int64(time.Now().Unix() - 1000), // 签名生效时间
ExpiresAt: int64(time.Now().Unix() + 60*60*24*7), // 过期时间 一周
Issuer: "qmPlus", //签名的发行者
NotBefore: time.Now().Unix() - 1000, // 签名生效时间
ExpiresAt: time.Now().Unix() + 60*60*24*7, // 过期时间 一周
Issuer: "qmPlus", // 签名的发行者
},
}
token, err := j.CreateToken(clams)
if err != nil {
response.FailWithMessage("获取token失败", c)
return
}
if !global.GVA_CONFIG.System.UseMultipoint {
response.OkWithData(resp.LoginResponse{
User: user,
Token: token,
ExpiresAt: clams.StandardClaims.ExpiresAt * 1000,
}, c)
return
}
var loginJwt model.JwtBlacklist
loginJwt.Jwt = token
err, jwtStr := service.GetRedisJWT(user.Username)
if err == redis.Nil {
if err := service.SetRedisJWT(loginJwt, user.Username); err != nil {
response.FailWithMessage("设置登录状态失败", c)
return
}
response.OkWithData(resp.LoginResponse{
User: user,
Token: token,
ExpiresAt: clams.StandardClaims.ExpiresAt * 1000,
}, c)
} else if err != nil {
response.FailWithMessage(fmt.Sprintf("%v", err), c)
} else {
if global.GVA_CONFIG.System.UseMultipoint {
var loginJwt model.JwtBlacklist
loginJwt.Jwt = token
err, jwtStr := service.GetRedisJWT(user.Username)
if err == redis.Nil {
err2 := service.SetRedisJWT(loginJwt, user.Username)
if err2 != nil {
response.FailWithMessage("设置登录状态失败", c)
} else {
response.OkWithData(resp.LoginResponse{
User: user,
Token: token,
ExpiresAt: clams.StandardClaims.ExpiresAt * 1000,
}, c)
}
} else if err != nil {
response.FailWithMessage(fmt.Sprintf("%v", err), c)
} else {
var blackJWT model.JwtBlacklist
blackJWT.Jwt = jwtStr
err3 := service.JsonInBlacklist(blackJWT)
if err3 != nil {
response.FailWithMessage("jwt作废失败", c)
} else {
err2 := service.SetRedisJWT(loginJwt, user.Username)
if err2 != nil {
response.FailWithMessage("设置登录状态失败", c)
} else {
response.OkWithData(resp.LoginResponse{
User: user,
Token: token,
ExpiresAt: clams.StandardClaims.ExpiresAt * 1000,
}, c)
}
}
}
} else {
response.OkWithData(resp.LoginResponse{
User: user,
Token: token,
ExpiresAt: clams.StandardClaims.ExpiresAt * 1000,
}, c)
var blackJWT model.JwtBlacklist
blackJWT.Jwt = jwtStr
if err := service.JsonInBlacklist(blackJWT); err != nil {
response.FailWithMessage("jwt作废失败", c)
return
}
if err := service.SetRedisJWT(loginJwt, user.Username); err != nil {
response.FailWithMessage("设置登录状态失败", c)
return
}
response.OkWithData(resp.LoginResponse{
User: user,
Token: token,
ExpiresAt: clams.StandardClaims.ExpiresAt * 1000,
}, c)
}
}

Expand Down Expand Up @@ -189,21 +186,21 @@ type UserHeaderImg struct {
// @Router /user/uploadHeaderImg [post]
func UploadHeaderImg(c *gin.Context) {
claims, _ := c.Get("claims")
//获取头像文件
// 获取头像文件
// 这里我们通过断言获取 claims内的所有内容
waitUse := claims.(*request.CustomClaims)
uuid := waitUse.UUID
_, header, err := c.Request.FormFile("headerImg")
//便于找到用户 以后从jwt中取
// 便于找到用户 以后从jwt中取
if err != nil {
response.FailWithMessage(fmt.Sprintf("上传文件失败,%v", err), c)
} else {
//文件上传后拿到文件路径
// 文件上传后拿到文件路径
err, filePath, _ := utils.Upload(header)
if err != nil {
response.FailWithMessage(fmt.Sprintf("接收返回值失败,%v", err), c)
} else {
//修改数据库后得到修改后的user并且返回供前端使用
// 修改数据库后得到修改后的user并且返回供前端使用
err, user := service.UploadHeaderImg(uuid, filePath)
if err != nil {
response.FailWithMessage(fmt.Sprintf("修改数据库链接失败,%v", err), c)
Expand Down
10 changes: 5 additions & 5 deletions server/api/v1/sys_work_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ func CreateWorkFlow(c *gin.Context) {
var wk model.SysWorkflow
_ = c.ShouldBindJSON(&wk)
WKVerify := utils.Rules{
"WorkflowNickName": {utils.NotEmpty()},
"WorkflowName": {utils.NotEmpty()},
"WorkflowDescription": {utils.NotEmpty()},
"WorkflowStepInfo": {utils.NotEmpty()},
"WorkflowNickName": {utils.NotEmpty()},
"WorkflowName": {utils.NotEmpty()},
"WorkflowDescription": {utils.NotEmpty()},
"WorkflowStepInfo": {utils.NotEmpty()},
}
WKVerifyErr := utils.Verify(wk, WKVerify)
if WKVerifyErr!=nil {
if WKVerifyErr != nil {
response.FailWithMessage(WKVerifyErr.Error(), c)
return
}
Expand Down
4 changes: 2 additions & 2 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ type Redis struct {
type Qiniu struct {
AccessKey string `mapstructure:"access-key" json:"accessKey" yaml:"access-key"`
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"`
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"`
ImgPath string `mapstructure:"img-path" json:"imgPath" yaml:"img-path"`
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"`
ImgPath string `mapstructure:"img-path" json:"imgPath" yaml:"img-path"`
}

type Captcha struct {
Expand Down
4 changes: 2 additions & 2 deletions server/global/response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ func FailWithMessage(message string, c *gin.Context) {
}

func FailWithDetailed(code int, data interface{}, message string, c *gin.Context) {
Result(code, data, message, c )
}
Result(code, data, message, c)
}
2 changes: 1 addition & 1 deletion server/initialize/db_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"gin-vue-admin/model"
)

//注册数据库表专用
// 注册数据库表专用
func DBTables() {
db := global.GVA_DB
db.AutoMigrate(model.SysUser{},
Expand Down
2 changes: 1 addition & 1 deletion server/initialize/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
)

//初始化数据库并产生数据库全局变量
// 初始化数据库并产生数据库全局变量
func Mysql() {
admin := global.GVA_CONFIG.Mysql
if db, err := gorm.Open("mysql", admin.Username+":"+admin.Password+"@("+admin.Path+")/"+admin.Dbname+"?"+admin.Config); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions server/initialize/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"github.com/swaggo/gin-swagger/swaggerFiles"
)

//初始化总路由
// 初始化总路由

func Routers() *gin.Engine {
var Router = gin.Default()
//Router.Use(middleware.LoadTls()) // 打开就能玩https了
// Router.Use(middleware.LoadTls()) // 打开就能玩https了
global.GVA_LOG.Debug("use middleware logger")
// 跨域
Router.Use(middleware.Cors())
Expand Down
Loading

0 comments on commit 2d7c6a7

Please sign in to comment.