基础架构变更 增加模块化
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package autocode
|
||||
|
||||
import (
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model/autocode"
|
||||
"gin-vue-admin/model/autocode/requset"
|
||||
)
|
||||
|
||||
type AutoCodeExampleService struct {
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: CreateAutoCodeExample
|
||||
//@description: 创建自动化示例数据
|
||||
//@param: autoCodeExampleService *AutoCodeExampleService
|
||||
//@return: err error
|
||||
|
||||
func (autoCodeExampleService *AutoCodeExampleService) CreateAutoCodeExample(autoCodeExample autocode.AutoCodeExample) (err error) {
|
||||
|
||||
err = global.GVA_DB.Create(&autoCodeExample).Error
|
||||
return err
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: DeleteAutoCodeExample
|
||||
//@description: 删除自动化示例数据
|
||||
//@param: autoCodeExample autocode.AutoCodeExample
|
||||
//@return: err error
|
||||
|
||||
func (autoCodeExampleService *AutoCodeExampleService) DeleteAutoCodeExample(autoCodeExample autocode.AutoCodeExample) (err error) {
|
||||
err = global.GVA_DB.Delete(&autoCodeExample).Error
|
||||
return err
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: UpdateAutoCodeExample
|
||||
//@description: 更新自动化示例数据
|
||||
//@param: autoCodeExample *autocode.AutoCodeExample
|
||||
//@return: err error
|
||||
|
||||
func (autoCodeExampleService *AutoCodeExampleService) UpdateAutoCodeExample(autoCodeExample *autocode.AutoCodeExample) (err error) {
|
||||
err = global.GVA_DB.Save(autoCodeExample).Error
|
||||
return err
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: GetAutoCodeExampleDetail
|
||||
//@description: 根据id获取自动化示例数据
|
||||
//@param: id uint
|
||||
//@return: err error, autoCodeExample autocode.AutoCodeExample
|
||||
|
||||
func (autoCodeExampleService *AutoCodeExampleService) GetAutoCodeExample(id uint) (err error, autoCodeExample autocode.AutoCodeExample) {
|
||||
err = global.GVA_DB.Where("id = ?", id).First(&autoCodeExample).Error
|
||||
return
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: GetAutoCodeExampleInfoList
|
||||
//@description: 分页获取自动化示例数据
|
||||
//@param: info request.AutoCodeExampleSearch
|
||||
//@return: err error, list interface{}, total int64
|
||||
|
||||
func (autoCodeExampleService *AutoCodeExampleService) GetAutoCodeExampleInfoList(info request.AutoCodeExampleSearch) (err error, list interface{}, total int64) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
// 创建db
|
||||
db := global.GVA_DB.Model(&autocode.AutoCodeExample{})
|
||||
var autoCodeExamples []autocode.AutoCodeExample
|
||||
// 如果有条件搜索 下方会自动创建搜索语句
|
||||
if info.AutoCodeExampleField != "" {
|
||||
db = db.Where("label LIKE ?", "%"+info.AutoCodeExampleField+"%")
|
||||
}
|
||||
err = db.Count(&total).Error
|
||||
err = db.Limit(limit).Offset(offset).Find(&autoCodeExamples).Error
|
||||
return err, autoCodeExamples, total
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package autocode
|
||||
|
||||
type ServiceGroup struct {
|
||||
AutoCodeExampleService
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"gin-vue-admin/service/autocode"
|
||||
"gin-vue-admin/service/example"
|
||||
"gin-vue-admin/service/system"
|
||||
)
|
||||
|
||||
type ServiceGroup struct {
|
||||
ExampleServiceGroup example.ServiceGroup
|
||||
SystemServiceGroup system.ServiceGroup
|
||||
AutoCodeServiceGroup autocode.ServiceGroup
|
||||
}
|
||||
|
||||
var ServiceGroupApp = new(ServiceGroup)
|
||||
@@ -0,0 +1,8 @@
|
||||
package example
|
||||
|
||||
type ServiceGroup struct {
|
||||
FileUploadAndDownloadService
|
||||
CustomerService
|
||||
ExcelService
|
||||
SimpleUploaderService
|
||||
}
|
||||
+7
-4
@@ -1,4 +1,4 @@
|
||||
package service
|
||||
package example
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -7,13 +7,16 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type FileUploadAndDownloadService struct {
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: FindOrCreateFile
|
||||
//@description: 上传文件时检测当前文件属性,如果没有文件则创建,有则返回文件的当前切片
|
||||
//@param: fileMd5 string, fileName string, chunkTotal int
|
||||
//@return: err error, file model.ExaFile
|
||||
|
||||
func FindOrCreateFile(fileMd5 string, fileName string, chunkTotal int) (err error, file example.ExaFile) {
|
||||
func (e *FileUploadAndDownloadService) FindOrCreateFile(fileMd5 string, fileName string, chunkTotal int) (err error, file example.ExaFile) {
|
||||
var cfile example.ExaFile
|
||||
cfile.FileMd5 = fileMd5
|
||||
cfile.FileName = fileName
|
||||
@@ -35,7 +38,7 @@ func FindOrCreateFile(fileMd5 string, fileName string, chunkTotal int) (err erro
|
||||
//@param: id uint, fileChunkPath string, fileChunkNumber int
|
||||
//@return: error
|
||||
|
||||
func CreateFileChunk(id uint, fileChunkPath string, fileChunkNumber int) error {
|
||||
func (e *FileUploadAndDownloadService) CreateFileChunk(id uint, fileChunkPath string, fileChunkNumber int) error {
|
||||
var chunk example.ExaFileChunk
|
||||
chunk.FileChunkPath = fileChunkPath
|
||||
chunk.ExaFileID = id
|
||||
@@ -50,7 +53,7 @@ func CreateFileChunk(id uint, fileChunkPath string, fileChunkNumber int) error {
|
||||
//@param: fileMd5 string, fileName string, filePath string
|
||||
//@return: error
|
||||
|
||||
func DeleteFileChunk(fileMd5 string, fileName string, filePath string) error {
|
||||
func (e *FileUploadAndDownloadService) DeleteFileChunk(fileMd5 string, fileName string, filePath string) error {
|
||||
var chunks []example.ExaFileChunk
|
||||
var file example.ExaFile
|
||||
err := global.GVA_DB.Where("file_md5 = ? AND file_name = ?", fileMd5, fileName).First(&file).Update("IsFinish", true).Update("file_path", filePath).Error
|
||||
@@ -1,19 +1,23 @@
|
||||
package service
|
||||
package example
|
||||
|
||||
import (
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model/common/request"
|
||||
"gin-vue-admin/model/example"
|
||||
"gin-vue-admin/model/example/request"
|
||||
"gin-vue-admin/model/system"
|
||||
systemService "gin-vue-admin/service/system"
|
||||
)
|
||||
|
||||
type CustomerService struct {
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: CreateExaCustomer
|
||||
//@description: 创建客户
|
||||
//@param: e model.ExaCustomer
|
||||
//@return: err error
|
||||
|
||||
func CreateExaCustomer(e example.ExaCustomer) (err error) {
|
||||
func (exa *CustomerService) CreateExaCustomer(e example.ExaCustomer) (err error) {
|
||||
err = global.GVA_DB.Create(&e).Error
|
||||
return err
|
||||
}
|
||||
@@ -24,7 +28,7 @@ func CreateExaCustomer(e example.ExaCustomer) (err error) {
|
||||
//@param: e model.ExaCustomer
|
||||
//@return: err error
|
||||
|
||||
func DeleteExaCustomer(e example.ExaCustomer) (err error) {
|
||||
func (exa *CustomerService) DeleteExaCustomer(e example.ExaCustomer) (err error) {
|
||||
err = global.GVA_DB.Delete(&e).Error
|
||||
return err
|
||||
}
|
||||
@@ -35,7 +39,7 @@ func DeleteExaCustomer(e example.ExaCustomer) (err error) {
|
||||
//@param: e *model.ExaCustomer
|
||||
//@return: err error
|
||||
|
||||
func UpdateExaCustomer(e *example.ExaCustomer) (err error) {
|
||||
func (exa *CustomerService) UpdateExaCustomer(e *example.ExaCustomer) (err error) {
|
||||
err = global.GVA_DB.Save(e).Error
|
||||
return err
|
||||
}
|
||||
@@ -46,7 +50,7 @@ func UpdateExaCustomer(e *example.ExaCustomer) (err error) {
|
||||
//@param: id uint
|
||||
//@return: err error, customer model.ExaCustomer
|
||||
|
||||
func GetExaCustomer(id uint) (err error, customer example.ExaCustomer) {
|
||||
func (exa *CustomerService) GetExaCustomer(id uint) (err error, customer example.ExaCustomer) {
|
||||
err = global.GVA_DB.Where("id = ?", id).First(&customer).Error
|
||||
return
|
||||
}
|
||||
@@ -57,13 +61,13 @@ func GetExaCustomer(id uint) (err error, customer example.ExaCustomer) {
|
||||
//@param: sysUserAuthorityID string, info request.PageInfo
|
||||
//@return: err error, list interface{}, total int64
|
||||
|
||||
func GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (err error, list interface{}, total int64) {
|
||||
func (exa *CustomerService) GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (err error, list interface{}, total int64) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
db := global.GVA_DB.Model(&example.ExaCustomer{})
|
||||
var a system.SysAuthority
|
||||
a.AuthorityId = sysUserAuthorityID
|
||||
err, auth := GetAuthorityInfo(a)
|
||||
err, auth := systemService.AuthorityServiceApp.GetAuthorityInfo(a)
|
||||
var dataId []string
|
||||
for _, v := range auth.DataAuthorityId {
|
||||
dataId = append(dataId, v.AuthorityId)
|
||||
@@ -1,4 +1,4 @@
|
||||
package service
|
||||
package example
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -9,7 +9,10 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func ParseInfoList2Excel(infoList []system.SysBaseMenu, filePath string) error {
|
||||
type ExcelService struct {
|
||||
}
|
||||
|
||||
func (exa *ExcelService) ParseInfoList2Excel(infoList []system.SysBaseMenu, filePath string) error {
|
||||
excel := excelize.NewFile()
|
||||
excel.SetSheetRow("Sheet1", "A1", &[]string{"ID", "路由Name", "路由Path", "是否隐藏", "父节点", "排序", "文件名称"})
|
||||
for i, menu := range infoList {
|
||||
@@ -28,7 +31,7 @@ func ParseInfoList2Excel(infoList []system.SysBaseMenu, filePath string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func ParseExcel2InfoList() ([]system.SysBaseMenu, error) {
|
||||
func (exa *ExcelService) ParseExcel2InfoList() ([]system.SysBaseMenu, error) {
|
||||
skipHeader := true
|
||||
fixedHeader := []string{"ID", "路由Name", "路由Path", "是否隐藏", "父节点", "排序", "文件名称"}
|
||||
file, err := excelize.OpenFile(global.GVA_CONFIG.Excel.Dir + "ExcelImport.xlsx")
|
||||
@@ -46,7 +49,7 @@ func ParseExcel2InfoList() ([]system.SysBaseMenu, error) {
|
||||
return nil, err
|
||||
}
|
||||
if skipHeader {
|
||||
if compareStrSlice(row, fixedHeader) {
|
||||
if exa.compareStrSlice(row, fixedHeader) {
|
||||
skipHeader = false
|
||||
continue
|
||||
} else {
|
||||
@@ -75,7 +78,7 @@ func ParseExcel2InfoList() ([]system.SysBaseMenu, error) {
|
||||
return menus, nil
|
||||
}
|
||||
|
||||
func compareStrSlice(a, b []string) bool {
|
||||
func (exa *ExcelService) compareStrSlice(a, b []string) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
+10
-10
@@ -1,10 +1,10 @@
|
||||
package service
|
||||
package example
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model/common/request"
|
||||
"gin-vue-admin/model/example"
|
||||
"gin-vue-admin/model/example/request"
|
||||
"gin-vue-admin/utils/upload"
|
||||
"mime/multipart"
|
||||
"strings"
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
//@param: file model.ExaFileUploadAndDownload
|
||||
//@return: error
|
||||
|
||||
func Upload(file example.ExaFileUploadAndDownload) error {
|
||||
func (e *FileUploadAndDownloadService) Upload(file example.ExaFileUploadAndDownload) error {
|
||||
return global.GVA_DB.Create(&file).Error
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func Upload(file example.ExaFileUploadAndDownload) error {
|
||||
//@param: id uint
|
||||
//@return: error, model.ExaFileUploadAndDownload
|
||||
|
||||
func FindFile(id uint) (error, example.ExaFileUploadAndDownload) {
|
||||
func (e *FileUploadAndDownloadService) FindFile(id uint) (error, example.ExaFileUploadAndDownload) {
|
||||
var file example.ExaFileUploadAndDownload
|
||||
err := global.GVA_DB.Where("id = ?", id).First(&file).Error
|
||||
return err, file
|
||||
@@ -38,9 +38,9 @@ func FindFile(id uint) (error, example.ExaFileUploadAndDownload) {
|
||||
//@param: file model.ExaFileUploadAndDownload
|
||||
//@return: err error
|
||||
|
||||
func DeleteFile(file example.ExaFileUploadAndDownload) (err error) {
|
||||
func (e *FileUploadAndDownloadService) DeleteFile(file example.ExaFileUploadAndDownload) (err error) {
|
||||
var fileFromDb example.ExaFileUploadAndDownload
|
||||
err, fileFromDb = FindFile(file.ID)
|
||||
err, fileFromDb = e.FindFile(file.ID)
|
||||
oss := upload.NewOss()
|
||||
if err = oss.DeleteFile(fileFromDb.Key); err != nil {
|
||||
return errors.New("文件删除失败")
|
||||
@@ -52,10 +52,10 @@ func DeleteFile(file example.ExaFileUploadAndDownload) (err error) {
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: GetFileRecordInfoList
|
||||
//@description: 分页获取数据
|
||||
//@param: info request.PageInfo
|
||||
//@param: info requset.PageInfo
|
||||
//@return: err error, list interface{}, total int64
|
||||
|
||||
func GetFileRecordInfoList(info request.PageInfo) (err error, list interface{}, total int64) {
|
||||
func (e *FileUploadAndDownloadService) GetFileRecordInfoList(info request.PageInfo) (err error, list interface{}, total int64) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
db := global.GVA_DB
|
||||
@@ -71,7 +71,7 @@ func GetFileRecordInfoList(info request.PageInfo) (err error, list interface{},
|
||||
//@param: header *multipart.FileHeader, noSave string
|
||||
//@return: err error, file model.ExaFileUploadAndDownload
|
||||
|
||||
func UploadFile(header *multipart.FileHeader, noSave string) (err error, file example.ExaFileUploadAndDownload) {
|
||||
func (e *FileUploadAndDownloadService) UploadFile(header *multipart.FileHeader, noSave string) (err error, file example.ExaFileUploadAndDownload) {
|
||||
oss := upload.NewOss()
|
||||
filePath, key, uploadErr := oss.UploadFile(header)
|
||||
if uploadErr != nil {
|
||||
@@ -85,7 +85,7 @@ func UploadFile(header *multipart.FileHeader, noSave string) (err error, file ex
|
||||
Tag: s[len(s)-1],
|
||||
Key: key,
|
||||
}
|
||||
return Upload(f), f
|
||||
return e.Upload(f), f
|
||||
}
|
||||
return
|
||||
}
|
||||
+7
-4
@@ -1,4 +1,4 @@
|
||||
package service
|
||||
package example
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -11,13 +11,16 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type SimpleUploaderService struct {
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: SaveChunk
|
||||
//@description: 保存文件切片路径
|
||||
//@param: uploader model.ExaSimpleUploader
|
||||
//@return: err error
|
||||
|
||||
func SaveChunk(uploader example.ExaSimpleUploader) (err error) {
|
||||
func (exa *SimpleUploaderService) SaveChunk(uploader example.ExaSimpleUploader) (err error) {
|
||||
return global.GVA_DB.Create(uploader).Error
|
||||
}
|
||||
|
||||
@@ -27,7 +30,7 @@ func SaveChunk(uploader example.ExaSimpleUploader) (err error) {
|
||||
//@param: md5 string
|
||||
//@return: err error, uploads []model.ExaSimpleUploader, isDone bool
|
||||
|
||||
func CheckFileMd5(md5 string) (err error, uploads []example.ExaSimpleUploader, isDone bool) {
|
||||
func (exa *SimpleUploaderService) CheckFileMd5(md5 string) (err error, uploads []example.ExaSimpleUploader, isDone bool) {
|
||||
err = global.GVA_DB.Find(&uploads, "identifier = ? AND is_done = ?", md5, false).Error
|
||||
isDone = errors.Is(global.GVA_DB.First(&example.ExaSimpleUploader{}, "identifier = ? AND is_done = ?", md5, true).Error, gorm.ErrRecordNotFound)
|
||||
return err, uploads, !isDone
|
||||
@@ -39,7 +42,7 @@ func CheckFileMd5(md5 string) (err error, uploads []example.ExaSimpleUploader, i
|
||||
//@param: md5 string, fileName string
|
||||
//@return: err error
|
||||
|
||||
func MergeFileMd5(md5 string, fileName string) (err error) {
|
||||
func (exa *SimpleUploaderService) MergeFileMd5(md5 string, fileName string) (err error) {
|
||||
finishDir := "./finish/"
|
||||
dir := "./chunk/" + md5
|
||||
// 如果文件上传成功 不做后续操作 通知成功即可
|
||||
@@ -0,0 +1,19 @@
|
||||
package system
|
||||
|
||||
type ServiceGroup struct {
|
||||
JwtService
|
||||
ApiService
|
||||
AuthorityService
|
||||
AutoCodeService
|
||||
AutoCodeHistoryService
|
||||
BaseMenuService
|
||||
CasbinService
|
||||
DictionaryService
|
||||
DictionaryDetailService
|
||||
EmailService
|
||||
InitDBService
|
||||
MenuService
|
||||
OperationRecordService
|
||||
SystemConfigService
|
||||
UserService
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package service
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -10,13 +10,16 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type JwtService struct {
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: JsonInBlacklist
|
||||
//@description: 拉黑jwt
|
||||
//@param: jwtList model.JwtBlacklist
|
||||
//@return: err error
|
||||
|
||||
func JsonInBlacklist(jwtList system.JwtBlacklist) (err error) {
|
||||
func (jwtService *JwtService) JsonInBlacklist(jwtList system.JwtBlacklist) (err error) {
|
||||
err = global.GVA_DB.Create(&jwtList).Error
|
||||
return
|
||||
}
|
||||
@@ -27,7 +30,7 @@ func JsonInBlacklist(jwtList system.JwtBlacklist) (err error) {
|
||||
//@param: jwt string
|
||||
//@return: bool
|
||||
|
||||
func IsBlacklist(jwt string) bool {
|
||||
func (jwtService *JwtService) IsBlacklist(jwt string) bool {
|
||||
err := global.GVA_DB.Where("jwt = ?", jwt).First(&system.JwtBlacklist{}).Error
|
||||
isNotFound := errors.Is(err, gorm.ErrRecordNotFound)
|
||||
return !isNotFound
|
||||
@@ -39,7 +42,7 @@ func IsBlacklist(jwt string) bool {
|
||||
//@param: userName string
|
||||
//@return: err error, redisJWT string
|
||||
|
||||
func GetRedisJWT(userName string) (err error, redisJWT string) {
|
||||
func (jwtService *JwtService) GetRedisJWT(userName string) (err error, redisJWT string) {
|
||||
redisJWT, err = global.GVA_REDIS.Get(context.Background(), userName).Result()
|
||||
return err, redisJWT
|
||||
}
|
||||
@@ -50,7 +53,7 @@ func GetRedisJWT(userName string) (err error, redisJWT string) {
|
||||
//@param: jwt string, userName string
|
||||
//@return: err error
|
||||
|
||||
func SetRedisJWT(jwt string, userName string) (err error) {
|
||||
func (jwtService *JwtService) SetRedisJWT(jwt string, userName string) (err error) {
|
||||
// 此处过期时间等于jwt过期时间
|
||||
timer := time.Duration(global.GVA_CONFIG.JWT.ExpiresTime) * time.Second
|
||||
err = global.GVA_REDIS.Set(context.Background(), userName, jwt, timer).Err()
|
||||
@@ -1,10 +1,10 @@
|
||||
package service
|
||||
package system
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model/common/request"
|
||||
"gin-vue-admin/model/system"
|
||||
"gin-vue-admin/model/system/request"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -15,7 +15,12 @@ import (
|
||||
//@param: api model.SysApi
|
||||
//@return: err error
|
||||
|
||||
func CreateApi(api system.SysApi) (err error) {
|
||||
type ApiService struct {
|
||||
}
|
||||
|
||||
var ApiServiceApp = new(ApiService)
|
||||
|
||||
func (apiService *ApiService) CreateApi(api system.SysApi) (err error) {
|
||||
if !errors.Is(global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).First(&system.SysApi{}).Error, gorm.ErrRecordNotFound) {
|
||||
return errors.New("存在相同api")
|
||||
}
|
||||
@@ -28,9 +33,9 @@ func CreateApi(api system.SysApi) (err error) {
|
||||
//@param: api model.SysApi
|
||||
//@return: err error
|
||||
|
||||
func DeleteApi(api system.SysApi) (err error) {
|
||||
func (apiService *ApiService) DeleteApi(api system.SysApi) (err error) {
|
||||
err = global.GVA_DB.Delete(&api).Error
|
||||
ClearCasbin(1, api.Path, api.Method)
|
||||
CasbinServiceApp.ClearCasbin(1, api.Path, api.Method)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -40,7 +45,7 @@ func DeleteApi(api system.SysApi) (err error) {
|
||||
//@param: api model.SysApi, info request.PageInfo, order string, desc bool
|
||||
//@return: err error
|
||||
|
||||
func GetAPIInfoList(api system.SysApi, info request.PageInfo, order string, desc bool) (err error, list interface{}, total int64) {
|
||||
func (apiService *ApiService) GetAPIInfoList(api system.SysApi, info request.PageInfo, order string, desc bool) (err error, list interface{}, total int64) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
db := global.GVA_DB.Model(&system.SysApi{})
|
||||
@@ -88,7 +93,7 @@ func GetAPIInfoList(api system.SysApi, info request.PageInfo, order string, desc
|
||||
//@description: 获取所有的api
|
||||
//@return: err error, apis []model.SysApi
|
||||
|
||||
func GetAllApis() (err error, apis []system.SysApi) {
|
||||
func (apiService *ApiService) GetAllApis() (err error, apis []system.SysApi) {
|
||||
err = global.GVA_DB.Find(&apis).Error
|
||||
return
|
||||
}
|
||||
@@ -99,7 +104,7 @@ func GetAllApis() (err error, apis []system.SysApi) {
|
||||
//@param: id float64
|
||||
//@return: err error, api model.SysApi
|
||||
|
||||
func GetApiById(id float64) (err error, api system.SysApi) {
|
||||
func (apiService *ApiService) GetApiById(id float64) (err error, api system.SysApi) {
|
||||
err = global.GVA_DB.Where("id = ?", id).First(&api).Error
|
||||
return
|
||||
}
|
||||
@@ -110,7 +115,7 @@ func GetApiById(id float64) (err error, api system.SysApi) {
|
||||
//@param: api model.SysApi
|
||||
//@return: err error
|
||||
|
||||
func UpdateApi(api system.SysApi) (err error) {
|
||||
func (apiService *ApiService) UpdateApi(api system.SysApi) (err error) {
|
||||
var oldA system.SysApi
|
||||
err = global.GVA_DB.Where("id = ?", api.ID).First(&oldA).Error
|
||||
if oldA.Path != api.Path || oldA.Method != api.Method {
|
||||
@@ -121,7 +126,7 @@ func UpdateApi(api system.SysApi) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
err = UpdateCasbinApi(oldA.Path, api.Path, oldA.Method, api.Method)
|
||||
err = CasbinServiceApp.UpdateCasbinApi(oldA.Path, api.Path, oldA.Method, api.Method)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
@@ -137,11 +142,11 @@ func UpdateApi(api system.SysApi) (err error) {
|
||||
//@param: apis []model.SysApi
|
||||
//@return: err error
|
||||
|
||||
func DeleteApisByIds(ids request.IdsReq) (err error) {
|
||||
func (apiService *ApiService) DeleteApisByIds(ids request.IdsReq) (err error) {
|
||||
err = global.GVA_DB.Delete(&[]system.SysApi{}, "id in ?", ids.Ids).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteApiByIds(ids []string) (err error) {
|
||||
func (apiService *ApiService) DeleteApiByIds(ids []string) (err error) {
|
||||
return global.GVA_DB.Delete(system.SysApi{}, ids).Error
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package service
|
||||
package system
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model/common/request"
|
||||
"gin-vue-admin/model/system"
|
||||
"gin-vue-admin/model/system/request"
|
||||
"gin-vue-admin/model/system/response"
|
||||
"gorm.io/gorm"
|
||||
"strconv"
|
||||
@@ -16,7 +16,12 @@ import (
|
||||
//@param: auth model.SysAuthority
|
||||
//@return: err error, authority model.SysAuthority
|
||||
|
||||
func CreateAuthority(auth system.SysAuthority) (err error, authority system.SysAuthority) {
|
||||
type AuthorityService struct {
|
||||
}
|
||||
|
||||
var AuthorityServiceApp = new(AuthorityService)
|
||||
|
||||
func (authorityService *AuthorityService) CreateAuthority(auth system.SysAuthority) (err error, authority system.SysAuthority) {
|
||||
var authorityBox system.SysAuthority
|
||||
if !errors.Is(global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).First(&authorityBox).Error, gorm.ErrRecordNotFound) {
|
||||
return errors.New("存在相同角色id"), auth
|
||||
@@ -31,13 +36,13 @@ func CreateAuthority(auth system.SysAuthority) (err error, authority system.SysA
|
||||
//@param: copyInfo response.SysAuthorityCopyResponse
|
||||
//@return: err error, authority model.SysAuthority
|
||||
|
||||
func CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, authority system.SysAuthority) {
|
||||
func (authorityService *AuthorityService) CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, authority system.SysAuthority) {
|
||||
var authorityBox system.SysAuthority
|
||||
if !errors.Is(global.GVA_DB.Where("authority_id = ?", copyInfo.Authority.AuthorityId).First(&authorityBox).Error, gorm.ErrRecordNotFound) {
|
||||
return errors.New("存在相同角色id"), authority
|
||||
}
|
||||
copyInfo.Authority.Children = []system.SysAuthority{}
|
||||
err, menus := GetMenuAuthority(&request.GetAuthorityId{AuthorityId: copyInfo.OldAuthorityId})
|
||||
err, menus := MenuServiceApp.GetMenuAuthority(&request.GetAuthorityId{AuthorityId: copyInfo.OldAuthorityId})
|
||||
var baseMenu []system.SysBaseMenu
|
||||
for _, v := range menus {
|
||||
intNum, _ := strconv.Atoi(v.MenuId)
|
||||
@@ -47,10 +52,10 @@ func CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, autho
|
||||
copyInfo.Authority.SysBaseMenus = baseMenu
|
||||
err = global.GVA_DB.Create(©Info.Authority).Error
|
||||
|
||||
paths := GetPolicyPathByAuthorityId(copyInfo.OldAuthorityId)
|
||||
err = UpdateCasbin(copyInfo.Authority.AuthorityId, paths)
|
||||
paths := CasbinServiceApp.GetPolicyPathByAuthorityId(copyInfo.OldAuthorityId)
|
||||
err = CasbinServiceApp.UpdateCasbin(copyInfo.Authority.AuthorityId, paths)
|
||||
if err != nil {
|
||||
_ = DeleteAuthority(©Info.Authority)
|
||||
_ = authorityService.DeleteAuthority(©Info.Authority)
|
||||
}
|
||||
return err, copyInfo.Authority
|
||||
}
|
||||
@@ -61,7 +66,7 @@ func CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, autho
|
||||
//@param: auth model.SysAuthority
|
||||
//@return: err error, authority model.SysAuthority
|
||||
|
||||
func UpdateAuthority(auth system.SysAuthority) (err error, authority system.SysAuthority) {
|
||||
func (authorityService *AuthorityService) UpdateAuthority(auth system.SysAuthority) (err error, authority system.SysAuthority) {
|
||||
err = global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).First(&system.SysAuthority{}).Updates(&auth).Error
|
||||
return err, auth
|
||||
}
|
||||
@@ -72,7 +77,7 @@ func UpdateAuthority(auth system.SysAuthority) (err error, authority system.SysA
|
||||
//@param: auth *model.SysAuthority
|
||||
//@return: err error
|
||||
|
||||
func DeleteAuthority(auth *system.SysAuthority) (err error) {
|
||||
func (authorityService *AuthorityService) DeleteAuthority(auth *system.SysAuthority) (err error) {
|
||||
if !errors.Is(global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).First(&system.SysUser{}).Error, gorm.ErrRecordNotFound) {
|
||||
return errors.New("此角色有用户正在使用禁止删除")
|
||||
}
|
||||
@@ -87,7 +92,7 @@ func DeleteAuthority(auth *system.SysAuthority) (err error) {
|
||||
} else {
|
||||
err = db.Error
|
||||
}
|
||||
ClearCasbin(0, auth.AuthorityId)
|
||||
CasbinServiceApp.ClearCasbin(0, auth.AuthorityId)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -97,7 +102,7 @@ func DeleteAuthority(auth *system.SysAuthority) (err error) {
|
||||
//@param: info request.PageInfo
|
||||
//@return: err error, list interface{}, total int64
|
||||
|
||||
func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, total int64) {
|
||||
func (authorityService *AuthorityService) GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, total int64) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
db := global.GVA_DB
|
||||
@@ -105,7 +110,7 @@ func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, t
|
||||
err = db.Limit(limit).Offset(offset).Preload("DataAuthorityId").Where("parent_id = 0").Find(&authority).Error
|
||||
if len(authority) > 0 {
|
||||
for k := range authority {
|
||||
err = findChildrenAuthority(&authority[k])
|
||||
err = authorityService.findChildrenAuthority(&authority[k])
|
||||
}
|
||||
}
|
||||
return err, authority, total
|
||||
@@ -117,7 +122,7 @@ func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, t
|
||||
//@param: auth model.SysAuthority
|
||||
//@return: err error, sa model.SysAuthority
|
||||
|
||||
func GetAuthorityInfo(auth system.SysAuthority) (err error, sa system.SysAuthority) {
|
||||
func (authorityService *AuthorityService) GetAuthorityInfo(auth system.SysAuthority) (err error, sa system.SysAuthority) {
|
||||
err = global.GVA_DB.Preload("DataAuthorityId").Where("authority_id = ?", auth.AuthorityId).First(&sa).Error
|
||||
return err, sa
|
||||
}
|
||||
@@ -128,7 +133,7 @@ func GetAuthorityInfo(auth system.SysAuthority) (err error, sa system.SysAuthori
|
||||
//@param: auth model.SysAuthority
|
||||
//@return: error
|
||||
|
||||
func SetDataAuthority(auth system.SysAuthority) error {
|
||||
func (authorityService *AuthorityService) SetDataAuthority(auth system.SysAuthority) error {
|
||||
var s system.SysAuthority
|
||||
global.GVA_DB.Preload("DataAuthorityId").First(&s, "authority_id = ?", auth.AuthorityId)
|
||||
err := global.GVA_DB.Model(&s).Association("DataAuthorityId").Replace(&auth.DataAuthorityId)
|
||||
@@ -141,7 +146,7 @@ func SetDataAuthority(auth system.SysAuthority) error {
|
||||
//@param: auth *model.SysAuthority
|
||||
//@return: error
|
||||
|
||||
func SetMenuAuthority(auth *system.SysAuthority) error {
|
||||
func (authorityService *AuthorityService) SetMenuAuthority(auth *system.SysAuthority) error {
|
||||
var s system.SysAuthority
|
||||
global.GVA_DB.Preload("SysBaseMenus").First(&s, "authority_id = ?", auth.AuthorityId)
|
||||
err := global.GVA_DB.Model(&s).Association("SysBaseMenus").Replace(&auth.SysBaseMenus)
|
||||
@@ -154,11 +159,11 @@ func SetMenuAuthority(auth *system.SysAuthority) error {
|
||||
//@param: authority *model.SysAuthority
|
||||
//@return: err error
|
||||
|
||||
func findChildrenAuthority(authority *system.SysAuthority) (err error) {
|
||||
func (authorityService *AuthorityService) findChildrenAuthority(authority *system.SysAuthority) (err error) {
|
||||
err = global.GVA_DB.Preload("DataAuthorityId").Where("parent_id = ?", authority.AuthorityId).Find(&authority.Children).Error
|
||||
if len(authority.Children) > 0 {
|
||||
for k := range authority.Children {
|
||||
err = findChildrenAuthority(&authority.Children[k])
|
||||
err = authorityService.findChildrenAuthority(&authority.Children[k])
|
||||
}
|
||||
}
|
||||
return err
|
||||
@@ -1,4 +1,4 @@
|
||||
package service
|
||||
package system
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -30,14 +30,19 @@ type tplData struct {
|
||||
autoMoveFilePath string
|
||||
}
|
||||
|
||||
type AutoCodeService struct {
|
||||
}
|
||||
|
||||
var AutoCodeServiceApp = new(AutoCodeService)
|
||||
|
||||
//@author: [songzhibin97](https://github.com/songzhibin97)
|
||||
//@function: PreviewTemp
|
||||
//@description: 预览创建代码
|
||||
//@param: model.AutoCodeStruct
|
||||
//@return: map[string]string, error
|
||||
|
||||
func PreviewTemp(autoCode system.AutoCodeStruct) (map[string]string, error) {
|
||||
dataList, _, needMkdir, err := getNeedList(&autoCode)
|
||||
func (autoCodeService *AutoCodeService) PreviewTemp(autoCode system.AutoCodeStruct) (map[string]string, error) {
|
||||
dataList, _, needMkdir, err := autoCodeService.getNeedList(&autoCode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -101,8 +106,8 @@ func PreviewTemp(autoCode system.AutoCodeStruct) (map[string]string, error) {
|
||||
//@param: model.AutoCodeStruct
|
||||
//@return: err error
|
||||
|
||||
func CreateTemp(autoCode system.AutoCodeStruct, ids ...uint) (err error) {
|
||||
dataList, fileList, needMkdir, err := getNeedList(&autoCode)
|
||||
func (autoCodeService *AutoCodeService) CreateTemp(autoCode system.AutoCodeStruct, ids ...uint) (err error) {
|
||||
dataList, fileList, needMkdir, err := autoCodeService.getNeedList(&autoCode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -137,8 +142,8 @@ func CreateTemp(autoCode system.AutoCodeStruct, ids ...uint) (err error) {
|
||||
idBf.WriteString(";")
|
||||
}
|
||||
if autoCode.AutoMoveFile { // 判断是否需要自动转移
|
||||
for index, _ := range dataList {
|
||||
addAutoMoveFile(&dataList[index])
|
||||
for index := range dataList {
|
||||
autoCodeService.addAutoMoveFile(&dataList[index])
|
||||
}
|
||||
for _, value := range dataList { // 移动文件
|
||||
if err := utils.FileMove(value.autoCodePath, value.autoMoveFilePath); err != nil {
|
||||
@@ -183,7 +188,7 @@ func CreateTemp(autoCode system.AutoCodeStruct, ids ...uint) (err error) {
|
||||
}
|
||||
if autoCode.AutoMoveFile || autoCode.AutoCreateApiToSql {
|
||||
if autoCode.TableName != "" {
|
||||
err = CreateAutoCodeHistory(
|
||||
err = AutoCodeHistoryServiceApp.CreateAutoCodeHistory(
|
||||
string(meta),
|
||||
autoCode.StructName,
|
||||
autoCode.Description,
|
||||
@@ -193,7 +198,7 @@ func CreateTemp(autoCode system.AutoCodeStruct, ids ...uint) (err error) {
|
||||
idBf.String(),
|
||||
)
|
||||
} else {
|
||||
err = CreateAutoCodeHistory(
|
||||
err = AutoCodeHistoryServiceApp.CreateAutoCodeHistory(
|
||||
string(meta),
|
||||
autoCode.StructName,
|
||||
autoCode.Description,
|
||||
@@ -220,11 +225,11 @@ func CreateTemp(autoCode system.AutoCodeStruct, ids ...uint) (err error) {
|
||||
//@param: pathName string, fileList []string
|
||||
//@return: []string, error
|
||||
|
||||
func GetAllTplFile(pathName string, fileList []string) ([]string, error) {
|
||||
func (autoCodeService *AutoCodeService) GetAllTplFile(pathName string, fileList []string) ([]string, error) {
|
||||
files, err := ioutil.ReadDir(pathName)
|
||||
for _, fi := range files {
|
||||
if fi.IsDir() {
|
||||
fileList, err = GetAllTplFile(pathName+"/"+fi.Name(), fileList)
|
||||
fileList, err = autoCodeService.GetAllTplFile(pathName+"/"+fi.Name(), fileList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -243,7 +248,7 @@ func GetAllTplFile(pathName string, fileList []string) ([]string, error) {
|
||||
//@param: dbName string
|
||||
//@return: err error, TableNames []request.TableReq
|
||||
|
||||
func GetTables(dbName string) (err error, TableNames []request.TableReq) {
|
||||
func (autoCodeService *AutoCodeService) GetTables(dbName string) (err error, TableNames []request.TableReq) {
|
||||
err = global.GVA_DB.Raw("select table_name as table_name from information_schema.tables where table_schema = ?", dbName).Scan(&TableNames).Error
|
||||
return err, TableNames
|
||||
}
|
||||
@@ -253,7 +258,7 @@ func GetTables(dbName string) (err error, TableNames []request.TableReq) {
|
||||
//@description: 获取数据库的所有数据库名
|
||||
//@return: err error, DBNames []request.DBReq
|
||||
|
||||
func GetDB() (err error, DBNames []request.DBReq) {
|
||||
func (autoCodeService *AutoCodeService) GetDB() (err error, DBNames []request.DBReq) {
|
||||
err = global.GVA_DB.Raw("SELECT SCHEMA_NAME AS `database` FROM INFORMATION_SCHEMA.SCHEMATA;").Scan(&DBNames).Error
|
||||
return err, DBNames
|
||||
}
|
||||
@@ -264,12 +269,12 @@ func GetDB() (err error, DBNames []request.DBReq) {
|
||||
//@param: tableName string, dbName string
|
||||
//@return: err error, Columns []request.ColumnReq
|
||||
|
||||
func GetColumn(tableName string, dbName string) (err error, Columns []request.ColumnReq) {
|
||||
func (autoCodeService *AutoCodeService) GetColumn(tableName string, dbName string) (err error, Columns []request.ColumnReq) {
|
||||
err = global.GVA_DB.Raw("SELECT COLUMN_NAME column_name,DATA_TYPE data_type,CASE DATA_TYPE WHEN 'longtext' THEN c.CHARACTER_MAXIMUM_LENGTH WHEN 'varchar' THEN c.CHARACTER_MAXIMUM_LENGTH WHEN 'double' THEN CONCAT_WS( ',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE ) WHEN 'decimal' THEN CONCAT_WS( ',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE ) WHEN 'int' THEN c.NUMERIC_PRECISION WHEN 'bigint' THEN c.NUMERIC_PRECISION ELSE '' END AS data_type_long,COLUMN_COMMENT column_comment FROM INFORMATION_SCHEMA.COLUMNS c WHERE table_name = ? AND table_schema = ?", tableName, dbName).Scan(&Columns).Error
|
||||
return err, Columns
|
||||
}
|
||||
|
||||
func DropTable(tableName string) error {
|
||||
func (autoCodeService *AutoCodeService) DropTable(tableName string) error {
|
||||
return global.GVA_DB.Exec("DROP TABLE " + tableName).Error
|
||||
}
|
||||
|
||||
@@ -280,7 +285,7 @@ func DropTable(tableName string) error {
|
||||
//@param: *tplData
|
||||
//@return: null
|
||||
|
||||
func addAutoMoveFile(data *tplData) {
|
||||
func (autoCodeService *AutoCodeService) addAutoMoveFile(data *tplData) {
|
||||
base := filepath.Base(data.autoCodePath)
|
||||
fileSlice := strings.Split(data.autoCodePath, string(os.PathSeparator))
|
||||
n := len(fileSlice)
|
||||
@@ -325,7 +330,7 @@ func addAutoMoveFile(data *tplData) {
|
||||
//@param: a *model.AutoCodeStruct
|
||||
//@return: err error
|
||||
|
||||
func AutoCreateApi(a *system.AutoCodeStruct) (ids []uint, err error) {
|
||||
func (autoCodeService *AutoCodeService) AutoCreateApi(a *system.AutoCodeStruct) (ids []uint, err error) {
|
||||
var apiList = []system.SysApi{
|
||||
{
|
||||
Path: "/" + a.Abbreviation + "/" + "create" + a.StructName,
|
||||
@@ -381,14 +386,14 @@ func AutoCreateApi(a *system.AutoCodeStruct) (ids []uint, err error) {
|
||||
return ids, err
|
||||
}
|
||||
|
||||
func getNeedList(autoCode *system.AutoCodeStruct) (dataList []tplData, fileList []string, needMkdir []string, err error) {
|
||||
func (autoCodeService *AutoCodeService) getNeedList(autoCode *system.AutoCodeStruct) (dataList []tplData, fileList []string, needMkdir []string, err error) {
|
||||
// 去除所有空格
|
||||
utils.TrimSpace(autoCode)
|
||||
for _, field := range autoCode.Fields {
|
||||
utils.TrimSpace(field)
|
||||
}
|
||||
// 获取 basePath 文件夹下所有tpl文件
|
||||
tplFileList, err := GetAllTplFile(basePath, nil)
|
||||
tplFileList, err := autoCodeService.GetAllTplFile(basePath, nil)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
+15
-10
@@ -1,8 +1,8 @@
|
||||
package service
|
||||
package system
|
||||
|
||||
import (
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model/request"
|
||||
"gin-vue-admin/model/common/request"
|
||||
"gin-vue-admin/model/system"
|
||||
"gin-vue-admin/utils"
|
||||
"strings"
|
||||
@@ -10,8 +10,13 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type AutoCodeHistoryService struct {
|
||||
}
|
||||
|
||||
var AutoCodeHistoryServiceApp = new(AutoCodeHistoryService)
|
||||
|
||||
// CreateAutoCodeHistory RouterPath : RouterPath@RouterString;RouterPath2@RouterString2
|
||||
func CreateAutoCodeHistory(meta, structName, structCNName, autoCodePath string, injectionMeta string, tableName string, apiIds string) error {
|
||||
func (autoCodeHistoryService *AutoCodeHistoryService) CreateAutoCodeHistory(meta, structName, structCNName, autoCodePath string, injectionMeta string, tableName string, apiIds string) error {
|
||||
return global.GVA_DB.Create(&system.SysAutoCodeHistory{
|
||||
RequestMeta: meta,
|
||||
AutoCodePath: autoCodePath,
|
||||
@@ -24,18 +29,18 @@ func CreateAutoCodeHistory(meta, structName, structCNName, autoCodePath string,
|
||||
}
|
||||
|
||||
// RollBack 回滚
|
||||
func RollBack(id uint) error {
|
||||
func (autoCodeHistoryService *AutoCodeHistoryService) RollBack(id uint) error {
|
||||
md := system.SysAutoCodeHistory{}
|
||||
if err := global.GVA_DB.First(&md, id).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
// 清除API表
|
||||
err := DeleteApiByIds(strings.Split(md.ApiIDs, ";"))
|
||||
err := ApiServiceApp.DeleteApiByIds(strings.Split(md.ApiIDs, ";"))
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("ClearTag DeleteApiByIds:", zap.Error(err))
|
||||
}
|
||||
// 获取全部表名
|
||||
err, dbNames := GetTables(global.GVA_CONFIG.Mysql.Dbname)
|
||||
err, dbNames := AutoCodeServiceApp.GetTables(global.GVA_CONFIG.Mysql.Dbname)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("ClearTag GetTables:", zap.Error(err))
|
||||
}
|
||||
@@ -43,7 +48,7 @@ func RollBack(id uint) error {
|
||||
for _, name := range dbNames {
|
||||
if strings.Contains(strings.ToUpper(strings.Replace(name.TableName, "_", "", -1)), strings.ToUpper(md.TableName)) {
|
||||
// 删除表
|
||||
if err = DropTable(name.TableName); err != nil {
|
||||
if err = AutoCodeServiceApp.DropTable(name.TableName); err != nil {
|
||||
global.GVA_LOG.Error("ClearTag DropTable:", zap.Error(err))
|
||||
|
||||
}
|
||||
@@ -65,13 +70,13 @@ func RollBack(id uint) error {
|
||||
return global.GVA_DB.Save(&md).Error
|
||||
}
|
||||
|
||||
func GetMeta(id uint) (string, error) {
|
||||
func (autoCodeHistoryService *AutoCodeHistoryService) GetMeta(id uint) (string, error) {
|
||||
var meta string
|
||||
return meta, global.GVA_DB.Model(system.SysAutoCodeHistory{}).Select("request_meta").First(&meta, id).Error
|
||||
}
|
||||
|
||||
// GetSysHistoryPage 获取系统历史数据
|
||||
func GetSysHistoryPage(info request.PageInfo) (err error, list interface{}, total int64) {
|
||||
func (autoCodeHistoryService *AutoCodeHistoryService) GetSysHistoryPage(info request.PageInfo) (err error, list interface{}, total int64) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
db := global.GVA_DB
|
||||
@@ -82,6 +87,6 @@ func GetSysHistoryPage(info request.PageInfo) (err error, list interface{}, tota
|
||||
}
|
||||
|
||||
// DeletePage 删除历史数据
|
||||
func DeletePage(id uint) error {
|
||||
func (autoCodeHistoryService *AutoCodeHistoryService) DeletePage(id uint) error {
|
||||
return global.GVA_DB.Delete(system.SysAutoCodeHistory{}, id).Error
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package service
|
||||
package system
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -7,13 +7,16 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type BaseMenuService struct {
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: DeleteBaseMenu
|
||||
//@description: 删除基础路由
|
||||
//@param: id float64
|
||||
//@return: err error
|
||||
|
||||
func DeleteBaseMenu(id float64) (err error) {
|
||||
func (baseMenuService *BaseMenuService) DeleteBaseMenu(id float64) (err error) {
|
||||
err = global.GVA_DB.Preload("Parameters").Where("parent_id = ?", id).First(&system.SysBaseMenu{}).Error
|
||||
if err != nil {
|
||||
var menu system.SysBaseMenu
|
||||
@@ -36,7 +39,7 @@ func DeleteBaseMenu(id float64) (err error) {
|
||||
//@param: menu model.SysBaseMenu
|
||||
//@return: err error
|
||||
|
||||
func UpdateBaseMenu(menu system.SysBaseMenu) (err error) {
|
||||
func (baseMenuService *BaseMenuService) UpdateBaseMenu(menu system.SysBaseMenu) (err error) {
|
||||
var oldMenu system.SysBaseMenu
|
||||
upDateMap := make(map[string]interface{})
|
||||
upDateMap["keep_alive"] = menu.KeepAlive
|
||||
@@ -65,7 +68,7 @@ func UpdateBaseMenu(menu system.SysBaseMenu) (err error) {
|
||||
return txErr
|
||||
}
|
||||
if len(menu.Parameters) > 0 {
|
||||
for k, _ := range menu.Parameters {
|
||||
for k := range menu.Parameters {
|
||||
menu.Parameters[k].SysBaseMenuID = menu.ID
|
||||
}
|
||||
txErr = tx.Create(&menu.Parameters).Error
|
||||
@@ -91,7 +94,7 @@ func UpdateBaseMenu(menu system.SysBaseMenu) (err error) {
|
||||
//@param: id float64
|
||||
//@return: err error, menu model.SysBaseMenu
|
||||
|
||||
func GetBaseMenuById(id float64) (err error, menu system.SysBaseMenu) {
|
||||
func (baseMenuService *BaseMenuService) GetBaseMenuById(id float64) (err error, menu system.SysBaseMenu) {
|
||||
err = global.GVA_DB.Preload("Parameters").Where("id = ?", id).First(&menu).Error
|
||||
return
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package service
|
||||
package system
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -19,8 +19,13 @@ import (
|
||||
//@param: authorityId string, casbinInfos []request.CasbinInfo
|
||||
//@return: error
|
||||
|
||||
func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error {
|
||||
ClearCasbin(0, authorityId)
|
||||
type CasbinService struct {
|
||||
}
|
||||
|
||||
var CasbinServiceApp = new(CasbinService)
|
||||
|
||||
func (casbinService *CasbinService) UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error {
|
||||
casbinService.ClearCasbin(0, authorityId)
|
||||
rules := [][]string{}
|
||||
for _, v := range casbinInfos {
|
||||
cm := system.CasbinModel{
|
||||
@@ -31,7 +36,7 @@ func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error {
|
||||
}
|
||||
rules = append(rules, []string{cm.AuthorityId, cm.Path, cm.Method})
|
||||
}
|
||||
e := Casbin()
|
||||
e := casbinService.Casbin()
|
||||
success, _ := e.AddPolicies(rules)
|
||||
if success == false {
|
||||
return errors.New("存在相同api,添加失败,请联系管理员")
|
||||
@@ -45,7 +50,7 @@ func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error {
|
||||
//@param: oldPath string, newPath string, oldMethod string, newMethod string
|
||||
//@return: error
|
||||
|
||||
func UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod string) error {
|
||||
func (casbinService *CasbinService) UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod string) error {
|
||||
err := global.GVA_DB.Table("casbin_rule").Model(&system.CasbinModel{}).Where("v1 = ? AND v2 = ?", oldPath, oldMethod).Updates(map[string]interface{}{
|
||||
"v1": newPath,
|
||||
"v2": newMethod,
|
||||
@@ -59,8 +64,8 @@ func UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod
|
||||
//@param: authorityId string
|
||||
//@return: pathMaps []request.CasbinInfo
|
||||
|
||||
func GetPolicyPathByAuthorityId(authorityId string) (pathMaps []request.CasbinInfo) {
|
||||
e := Casbin()
|
||||
func (casbinService *CasbinService) GetPolicyPathByAuthorityId(authorityId string) (pathMaps []request.CasbinInfo) {
|
||||
e := casbinService.Casbin()
|
||||
list := e.GetFilteredPolicy(0, authorityId)
|
||||
for _, v := range list {
|
||||
pathMaps = append(pathMaps, request.CasbinInfo{
|
||||
@@ -77,8 +82,8 @@ func GetPolicyPathByAuthorityId(authorityId string) (pathMaps []request.CasbinIn
|
||||
//@param: v int, p ...string
|
||||
//@return: bool
|
||||
|
||||
func ClearCasbin(v int, p ...string) bool {
|
||||
e := Casbin()
|
||||
func (casbinService *CasbinService) ClearCasbin(v int, p ...string) bool {
|
||||
e := casbinService.Casbin()
|
||||
success, _ := e.RemoveFilteredPolicy(v, p...)
|
||||
return success
|
||||
|
||||
@@ -94,11 +99,11 @@ var (
|
||||
once sync.Once
|
||||
)
|
||||
|
||||
func Casbin() *casbin.SyncedEnforcer {
|
||||
func (casbinService *CasbinService) Casbin() *casbin.SyncedEnforcer {
|
||||
once.Do(func() {
|
||||
a, _ := gormadapter.NewAdapterByDB(global.GVA_DB)
|
||||
syncedEnforcer, _ = casbin.NewSyncedEnforcer(global.GVA_CONFIG.Casbin.ModelPath, a)
|
||||
syncedEnforcer.AddFunction("ParamsMatch", ParamsMatchFunc)
|
||||
syncedEnforcer.AddFunction("ParamsMatch", casbinService.ParamsMatchFunc)
|
||||
})
|
||||
_ = syncedEnforcer.LoadPolicy()
|
||||
return syncedEnforcer
|
||||
@@ -110,7 +115,7 @@ func Casbin() *casbin.SyncedEnforcer {
|
||||
//@param: fullNameKey1 string, key2 string
|
||||
//@return: bool
|
||||
|
||||
func ParamsMatch(fullNameKey1 string, key2 string) bool {
|
||||
func (casbinService *CasbinService) ParamsMatch(fullNameKey1 string, key2 string) bool {
|
||||
key1 := strings.Split(fullNameKey1, "?")[0]
|
||||
// 剥离路径后再使用casbin的keyMatch2
|
||||
return util.KeyMatch2(key1, key2)
|
||||
@@ -122,9 +127,9 @@ func ParamsMatch(fullNameKey1 string, key2 string) bool {
|
||||
//@param: args ...interface{}
|
||||
//@return: interface{}, error
|
||||
|
||||
func ParamsMatchFunc(args ...interface{}) (interface{}, error) {
|
||||
func (casbinService *CasbinService) ParamsMatchFunc(args ...interface{}) (interface{}, error) {
|
||||
name1 := args[0].(string)
|
||||
name2 := args[1].(string)
|
||||
|
||||
return ParamsMatch(name1, name2), nil
|
||||
return casbinService.ParamsMatch(name1, name2), nil
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package service
|
||||
package system
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -14,7 +14,10 @@ import (
|
||||
//@param: sysDictionary model.SysDictionary
|
||||
//@return: err error
|
||||
|
||||
func CreateSysDictionary(sysDictionary system.SysDictionary) (err error) {
|
||||
type DictionaryService struct {
|
||||
}
|
||||
|
||||
func (dictionaryService *DictionaryService) CreateSysDictionary(sysDictionary system.SysDictionary) (err error) {
|
||||
if (!errors.Is(global.GVA_DB.First(&system.SysDictionary{}, "type = ?", sysDictionary.Type).Error, gorm.ErrRecordNotFound)) {
|
||||
return errors.New("存在相同的type,不允许创建")
|
||||
}
|
||||
@@ -28,7 +31,7 @@ func CreateSysDictionary(sysDictionary system.SysDictionary) (err error) {
|
||||
//@param: sysDictionary model.SysDictionary
|
||||
//@return: err error
|
||||
|
||||
func DeleteSysDictionary(sysDictionary system.SysDictionary) (err error) {
|
||||
func (dictionaryService *DictionaryService) DeleteSysDictionary(sysDictionary system.SysDictionary) (err error) {
|
||||
err = global.GVA_DB.Delete(&sysDictionary).Delete(&sysDictionary.SysDictionaryDetails).Error
|
||||
return err
|
||||
}
|
||||
@@ -39,7 +42,7 @@ func DeleteSysDictionary(sysDictionary system.SysDictionary) (err error) {
|
||||
//@param: sysDictionary *model.SysDictionary
|
||||
//@return: err error
|
||||
|
||||
func UpdateSysDictionary(sysDictionary *system.SysDictionary) (err error) {
|
||||
func (dictionaryService *DictionaryService) UpdateSysDictionary(sysDictionary *system.SysDictionary) (err error) {
|
||||
var dict system.SysDictionary
|
||||
sysDictionaryMap := map[string]interface{}{
|
||||
"Name": sysDictionary.Name,
|
||||
@@ -66,7 +69,7 @@ func UpdateSysDictionary(sysDictionary *system.SysDictionary) (err error) {
|
||||
//@param: Type string, Id uint
|
||||
//@return: err error, sysDictionary model.SysDictionary
|
||||
|
||||
func GetSysDictionary(Type string, Id uint) (err error, sysDictionary system.SysDictionary) {
|
||||
func (dictionaryService *DictionaryService) GetSysDictionary(Type string, Id uint) (err error, sysDictionary system.SysDictionary) {
|
||||
err = global.GVA_DB.Where("type = ? OR id = ?", Type, Id).Preload("SysDictionaryDetails").First(&sysDictionary).Error
|
||||
return
|
||||
}
|
||||
@@ -78,7 +81,7 @@ func GetSysDictionary(Type string, Id uint) (err error, sysDictionary system.Sys
|
||||
//@param: info request.SysDictionarySearch
|
||||
//@return: err error, list interface{}, total int64
|
||||
|
||||
func GetSysDictionaryInfoList(info request.SysDictionarySearch) (err error, list interface{}, total int64) {
|
||||
func (dictionaryService *DictionaryService) GetSysDictionaryInfoList(info request.SysDictionarySearch) (err error, list interface{}, total int64) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
// 创建db
|
||||
+9
-6
@@ -1,4 +1,4 @@
|
||||
package service
|
||||
package system
|
||||
|
||||
import (
|
||||
"gin-vue-admin/global"
|
||||
@@ -12,7 +12,10 @@ import (
|
||||
//@param: sysDictionaryDetail model.SysDictionaryDetail
|
||||
//@return: err error
|
||||
|
||||
func CreateSysDictionaryDetail(sysDictionaryDetail system.SysDictionaryDetail) (err error) {
|
||||
type DictionaryDetailService struct {
|
||||
}
|
||||
|
||||
func (dictionaryDetailService *DictionaryDetailService) CreateSysDictionaryDetail(sysDictionaryDetail system.SysDictionaryDetail) (err error) {
|
||||
err = global.GVA_DB.Create(&sysDictionaryDetail).Error
|
||||
return err
|
||||
}
|
||||
@@ -23,7 +26,7 @@ func CreateSysDictionaryDetail(sysDictionaryDetail system.SysDictionaryDetail) (
|
||||
//@param: sysDictionaryDetail model.SysDictionaryDetail
|
||||
//@return: err error
|
||||
|
||||
func DeleteSysDictionaryDetail(sysDictionaryDetail system.SysDictionaryDetail) (err error) {
|
||||
func (dictionaryDetailService *DictionaryDetailService) DeleteSysDictionaryDetail(sysDictionaryDetail system.SysDictionaryDetail) (err error) {
|
||||
err = global.GVA_DB.Delete(&sysDictionaryDetail).Error
|
||||
return err
|
||||
}
|
||||
@@ -34,7 +37,7 @@ func DeleteSysDictionaryDetail(sysDictionaryDetail system.SysDictionaryDetail) (
|
||||
//@param: sysDictionaryDetail *model.SysDictionaryDetail
|
||||
//@return: err error
|
||||
|
||||
func UpdateSysDictionaryDetail(sysDictionaryDetail *system.SysDictionaryDetail) (err error) {
|
||||
func (dictionaryDetailService *DictionaryDetailService) UpdateSysDictionaryDetail(sysDictionaryDetail *system.SysDictionaryDetail) (err error) {
|
||||
err = global.GVA_DB.Save(sysDictionaryDetail).Error
|
||||
return err
|
||||
}
|
||||
@@ -45,7 +48,7 @@ func UpdateSysDictionaryDetail(sysDictionaryDetail *system.SysDictionaryDetail)
|
||||
//@param: id uint
|
||||
//@return: err error, sysDictionaryDetail model.SysDictionaryDetail
|
||||
|
||||
func GetSysDictionaryDetail(id uint) (err error, sysDictionaryDetail system.SysDictionaryDetail) {
|
||||
func (dictionaryDetailService *DictionaryDetailService) GetSysDictionaryDetail(id uint) (err error, sysDictionaryDetail system.SysDictionaryDetail) {
|
||||
err = global.GVA_DB.Where("id = ?", id).First(&sysDictionaryDetail).Error
|
||||
return
|
||||
}
|
||||
@@ -56,7 +59,7 @@ func GetSysDictionaryDetail(id uint) (err error, sysDictionaryDetail system.SysD
|
||||
//@param: info request.SysDictionaryDetailSearch
|
||||
//@return: err error, list interface{}, total int64
|
||||
|
||||
func GetSysDictionaryDetailInfoList(info request.SysDictionaryDetailSearch) (err error, list interface{}, total int64) {
|
||||
func (dictionaryDetailService *DictionaryDetailService) GetSysDictionaryDetailInfoList(info request.SysDictionaryDetailSearch) (err error, list interface{}, total int64) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
// 创建db
|
||||
@@ -1,15 +1,18 @@
|
||||
package service
|
||||
package system
|
||||
|
||||
import (
|
||||
"gin-vue-admin/utils"
|
||||
)
|
||||
|
||||
type EmailService struct {
|
||||
}
|
||||
|
||||
//@author: [maplepie](https://github.com/maplepie)
|
||||
//@function: EmailTest
|
||||
//@description: 发送邮件测试
|
||||
//@return: err error
|
||||
|
||||
func EmailTest() (err error) {
|
||||
func (e *EmailService) EmailTest() (err error) {
|
||||
subject := "test"
|
||||
body := "test"
|
||||
err = utils.EmailTest(subject, body)
|
||||
@@ -1,4 +1,4 @@
|
||||
package service
|
||||
package system
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
@@ -23,7 +23,10 @@ import (
|
||||
//@param: viper *viper.Viper, mysql config.Mysql
|
||||
//@return: error
|
||||
|
||||
func writeConfig(viper *viper.Viper, mysql config.Mysql) error {
|
||||
type InitDBService struct {
|
||||
}
|
||||
|
||||
func (initDBService *InitDBService) writeConfig(viper *viper.Viper, mysql config.Mysql) error {
|
||||
global.GVA_CONFIG.Mysql = mysql
|
||||
cs := utils.StructToMap(global.GVA_CONFIG)
|
||||
for k, v := range cs {
|
||||
@@ -38,7 +41,7 @@ func writeConfig(viper *viper.Viper, mysql config.Mysql) error {
|
||||
//@param: dsn string, driver string, createSql
|
||||
//@return: error
|
||||
|
||||
func createTable(dsn string, driver string, createSql string) error {
|
||||
func (initDBService *InitDBService) createTable(dsn string, driver string, createSql string) error {
|
||||
db, err := sql.Open(driver, dsn)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -56,7 +59,7 @@ func createTable(dsn string, driver string, createSql string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func initDB(InitDBFunctions ...system.InitDBFunc) (err error) {
|
||||
func (initDBService *InitDBService) initDB(InitDBFunctions ...system.InitDBFunc) (err error) {
|
||||
for _, v := range InitDBFunctions {
|
||||
err = v.Init()
|
||||
if err != nil {
|
||||
@@ -72,7 +75,7 @@ func initDB(InitDBFunctions ...system.InitDBFunc) (err error) {
|
||||
//@param: conf request.InitDB
|
||||
//@return: error
|
||||
|
||||
func InitDB(conf request.InitDB) error {
|
||||
func (initDBService *InitDBService) InitDB(conf request.InitDB) error {
|
||||
|
||||
if conf.Host == "" {
|
||||
conf.Host = "127.0.0.1"
|
||||
@@ -83,7 +86,7 @@ func InitDB(conf request.InitDB) error {
|
||||
}
|
||||
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/", conf.UserName, conf.Password, conf.Host, conf.Port)
|
||||
createSql := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS `%s` DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci;", conf.DBName)
|
||||
if err := createTable(dsn, "mysql", createSql); err != nil {
|
||||
if err := initDBService.createTable(dsn, "mysql", createSql); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -138,7 +141,7 @@ func InitDB(conf request.InitDB) error {
|
||||
global.GVA_DB = nil
|
||||
return err
|
||||
}
|
||||
err = initDB(
|
||||
err = initDBService.initDB(
|
||||
source.Admin,
|
||||
source.Api,
|
||||
source.AuthorityMenu,
|
||||
@@ -154,7 +157,7 @@ func InitDB(conf request.InitDB) error {
|
||||
global.GVA_DB = nil
|
||||
return err
|
||||
}
|
||||
if err = writeConfig(global.GVA_VP, MysqlConfig); err != nil {
|
||||
if err = initDBService.writeConfig(global.GVA_VP, MysqlConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
global.GVA_CONFIG.AutoCode.Root, _ = filepath.Abs("..")
|
||||
@@ -1,10 +1,10 @@
|
||||
package service
|
||||
package system
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model/common/request"
|
||||
"gin-vue-admin/model/system"
|
||||
"gin-vue-admin/model/system/request"
|
||||
"gorm.io/gorm"
|
||||
"strconv"
|
||||
)
|
||||
@@ -15,7 +15,12 @@ import (
|
||||
//@param: authorityId string
|
||||
//@return: err error, treeMap map[string][]model.SysMenu
|
||||
|
||||
func getMenuTreeMap(authorityId string) (err error, treeMap map[string][]system.SysMenu) {
|
||||
type MenuService struct {
|
||||
}
|
||||
|
||||
var MenuServiceApp = new(MenuService)
|
||||
|
||||
func (menuService *MenuService) getMenuTreeMap(authorityId string) (err error, treeMap map[string][]system.SysMenu) {
|
||||
var allMenus []system.SysMenu
|
||||
treeMap = make(map[string][]system.SysMenu)
|
||||
err = global.GVA_DB.Where("authority_id = ?", authorityId).Order("sort").Preload("Parameters").Find(&allMenus).Error
|
||||
@@ -31,11 +36,11 @@ func getMenuTreeMap(authorityId string) (err error, treeMap map[string][]system.
|
||||
//@param: authorityId string
|
||||
//@return: err error, menus []model.SysMenu
|
||||
|
||||
func GetMenuTree(authorityId string) (err error, menus []system.SysMenu) {
|
||||
err, menuTree := getMenuTreeMap(authorityId)
|
||||
func (menuService *MenuService) GetMenuTree(authorityId string) (err error, menus []system.SysMenu) {
|
||||
err, menuTree := menuService.getMenuTreeMap(authorityId)
|
||||
menus = menuTree["0"]
|
||||
for i := 0; i < len(menus); i++ {
|
||||
err = getChildrenList(&menus[i], menuTree)
|
||||
err = menuService.getChildrenList(&menus[i], menuTree)
|
||||
}
|
||||
return err, menus
|
||||
}
|
||||
@@ -46,10 +51,10 @@ func GetMenuTree(authorityId string) (err error, menus []system.SysMenu) {
|
||||
//@param: menu *model.SysMenu, treeMap map[string][]model.SysMenu
|
||||
//@return: err error
|
||||
|
||||
func getChildrenList(menu *system.SysMenu, treeMap map[string][]system.SysMenu) (err error) {
|
||||
func (menuService *MenuService) getChildrenList(menu *system.SysMenu, treeMap map[string][]system.SysMenu) (err error) {
|
||||
menu.Children = treeMap[menu.MenuId]
|
||||
for i := 0; i < len(menu.Children); i++ {
|
||||
err = getChildrenList(&menu.Children[i], treeMap)
|
||||
err = menuService.getChildrenList(&menu.Children[i], treeMap)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -59,12 +64,12 @@ func getChildrenList(menu *system.SysMenu, treeMap map[string][]system.SysMenu)
|
||||
//@description: 获取路由分页
|
||||
//@return: err error, list interface{}, total int64
|
||||
|
||||
func GetInfoList() (err error, list interface{}, total int64) {
|
||||
func (menuService *MenuService) GetInfoList() (err error, list interface{}, total int64) {
|
||||
var menuList []system.SysBaseMenu
|
||||
err, treeMap := getBaseMenuTreeMap()
|
||||
err, treeMap := menuService.getBaseMenuTreeMap()
|
||||
menuList = treeMap["0"]
|
||||
for i := 0; i < len(menuList); i++ {
|
||||
err = getBaseChildrenList(&menuList[i], treeMap)
|
||||
err = menuService.getBaseChildrenList(&menuList[i], treeMap)
|
||||
}
|
||||
return err, menuList, total
|
||||
}
|
||||
@@ -75,10 +80,10 @@ func GetInfoList() (err error, list interface{}, total int64) {
|
||||
//@param: menu *model.SysBaseMenu, treeMap map[string][]model.SysBaseMenu
|
||||
//@return: err error
|
||||
|
||||
func getBaseChildrenList(menu *system.SysBaseMenu, treeMap map[string][]system.SysBaseMenu) (err error) {
|
||||
func (menuService *MenuService) getBaseChildrenList(menu *system.SysBaseMenu, treeMap map[string][]system.SysBaseMenu) (err error) {
|
||||
menu.Children = treeMap[strconv.Itoa(int(menu.ID))]
|
||||
for i := 0; i < len(menu.Children); i++ {
|
||||
err = getBaseChildrenList(&menu.Children[i], treeMap)
|
||||
err = menuService.getBaseChildrenList(&menu.Children[i], treeMap)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -89,7 +94,7 @@ func getBaseChildrenList(menu *system.SysBaseMenu, treeMap map[string][]system.S
|
||||
//@param: menu model.SysBaseMenu
|
||||
//@return: error
|
||||
|
||||
func AddBaseMenu(menu system.SysBaseMenu) error {
|
||||
func (menuService *MenuService) AddBaseMenu(menu system.SysBaseMenu) error {
|
||||
if !errors.Is(global.GVA_DB.Where("name = ?", menu.Name).First(&system.SysBaseMenu{}).Error, gorm.ErrRecordNotFound) {
|
||||
return errors.New("存在重复name,请修改name")
|
||||
}
|
||||
@@ -101,7 +106,7 @@ func AddBaseMenu(menu system.SysBaseMenu) error {
|
||||
//@description: 获取路由总树map
|
||||
//@return: err error, treeMap map[string][]model.SysBaseMenu
|
||||
|
||||
func getBaseMenuTreeMap() (err error, treeMap map[string][]system.SysBaseMenu) {
|
||||
func (menuService *MenuService) getBaseMenuTreeMap() (err error, treeMap map[string][]system.SysBaseMenu) {
|
||||
var allMenus []system.SysBaseMenu
|
||||
treeMap = make(map[string][]system.SysBaseMenu)
|
||||
err = global.GVA_DB.Order("sort").Preload("Parameters").Find(&allMenus).Error
|
||||
@@ -116,11 +121,11 @@ func getBaseMenuTreeMap() (err error, treeMap map[string][]system.SysBaseMenu) {
|
||||
//@description: 获取基础路由树
|
||||
//@return: err error, menus []model.SysBaseMenu
|
||||
|
||||
func GetBaseMenuTree() (err error, menus []system.SysBaseMenu) {
|
||||
err, treeMap := getBaseMenuTreeMap()
|
||||
func (menuService *MenuService) GetBaseMenuTree() (err error, menus []system.SysBaseMenu) {
|
||||
err, treeMap := menuService.getBaseMenuTreeMap()
|
||||
menus = treeMap["0"]
|
||||
for i := 0; i < len(menus); i++ {
|
||||
err = getBaseChildrenList(&menus[i], treeMap)
|
||||
err = menuService.getBaseChildrenList(&menus[i], treeMap)
|
||||
}
|
||||
return err, menus
|
||||
}
|
||||
@@ -131,11 +136,11 @@ func GetBaseMenuTree() (err error, menus []system.SysBaseMenu) {
|
||||
//@param: menus []model.SysBaseMenu, authorityId string
|
||||
//@return: err error
|
||||
|
||||
func AddMenuAuthority(menus []system.SysBaseMenu, authorityId string) (err error) {
|
||||
func (menuService *MenuService) AddMenuAuthority(menus []system.SysBaseMenu, authorityId string) (err error) {
|
||||
var auth system.SysAuthority
|
||||
auth.AuthorityId = authorityId
|
||||
auth.SysBaseMenus = menus
|
||||
err = SetMenuAuthority(&auth)
|
||||
err = AuthorityServiceApp.SetMenuAuthority(&auth)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -145,7 +150,7 @@ func AddMenuAuthority(menus []system.SysBaseMenu, authorityId string) (err error
|
||||
//@param: info *request.GetAuthorityId
|
||||
//@return: err error, menus []model.SysMenu
|
||||
|
||||
func GetMenuAuthority(info *request.GetAuthorityId) (err error, menus []system.SysMenu) {
|
||||
func (menuService *MenuService) GetMenuAuthority(info *request.GetAuthorityId) (err error, menus []system.SysMenu) {
|
||||
err = global.GVA_DB.Where("authority_id = ? ", info.AuthorityId).Order("sort").Find(&menus).Error
|
||||
//sql := "SELECT authority_menu.keep_alive,authority_menu.default_menu,authority_menu.created_at,authority_menu.updated_at,authority_menu.deleted_at,authority_menu.menu_level,authority_menu.parent_id,authority_menu.path,authority_menu.`name`,authority_menu.hidden,authority_menu.component,authority_menu.title,authority_menu.icon,authority_menu.sort,authority_menu.menu_id,authority_menu.authority_id FROM authority_menu WHERE authority_menu.authority_id = ? ORDER BY authority_menu.sort ASC"
|
||||
//err = global.GVA_DB.Raw(sql, authorityId).Scan(&menus).Error
|
||||
+12
-8
@@ -1,9 +1,10 @@
|
||||
package service
|
||||
package system
|
||||
|
||||
import (
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model/common/request"
|
||||
"gin-vue-admin/model/system"
|
||||
"gin-vue-admin/model/system/request"
|
||||
systemReq "gin-vue-admin/model/system/request"
|
||||
)
|
||||
|
||||
//@author: [granty1](https://github.com/granty1)
|
||||
@@ -12,7 +13,10 @@ import (
|
||||
//@param: sysOperationRecord model.SysOperationRecord
|
||||
//@return: err error
|
||||
|
||||
func CreateSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err error) {
|
||||
type OperationRecordService struct {
|
||||
}
|
||||
|
||||
func (operationRecordService *OperationRecordService) CreateSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err error) {
|
||||
err = global.GVA_DB.Create(&sysOperationRecord).Error
|
||||
return err
|
||||
}
|
||||
@@ -24,7 +28,7 @@ func CreateSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err
|
||||
//@param: ids request.IdsReq
|
||||
//@return: err error
|
||||
|
||||
func DeleteSysOperationRecordByIds(ids request.IdsReq) (err error) {
|
||||
func (operationRecordService *OperationRecordService) DeleteSysOperationRecordByIds(ids request.IdsReq) (err error) {
|
||||
err = global.GVA_DB.Delete(&[]system.SysOperationRecord{}, "id in (?)", ids.Ids).Error
|
||||
return err
|
||||
}
|
||||
@@ -35,7 +39,7 @@ func DeleteSysOperationRecordByIds(ids request.IdsReq) (err error) {
|
||||
//@param: sysOperationRecord model.SysOperationRecord
|
||||
//@return: err error
|
||||
|
||||
func DeleteSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err error) {
|
||||
func (operationRecordService *OperationRecordService) DeleteSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err error) {
|
||||
err = global.GVA_DB.Delete(&sysOperationRecord).Error
|
||||
return err
|
||||
}
|
||||
@@ -46,7 +50,7 @@ func DeleteSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err
|
||||
//@param: id uint
|
||||
//@return: err error, sysOperationRecord model.SysOperationRecord
|
||||
|
||||
func GetSysOperationRecord(id uint) (err error, sysOperationRecord system.SysOperationRecord) {
|
||||
func (operationRecordService *OperationRecordService) GetSysOperationRecord(id uint) (err error, sysOperationRecord system.SysOperationRecord) {
|
||||
err = global.GVA_DB.Where("id = ?", id).First(&sysOperationRecord).Error
|
||||
return
|
||||
}
|
||||
@@ -55,10 +59,10 @@ func GetSysOperationRecord(id uint) (err error, sysOperationRecord system.SysOpe
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: GetSysOperationRecordInfoList
|
||||
//@description: 分页获取操作记录列表
|
||||
//@param: info request.SysOperationRecordSearch
|
||||
//@param: info systemReq.SysOperationRecordSearch
|
||||
//@return: err error, list interface{}, total int64
|
||||
|
||||
func GetSysOperationRecordInfoList(info request.SysOperationRecordSearch) (err error, list interface{}, total int64) {
|
||||
func (operationRecordService *OperationRecordService) GetSysOperationRecordInfoList(info systemReq.SysOperationRecordSearch) (err error, list interface{}, total int64) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
// 创建db
|
||||
@@ -1,4 +1,4 @@
|
||||
package service
|
||||
package system
|
||||
|
||||
import (
|
||||
"gin-vue-admin/config"
|
||||
@@ -13,7 +13,10 @@ import (
|
||||
//@description: 读取配置文件
|
||||
//@return: err error, conf config.Server
|
||||
|
||||
func GetSystemConfig() (err error, conf config.Server) {
|
||||
type SystemConfigService struct {
|
||||
}
|
||||
|
||||
func (systemConfigService *SystemConfigService) GetSystemConfig() (err error, conf config.Server) {
|
||||
return nil, global.GVA_CONFIG
|
||||
}
|
||||
|
||||
@@ -24,7 +27,7 @@ func GetSystemConfig() (err error, conf config.Server) {
|
||||
//@param: system model.System
|
||||
//@return: err error
|
||||
|
||||
func SetSystemConfig(system system.System) (err error) {
|
||||
func (systemConfigService *SystemConfigService) SetSystemConfig(system system.System) (err error) {
|
||||
cs := utils.StructToMap(system.Config)
|
||||
for k, v := range cs {
|
||||
global.GVA_VP.Set(k, v)
|
||||
@@ -38,7 +41,7 @@ func SetSystemConfig(system system.System) (err error) {
|
||||
//@description: 获取服务器信息
|
||||
//@return: server *utils.Server, err error
|
||||
|
||||
func GetServerInfo() (server *utils.Server, err error) {
|
||||
func (systemConfigService *SystemConfigService) GetServerInfo() (server *utils.Server, err error) {
|
||||
var s utils.Server
|
||||
s.Os = utils.InitOS()
|
||||
if s.Cpu, err = utils.InitCPU(); err != nil {
|
||||
@@ -1,10 +1,10 @@
|
||||
package service
|
||||
package system
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model/common/request"
|
||||
"gin-vue-admin/model/system"
|
||||
"gin-vue-admin/model/system/request"
|
||||
"gin-vue-admin/utils"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"gorm.io/gorm"
|
||||
@@ -16,7 +16,10 @@ import (
|
||||
//@param: u model.SysUser
|
||||
//@return: err error, userInter model.SysUser
|
||||
|
||||
func Register(u system.SysUser) (err error, userInter system.SysUser) {
|
||||
type UserService struct {
|
||||
}
|
||||
|
||||
func (userService *UserService) Register(u system.SysUser) (err error, userInter system.SysUser) {
|
||||
var user system.SysUser
|
||||
if !errors.Is(global.GVA_DB.Where("username = ?", u.Username).First(&user).Error, gorm.ErrRecordNotFound) { // 判断用户名是否注册
|
||||
return errors.New("用户名已注册"), userInter
|
||||
@@ -34,7 +37,7 @@ func Register(u system.SysUser) (err error, userInter system.SysUser) {
|
||||
//@param: u *model.SysUser
|
||||
//@return: err error, userInter *model.SysUser
|
||||
|
||||
func Login(u *system.SysUser) (err error, userInter *system.SysUser) {
|
||||
func (userService *UserService) Login(u *system.SysUser) (err error, userInter *system.SysUser) {
|
||||
var user system.SysUser
|
||||
u.Password = utils.MD5V([]byte(u.Password))
|
||||
err = global.GVA_DB.Where("username = ? AND password = ?", u.Username, u.Password).Preload("Authority").First(&user).Error
|
||||
@@ -47,7 +50,7 @@ func Login(u *system.SysUser) (err error, userInter *system.SysUser) {
|
||||
//@param: u *model.SysUser, newPassword string
|
||||
//@return: err error, userInter *model.SysUser
|
||||
|
||||
func ChangePassword(u *system.SysUser, newPassword string) (err error, userInter *system.SysUser) {
|
||||
func (userService *UserService) ChangePassword(u *system.SysUser, newPassword string) (err error, userInter *system.SysUser) {
|
||||
var user system.SysUser
|
||||
u.Password = utils.MD5V([]byte(u.Password))
|
||||
err = global.GVA_DB.Where("username = ? AND password = ?", u.Username, u.Password).First(&user).Update("password", utils.MD5V([]byte(newPassword))).Error
|
||||
@@ -60,7 +63,7 @@ func ChangePassword(u *system.SysUser, newPassword string) (err error, userInter
|
||||
//@param: info request.PageInfo
|
||||
//@return: err error, list interface{}, total int64
|
||||
|
||||
func GetUserInfoList(info request.PageInfo) (err error, list interface{}, total int64) {
|
||||
func (userService *UserService) GetUserInfoList(info request.PageInfo) (err error, list interface{}, total int64) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
db := global.GVA_DB.Model(&system.SysUser{})
|
||||
@@ -76,7 +79,7 @@ func GetUserInfoList(info request.PageInfo) (err error, list interface{}, total
|
||||
//@param: uuid uuid.UUID, authorityId string
|
||||
//@return: err error
|
||||
|
||||
func SetUserAuthority(uuid uuid.UUID, authorityId string) (err error) {
|
||||
func (userService *UserService) SetUserAuthority(uuid uuid.UUID, authorityId string) (err error) {
|
||||
err = global.GVA_DB.Where("uuid = ?", uuid).First(&system.SysUser{}).Update("authority_id", authorityId).Error
|
||||
return err
|
||||
}
|
||||
@@ -87,7 +90,7 @@ func SetUserAuthority(uuid uuid.UUID, authorityId string) (err error) {
|
||||
//@param: id float64
|
||||
//@return: err error
|
||||
|
||||
func DeleteUser(id float64) (err error) {
|
||||
func (userService *UserService) DeleteUser(id float64) (err error) {
|
||||
var user system.SysUser
|
||||
err = global.GVA_DB.Where("id = ?", id).Delete(&user).Error
|
||||
return err
|
||||
@@ -99,7 +102,7 @@ func DeleteUser(id float64) (err error) {
|
||||
//@param: reqUser model.SysUser
|
||||
//@return: err error, user model.SysUser
|
||||
|
||||
func SetUserInfo(reqUser system.SysUser) (err error, user system.SysUser) {
|
||||
func (userService *UserService) SetUserInfo(reqUser system.SysUser) (err error, user system.SysUser) {
|
||||
err = global.GVA_DB.Updates(&reqUser).Error
|
||||
return err, reqUser
|
||||
}
|
||||
@@ -110,7 +113,7 @@ func SetUserInfo(reqUser system.SysUser) (err error, user system.SysUser) {
|
||||
//@param: id int
|
||||
//@return: err error, user *model.SysUser
|
||||
|
||||
func FindUserById(id int) (err error, user *system.SysUser) {
|
||||
func (userService *UserService) FindUserById(id int) (err error, user *system.SysUser) {
|
||||
var u system.SysUser
|
||||
err = global.GVA_DB.Where("`id` = ?", id).First(&u).Error
|
||||
return err, &u
|
||||
@@ -122,7 +125,7 @@ func FindUserById(id int) (err error, user *system.SysUser) {
|
||||
//@param: uuid string
|
||||
//@return: err error, user *model.SysUser
|
||||
|
||||
func FindUserByUuid(uuid string) (err error, user *system.SysUser) {
|
||||
func (userService *UserService) FindUserByUuid(uuid string) (err error, user *system.SysUser) {
|
||||
var u system.SysUser
|
||||
if err = global.GVA_DB.Where("`uuid` = ?", uuid).First(&u).Error; err != nil {
|
||||
return errors.New("用户不存在"), &u
|
||||
Reference in New Issue
Block a user