Skip to content

Commit 9fc2472

Browse files
author
奇淼(piexlmax
authored
Merge branch 'develop' into develop
2 parents 8cfb4c6 + 4b03d2c commit 9fc2472

39 files changed

+719
-384
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
44
patreon: # Replace with a single Patreon username
5-
open_collective: # Replace with a single Open Collective username
5+
open_collective: gin-vue-admin
66
ko_fi: # Replace with a single Ko-fi username
77
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
88
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry

server/api/v1/exa_excel.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package v1
2+
3+
import (
4+
"gin-vue-admin/global"
5+
"gin-vue-admin/model"
6+
"gin-vue-admin/model/response"
7+
"gin-vue-admin/service"
8+
"gin-vue-admin/utils"
9+
"github.com/gin-gonic/gin"
10+
"go.uber.org/zap"
11+
)
12+
13+
// /excel/importExcel 接口,与upload接口作用类似,只是把文件存到resource/excel目录下,用于导入Excel时存放Excel文件(ExcelImport.xlsx)
14+
// /excel/loadExcel接口,用于读取resource/excel目录下的文件((ExcelImport.xlsx)并加载为[]model.SysBaseMenu类型的示例数据
15+
// /excel/exportExcel 接口,用于读取前端传来的tableData,生成Excel文件并返回
16+
// /excel/downloadTemplate 接口,用于下载resource/excel目录下的 ExcelTemplate.xlsx 文件,作为导入的模板
17+
18+
// @Tags excel
19+
// @Summary 导出Excel
20+
// @Security ApiKeyAuth
21+
// @accept application/json
22+
// @Produce application/octet-stream
23+
// @Param data body model.ExcelInfo true "导出Excel文件信息"
24+
// @Success 200
25+
// @Router /excel/exportExcel [post]
26+
func ExportExcel(c *gin.Context) {
27+
var excelInfo model.ExcelInfo
28+
_ = c.ShouldBindJSON(&excelInfo)
29+
filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName
30+
err := service.ParseInfoList2Excel(excelInfo.InfoList, filePath)
31+
if err != nil {
32+
global.GVA_LOG.Error("转换Excel失败!", zap.Any("err", err))
33+
response.FailWithMessage("转换Excel失败", c)
34+
return
35+
}
36+
c.Writer.Header().Add("success", "true")
37+
c.File(filePath)
38+
}
39+
40+
// @Tags excel
41+
// @Summary 导入Excel文件
42+
// @Security ApiKeyAuth
43+
// @accept multipart/form-data
44+
// @Produce application/json
45+
// @Param file formData file true "导入Excel文件"
46+
// @Success 200 {string} string "{"success":true,"data":{},"msg":"导入成功"}"
47+
// @Router /excel/importExcel [post]
48+
func ImportExcel(c *gin.Context) {
49+
_, header, err := c.Request.FormFile("file")
50+
if err != nil {
51+
global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
52+
response.FailWithMessage("接收文件失败", c)
53+
return
54+
}
55+
_ = c.SaveUploadedFile(header, global.GVA_CONFIG.Excel.Dir+"ExcelImport.xlsx")
56+
response.OkWithMessage("导入成功", c)
57+
}
58+
59+
// @Tags excel
60+
// @Summary 加载Excel数据
61+
// @Security ApiKeyAuth
62+
// @Produce application/json
63+
// @Success 200 {string} string "{"success":true,"data":{},"msg":"加载数据成功"}"
64+
// @Router /excel/loadExcel [get]
65+
func LoadExcel(c *gin.Context) {
66+
menus, err := service.ParseExcel2InfoList()
67+
if err != nil {
68+
global.GVA_LOG.Error("加载数据失败", zap.Any("err", err))
69+
response.FailWithMessage("加载数据失败", c)
70+
return
71+
}
72+
response.OkWithDetailed(response.PageResult{
73+
List: menus,
74+
Total: int64(len(menus)),
75+
Page: 1,
76+
PageSize: 999,
77+
}, "加载数据成功", c)
78+
}
79+
80+
// @Tags excel
81+
// @Summary 下载模板
82+
// @Security ApiKeyAuth
83+
// @accept multipart/form-data
84+
// @Produce application/json
85+
// @Param fileName query fileName true "模板名称"
86+
// @Success 200
87+
// @Router /excel/downloadTemplate [get]
88+
func DownloadTemplate(c *gin.Context) {
89+
fileName := c.Query("fileName")
90+
filePath := global.GVA_CONFIG.Excel.Dir + fileName
91+
ok, err := utils.PathExists(filePath)
92+
if !ok || err != nil {
93+
global.GVA_LOG.Error("文件不存在", zap.Any("err", err))
94+
response.FailWithMessage("文件不存在", c)
95+
return
96+
}
97+
c.Writer.Header().Add("success", "true")
98+
c.File(filePath)
99+
}

server/api/v1/exa_file_upload_download.go

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"gin-vue-admin/model/request"
77
"gin-vue-admin/model/response"
88
"gin-vue-admin/service"
9-
"gin-vue-admin/utils"
109
"github.com/gin-gonic/gin"
1110
"go.uber.org/zap"
1211
)
@@ -76,89 +75,6 @@ func GetFileList(c *gin.Context) {
7675
Total: total,
7776
Page: pageInfo.Page,
7877
PageSize: pageInfo.PageSize,
79-
},"获取成功", c)
78+
}, "获取成功", c)
8079
}
8180
}
82-
83-
// @Tags ExaFileUploadAndDownload
84-
// @Summary 导出Excel
85-
// @Security ApiKeyAuth
86-
// @accept application/json
87-
// @Produce application/octet-stream
88-
// @Param data body request.ExcelInfo true "导出Excel文件信息"
89-
// @Success 200
90-
// @Router /fileUploadAndDownload/exportExcel [post]
91-
func ExportExcel(c *gin.Context) {
92-
var excelInfo request.ExcelInfo
93-
c.ShouldBindJSON(&excelInfo)
94-
filePath := global.GVA_CONFIG.Excel.Dir+excelInfo.FileName
95-
err := service.ParseInfoList2Excel(excelInfo.InfoList, filePath)
96-
if err != nil {
97-
global.GVA_LOG.Error("转换Excel失败!", zap.Any("err", err))
98-
response.FailWithMessage("转换Excel失败", c)
99-
return
100-
}
101-
c.Writer.Header().Add("success", "true")
102-
c.File(filePath)
103-
}
104-
105-
// @Tags ExaFileUploadAndDownload
106-
// @Summary 导入Excel文件
107-
// @Security ApiKeyAuth
108-
// @accept multipart/form-data
109-
// @Produce application/json
110-
// @Param file formData file true "导入Excel文件"
111-
// @Success 200 {string} string "{"success":true,"data":{},"msg":"导入成功"}"
112-
// @Router /fileUploadAndDownload/importExcel [post]
113-
func ImportExcel(c *gin.Context) {
114-
_, header, err := c.Request.FormFile("file")
115-
if err != nil {
116-
global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
117-
response.FailWithMessage("接收文件失败", c)
118-
return
119-
}
120-
c.SaveUploadedFile(header, global.GVA_CONFIG.Excel.Dir+"ExcelImport.xlsx")
121-
response.OkWithMessage("导入成功", c)
122-
}
123-
124-
// @Tags ExaFileUploadAndDownload
125-
// @Summary 加载Excel数据
126-
// @Security ApiKeyAuth
127-
// @Produce application/json
128-
// @Success 200 {string} string "{"success":true,"data":{},"msg":"加载数据成功"}"
129-
// @Router /fileUploadAndDownload/loadExcel [get]
130-
func LoadExcel(c *gin.Context) {
131-
menus, err := service.ParseExcel2InfoList()
132-
if err != nil {
133-
global.GVA_LOG.Error("加载数据失败", zap.Any("err", err))
134-
response.FailWithMessage("加载数据失败", c)
135-
return
136-
}
137-
response.OkWithDetailed(response.PageResult{
138-
List: menus,
139-
Total: int64(len(menus)),
140-
Page: 1,
141-
PageSize: 999,
142-
},"加载数据成功", c)
143-
}
144-
145-
// @Tags ExaFileUploadAndDownload
146-
// @Summary 下载模板
147-
// @Security ApiKeyAuth
148-
// @accept multipart/form-data
149-
// @Produce application/json
150-
// @Param fileName query fileName true "模板名称"
151-
// @Success 200
152-
// @Router /fileUploadAndDownload/downloadTemplate [get]
153-
func DownloadTemplate(c *gin.Context) {
154-
fileName := c.Query("fileName")
155-
filePath := global.GVA_CONFIG.Excel.Dir+fileName
156-
ok, err := utils.PathExists(filePath)
157-
if !ok || err != nil {
158-
global.GVA_LOG.Error("文件不存在", zap.Any("err", err))
159-
response.FailWithMessage("文件不存在", c)
160-
return
161-
}
162-
c.Writer.Header().Add("success", "true")
163-
c.File(filePath)
164-
}

server/api/v1/sys_auto_code.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,44 @@
11
package v1
22

33
import (
4+
"errors"
45
"fmt"
56
"gin-vue-admin/global"
67
"gin-vue-admin/model"
78
"gin-vue-admin/model/response"
89
"gin-vue-admin/service"
910
"gin-vue-admin/utils"
10-
"github.com/gin-gonic/gin"
11-
"github.com/pkg/errors"
12-
"go.uber.org/zap"
1311
"net/url"
1412
"os"
13+
14+
"github.com/gin-gonic/gin"
15+
"go.uber.org/zap"
1516
)
1617

18+
// @Tags AutoCode
19+
// @Summary 预览创建后的代码
20+
// @Security ApiKeyAuth
21+
// @accept application/json
22+
// @Produce application/json
23+
// @Param data body model.AutoCodeStruct true "预览创建代码"
24+
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
25+
// @Router /autoCode/preview [post]
26+
func PreviewTemp(c *gin.Context) {
27+
var a model.AutoCodeStruct
28+
_ = c.ShouldBindJSON(&a)
29+
if err := utils.Verify(a, utils.AutoCodeVerify); err != nil {
30+
response.FailWithMessage(err.Error(), c)
31+
return
32+
}
33+
autoCode, err := service.PreviewTemp(a)
34+
if err != nil {
35+
global.GVA_LOG.Error("预览失败!", zap.Any("err", err))
36+
response.FailWithMessage("预览失败", c)
37+
} else {
38+
response.OkWithDetailed(gin.H{"autoCode": autoCode}, "预览成功", c)
39+
}
40+
}
41+
1742
// @Tags AutoCode
1843
// @Summary 自动代码模板
1944
// @Security ApiKeyAuth

server/cmd/gva/mysql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (m *_mysql) Init() {
4444
m._config.DisableForeignKeyConstraintWhenMigrating = true
4545
m.db, m.err = gorm.Open(mysql.New(mysql.Config{
4646
DSN: global.GVA_CONFIG.Mysql.Dsn(), // DSN data source name
47-
DefaultStringSize: 256, // string 类型字段的默认长度
47+
DefaultStringSize: 191, // string 类型字段的默认长度
4848
DisableDatetimePrecision: true, // 禁用 datetime 精度,MySQL 5.6 之前的数据库不支持
4949
DontSupportRenameIndex: true, // 重命名索引时采用删除并新建的方式,MySQL 5.7 之前的数据库和 MariaDB 不支持重命名索引
5050
DontSupportRenameColumn: true, // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列

server/cmd/information/system/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ var apis = []model.SysApi{
9292
{global.GVA_MODEL{ID: 77, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/getMyNeed", "获取我的待办", "workflowProcess", "GET"},
9393
{global.GVA_MODEL{ID: 78, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/getWorkflowMoveByID", "根据id获取当前节点详情和历史", "workflowProcess", "GET"},
9494
{global.GVA_MODEL{ID: 79, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/completeWorkflowMove", "提交工作流", "workflowProcess", "POST"},
95+
{global.GVA_MODEL{ID: 80, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/preview", "预览自动化代码", "autoCode", "POST"},
96+
{global.GVA_MODEL{ID: 81, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/excel/importExcel", "预览自动化代码", "autoCode", "POST"},
97+
{global.GVA_MODEL{ID: 82, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/excel/loadExcel", "预览自动化代码", "autoCode", "POST"},
98+
{global.GVA_MODEL{ID: 83, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/excel/exportExcel", "预览自动化代码", "autoCode", "POST"},
99+
{global.GVA_MODEL{ID: 84, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/excel/downloadTemplate", "预览自动化代码", "autoCode", "POST"},
95100
}
96101

97102
//@author: [SliverHorn](https://github.com/SliverHorn)

server/cmd/information/system/casbin.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ var carbines = []gormadapter.CasbinRule{
5555
{PType: "p", V0: "888", V1: "/customer/customer", V2: "GET"},
5656
{PType: "p", V0: "888", V1: "/customer/customerList", V2: "GET"},
5757
{PType: "p", V0: "888", V1: "/autoCode/createTemp", V2: "POST"},
58+
{PType: "p", V0: "888", V1: "/autoCode/preview", V2: "POST"},
5859
{PType: "p", V0: "888", V1: "/autoCode/getTables", V2: "GET"},
5960
{PType: "p", V0: "888", V1: "/autoCode/getDB", V2: "GET"},
6061
{PType: "p", V0: "888", V1: "/autoCode/getColumn", V2: "GET"},
@@ -91,6 +92,10 @@ var carbines = []gormadapter.CasbinRule{
9192
{PType: "p", V0: "888", V1: "/workflowProcess/getMyStated", V2: "GET"},
9293
{PType: "p", V0: "888", V1: "/workflowProcess/getMyNeed", V2: "GET"},
9394
{PType: "p", V0: "888", V1: "/workflowProcess/getWorkflowMoveByID", V2: "GET"},
95+
{PType: "p", V0: "888", V1: "/excel/importExcel", V2: "POST"},
96+
{PType: "p", V0: "888", V1: "/excel/loadExcel", V2: "GET"},
97+
{PType: "p", V0: "888", V1: "/excel/exportExcel", V2: "POST"},
98+
{PType: "p", V0: "888", V1: "/excel/downloadTemplate", V2: "GET"},
9499
{PType: "p", V0: "8881", V1: "/base/login", V2: "POST"},
95100
{PType: "p", V0: "8881", V1: "/user/register", V2: "POST"},
96101
{PType: "p", V0: "8881", V1: "/api/createApi", V2: "POST"},

server/config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ qiniu:
7878
secret-key: 'pgdbqEsf7ooZh7W3xokP833h3dZ_VecFXPDeG5JY'
7979
use-cdn-domains: false
8080

81+
8182
# aliyun oss configuration
8283
aliyun-oss:
8384
endpoint: 'yourEndpoint'
@@ -86,6 +87,15 @@ aliyun-oss:
8687
bucket-name: 'yourBucketName'
8788
bucket-url: 'yourBucketUrl'
8889

90+
# tencent cos configuration
91+
tencent-cos:
92+
bucket: 'xxxxx-10005608'
93+
region: 'ap-shanghai'
94+
secret-id: 'xxxxxxxx'
95+
secret-key: 'xxxxxxxx'
96+
base-url: 'https://gin.vue.admin'
97+
path-prefix: 'gin-vue-admin'
98+
8999
# excel configuration
90100
excel:
91101
dir: './resource/excel/'

server/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ type Server struct {
1414
Local Local `mapstructure:"local" json:"local" yaml:"local"`
1515
Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
1616
AliyunOSS AliyunOSS `mapstructure:"aliyun-oss" json:"aliyunOSS" yaml:"aliyun-oss"`
17-
Excel Excel `mapstructure:"excel" json:"excel" yaml:"excel"`
17+
TencentCOS TencentCOS `mapstructure:"tencent-cos" json:"tencentCOS" yaml:"tencent-cos"`
18+
Excel Excel `mapstructure:"excel" json:"excel" yaml:"excel"`
1819
}

server/config/oss.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@ type Qiniu struct {
1414
UseCdnDomains bool `mapstructure:"use-cdn-domains" json:"useCdnDomains" yaml:"use-cdn-domains"`
1515
}
1616

17+
1718
type AliyunOSS struct {
1819
Endpoint string `mapstructure:"endpoint" json:"endpoint" yaml:"endpoint"`
1920
AccessKeyId string `mapstructure:"access-key-id" json:"accessKeyId" yaml:"access-key-id"`
2021
AccessKeySecret string `mapstructure:"access-key-secret" json:"accessKeySecret" yaml:"access-key-secret"`
2122
BucketName string `mapstructure:"bucket-name" json:"bucketName" yaml:"bucket-name"`
2223
BucketUrl string `mapstructure:"bucket-url" json:"bucketUrl" yaml:"bucket-url"`
24+
25+
type TencentCOS struct {
26+
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"`
27+
Region string `mapstructure:"region" json:"region" yaml:"region"`
28+
SecretID string `mapstructure:"secret-id" json:"secretID" yaml:"secret-id"`
29+
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"`
30+
BaseURL string `mapstructure:"base-url" json:"baseURL" yaml:"base-url"`
31+
PathPrefix string `mapstructure:"path-prefix" json:"pathPrefix" yaml:"path-prefix"`
32+
2333
}

server/go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ require (
3636
github.com/onsi/ginkgo v1.7.0 // indirect
3737
github.com/onsi/gomega v1.4.3 // indirect
3838
github.com/pelletier/go-toml v1.6.0 // indirect
39-
github.com/pkg/errors v0.9.1
39+
github.com/pkg/errors v0.9.1 // indirect
4040
github.com/qiniu/api.v7/v7 v7.4.1
4141
github.com/satori/go.uuid v1.2.0
42-
github.com/shirou/gopsutil v2.20.8+incompatible
42+
github.com/shirou/gopsutil v3.21.1+incompatible
4343
github.com/spf13/afero v1.2.2 // indirect
4444
github.com/spf13/cast v1.3.1 // indirect
4545
github.com/spf13/cobra v1.1.1
@@ -48,6 +48,7 @@ require (
4848
github.com/swaggo/gin-swagger v1.2.0
4949
github.com/swaggo/swag v1.6.7
5050
github.com/tebeka/strftime v0.1.3 // indirect
51+
github.com/tencentyun/cos-go-sdk-v5 v0.7.19
5152
github.com/unrolled/secure v1.0.7
5253
go.uber.org/zap v1.10.0
5354
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect

server/initialize/router.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func Routers() *gin.Engine {
4747
router.InitSysDictionaryDetailRouter(PrivateGroup) // 字典详情管理
4848
router.InitFileUploadAndDownloadRouter(PrivateGroup) // 文件上传下载功能路由
4949
router.InitWorkflowProcessRouter(PrivateGroup) // 工作流相关接口
50+
router.InitExcelRouter(PrivateGroup) // 表格导入导出
5051
}
5152
global.GVA_LOG.Info("router register success")
5253
return Router

server/model/exa_excel.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package model
2+
3+
type ExcelInfo struct {
4+
FileName string `json:"fileName"`
5+
InfoList []SysBaseMenu `json:"infoList"`
6+
}

server/model/request/exa_file_upload_and_download.go

Lines changed: 0 additions & 8 deletions
This file was deleted.
2.2 KB
Binary file not shown.
File renamed without changes.

0 commit comments

Comments
 (0)