diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 8b28c9bb..00000000 --- a/package-lock.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "gin-vue-admin", - "lockfileVersion": 2, - "requires": true, - "packages": {} -} diff --git a/package.json b/package.json deleted file mode 100644 index 0967ef42..00000000 --- a/package.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/server/api/v1/example/exa_breakpoint_continue.go b/server/api/v1/example/exa_breakpoint_continue.go index 9afbf279..cf20d55c 100644 --- a/server/api/v1/example/exa_breakpoint_continue.go +++ b/server/api/v1/example/exa_breakpoint_continue.go @@ -1,7 +1,9 @@ package example import ( + "fmt" "io/ioutil" + "mime/multipart" "strconv" "github.com/flipped-aurora/gin-vue-admin/server/global" @@ -38,7 +40,12 @@ func (u *FileUploadAndDownloadApi) BreakpointContinue(c *gin.Context) { response.FailWithMessage("文件读取失败", c) return } - defer f.Close() + defer func(f multipart.File) { + err := f.Close() + if err != nil { + fmt.Println(err) + } + }(f) cen, _ := ioutil.ReadAll(f) if !utils.CheckMd5(cen, chunkMd5) { global.GVA_LOG.Error("检查md5失败!", zap.Any("err", err)) @@ -120,6 +127,9 @@ func (u *FileUploadAndDownloadApi) RemoveChunk(c *gin.Context) { fileName := c.Query("fileName") filePath := c.Query("filePath") err := utils.RemoveChunk(fileMd5) + if err != nil { + return + } err = fileUploadAndDownloadService.DeleteFileChunk(fileMd5, fileName, filePath) if err != nil { global.GVA_LOG.Error("缓存切片删除失败!", zap.Any("err", err)) diff --git a/server/go.mod b/server/go.mod index 58369fe1..0cfd9d05 100644 --- a/server/go.mod +++ b/server/go.mod @@ -25,6 +25,7 @@ require ( github.com/shirou/gopsutil v3.21.1+incompatible github.com/songzhibin97/gkit v1.1.1 github.com/spf13/viper v1.7.0 + github.com/stretchr/testify v1.7.0 // indirect github.com/swaggo/gin-swagger v1.3.0 github.com/swaggo/swag v1.7.0 github.com/tencentyun/cos-go-sdk-v5 v0.7.19 diff --git a/server/go.sum b/server/go.sum index 9a54896f..4cdf6692 100644 --- a/server/go.sum +++ b/server/go.sum @@ -463,6 +463,7 @@ github.com/spf13/viper v1.7.0 h1:xVKxvI7ouOI5I+U9s2eeiUfMaWBVoXA3AWskkrqK0VM= github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/server/middleware/email.go b/server/middleware/email.go index 9ba328b9..9942599e 100644 --- a/server/middleware/email.go +++ b/server/middleware/email.go @@ -42,7 +42,7 @@ func ErrorToEmail() gin.HandlerFunc { c.Next() - latency := time.Now().Sub(now) + latency := time.Since(now) status := c.Writer.Status() record.ErrorMessage = c.Errors.ByType(gin.ErrorTypePrivate).String() str := "接收到的请求为" + record.Body + "\n" + "请求方式为" + record.Method + "\n" + "报错信息如下" + record.ErrorMessage + "\n" + "耗时" + latency.String() + "\n" diff --git a/server/middleware/operation.go b/server/middleware/operation.go index d6efd088..8e4539b2 100644 --- a/server/middleware/operation.go +++ b/server/middleware/operation.go @@ -62,7 +62,7 @@ func OperationRecord() gin.HandlerFunc { c.Next() - latency := time.Now().Sub(now) + latency := time.Since(now) record.ErrorMessage = c.Errors.ByType(gin.ErrorTypePrivate).String() record.Status = c.Writer.Status() record.Latency = latency diff --git a/server/resource/template/server/service.go.tpl b/server/resource/template/server/service.go.tpl index 8a40fc44..2fc99f19 100644 --- a/server/resource/template/server/service.go.tpl +++ b/server/resource/template/server/service.go.tpl @@ -80,6 +80,9 @@ func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}InfoLis {{- end }} {{- end }} err = db.Count(&total).Error + if err!=nil { + return + } err = db.Limit(limit).Offset(offset).Find(&{{.Abbreviation}}s).Error return err, {{.Abbreviation}}s, total } diff --git a/server/service/autocode/autocodeExample.go b/server/service/autocode/autocodeExample.go index 3d53c5aa..3f6e6205 100644 --- a/server/service/autocode/autocodeExample.go +++ b/server/service/autocode/autocodeExample.go @@ -71,6 +71,9 @@ func (autoCodeExampleService *AutoCodeExampleService) GetAutoCodeExampleInfoList db = db.Where("label LIKE ?", "%"+info.AutoCodeExampleField+"%") } err = db.Count(&total).Error + if err != nil { + return + } err = db.Limit(limit).Offset(offset).Find(&autoCodeExamples).Error return err, autoCodeExamples, total } diff --git a/server/service/example/exa_breakpoint_continue.go b/server/service/example/exa_breakpoint_continue.go index 23805a0d..afce53b2 100644 --- a/server/service/example/exa_breakpoint_continue.go +++ b/server/service/example/exa_breakpoint_continue.go @@ -58,6 +58,9 @@ func (e *FileUploadAndDownloadService) DeleteFileChunk(fileMd5 string, fileName 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 + if err != nil { + return err + } err = global.GVA_DB.Where("exa_file_id = ?", file.ID).Delete(&chunks).Unscoped().Error return err } diff --git a/server/service/example/exa_customer.go b/server/service/example/exa_customer.go index 11f3d04c..b191eba9 100644 --- a/server/service/example/exa_customer.go +++ b/server/service/example/exa_customer.go @@ -68,6 +68,9 @@ func (exa *CustomerService) GetCustomerInfoList(sysUserAuthorityID string, info var a system.SysAuthority a.AuthorityId = sysUserAuthorityID err, auth := systemService.AuthorityServiceApp.GetAuthorityInfo(a) + if err != nil { + return + } var dataId []string for _, v := range auth.DataAuthorityId { dataId = append(dataId, v.AuthorityId) diff --git a/server/service/example/exa_file_upload_download.go b/server/service/example/exa_file_upload_download.go index d38e6946..14d0df5a 100644 --- a/server/service/example/exa_file_upload_download.go +++ b/server/service/example/exa_file_upload_download.go @@ -42,6 +42,9 @@ func (e *FileUploadAndDownloadService) FindFile(id uint) (error, example.ExaFile func (e *FileUploadAndDownloadService) DeleteFile(file example.ExaFileUploadAndDownload) (err error) { var fileFromDb example.ExaFileUploadAndDownload err, fileFromDb = e.FindFile(file.ID) + if err != nil { + return + } oss := upload.NewOss() if err = oss.DeleteFile(fileFromDb.Key); err != nil { return errors.New("文件删除失败") @@ -62,6 +65,9 @@ func (e *FileUploadAndDownloadService) GetFileRecordInfoList(info request.PageIn db := global.GVA_DB var fileLists []example.ExaFileUploadAndDownload err = db.Find(&fileLists).Count(&total).Error + if err != nil { + return + } err = db.Limit(limit).Offset(offset).Order("updated_at desc").Find(&fileLists).Error return err, fileLists, total } diff --git a/server/service/system/sys_authority.go b/server/service/system/sys_authority.go index 810966dd..8b47a2e8 100644 --- a/server/service/system/sys_authority.go +++ b/server/service/system/sys_authority.go @@ -44,6 +44,9 @@ func (authorityService *AuthorityService) CopyAuthority(copyInfo response.SysAut } copyInfo.Authority.Children = []system.SysAuthority{} err, menus := MenuServiceApp.GetMenuAuthority(&request.GetAuthorityId{AuthorityId: copyInfo.OldAuthorityId}) + if err != nil { + return + } var baseMenu []system.SysBaseMenu for _, v := range menus { intNum, _ := strconv.Atoi(v.MenuId) @@ -52,7 +55,9 @@ func (authorityService *AuthorityService) CopyAuthority(copyInfo response.SysAut } copyInfo.Authority.SysBaseMenus = baseMenu err = global.GVA_DB.Create(©Info.Authority).Error - + if err != nil { + return + } paths := CasbinServiceApp.GetPolicyPathByAuthorityId(copyInfo.OldAuthorityId) err = CasbinServiceApp.UpdateCasbin(copyInfo.Authority.AuthorityId, paths) if err != nil { @@ -87,11 +92,20 @@ func (authorityService *AuthorityService) DeleteAuthority(auth *system.SysAuthor } db := global.GVA_DB.Preload("SysBaseMenus").Where("authority_id = ?", auth.AuthorityId).First(auth) err = db.Unscoped().Delete(auth).Error + if err != nil { + return + } if len(auth.SysBaseMenus) > 0 { err = global.GVA_DB.Model(auth).Association("SysBaseMenus").Delete(auth.SysBaseMenus) + if err != nil { + return + } //err = db.Association("SysBaseMenus").Delete(&auth) } else { err = db.Error + if err != nil { + return + } } err = global.GVA_DB.Delete(&[]system.SysUseAuthority{}, "sys_authority_authority_id = ?", auth.AuthorityId).Error CasbinServiceApp.ClearCasbin(0, auth.AuthorityId) diff --git a/server/service/system/sys_autocode_history.go b/server/service/system/sys_autocode_history.go index 4bce5d02..8604af6a 100644 --- a/server/service/system/sys_autocode_history.go +++ b/server/service/system/sys_autocode_history.go @@ -111,6 +111,9 @@ func (autoCodeHistoryService *AutoCodeHistoryService) GetSysHistoryPage(info req db := global.GVA_DB var fileLists []system.SysAutoCodeHistory err = db.Find(&fileLists).Count(&total).Error + if err != nil { + return + } err = db.Limit(limit).Offset(offset).Order("updated_at desc").Select("id,created_at,updated_at,struct_name,struct_cn_name,flag,table_name").Find(&fileLists).Error return err, fileLists, total } diff --git a/server/service/system/sys_base_menu.go b/server/service/system/sys_base_menu.go index 776c40f3..2bdde5c4 100644 --- a/server/service/system/sys_base_menu.go +++ b/server/service/system/sys_base_menu.go @@ -23,10 +23,16 @@ func (baseMenuService *BaseMenuService) DeleteBaseMenu(id float64) (err error) { var menu system.SysBaseMenu db := global.GVA_DB.Preload("SysAuthoritys").Where("id = ?", id).First(&menu).Delete(&menu) err = global.GVA_DB.Delete(&system.SysBaseMenuParameter{}, "sys_base_menu_id = ?", id).Error + if err != nil { + return err + } if len(menu.SysAuthoritys) > 0 { err = global.GVA_DB.Model(&menu).Association("SysAuthoritys").Delete(&menu.SysAuthoritys) } else { err = db.Error + if err != nil { + return + } } } else { return errors.New("此菜单存在子菜单不可删除") diff --git a/server/service/system/sys_dictionary.go b/server/service/system/sys_dictionary.go index 37f05b69..4dfc9601 100644 --- a/server/service/system/sys_dictionary.go +++ b/server/service/system/sys_dictionary.go @@ -99,6 +99,9 @@ func (dictionaryService *DictionaryService) GetSysDictionaryInfoList(info reques db = db.Where("`desc` LIKE ?", "%"+info.Desc+"%") } err = db.Count(&total).Error + if err != nil { + return + } err = db.Limit(limit).Offset(offset).Find(&sysDictionarys).Error return err, sysDictionarys, total } diff --git a/server/service/system/sys_dictionary_detail.go b/server/service/system/sys_dictionary_detail.go index a8aca53e..f227b5ea 100644 --- a/server/service/system/sys_dictionary_detail.go +++ b/server/service/system/sys_dictionary_detail.go @@ -79,6 +79,9 @@ func (dictionaryDetailService *DictionaryDetailService) GetSysDictionaryDetailIn db = db.Where("sys_dictionary_id = ?", info.SysDictionaryID) } err = db.Count(&total).Error + if err != nil { + return + } err = db.Limit(limit).Offset(offset).Find(&sysDictionaryDetails).Error return err, sysDictionaryDetails, total } diff --git a/server/service/system/sys_initdb.go b/server/service/system/sys_initdb.go index 45d3b747..25b03fbd 100644 --- a/server/service/system/sys_initdb.go +++ b/server/service/system/sys_initdb.go @@ -53,7 +53,7 @@ func (initDBService *InitDBService) createTable(dsn string, driver string, creat defer func(db *sql.DB) { err := db.Close() if err != nil { - + fmt.Println(err) } }(db) if err = db.Ping(); err != nil { diff --git a/server/service/system/sys_operation_record.go b/server/service/system/sys_operation_record.go index 49811b8f..9e7e6a0a 100644 --- a/server/service/system/sys_operation_record.go +++ b/server/service/system/sys_operation_record.go @@ -79,6 +79,9 @@ func (operationRecordService *OperationRecordService) GetSysOperationRecordInfoL db = db.Where("status = ?", info.Status) } err = db.Count(&total).Error + if err != nil { + return + } err = db.Order("id desc").Limit(limit).Offset(offset).Preload("User").Find(&sysOperationRecords).Error return err, sysOperationRecords, total } diff --git a/server/service/system/sys_user.go b/server/service/system/sys_user.go index ebdd8908..a467569c 100644 --- a/server/service/system/sys_user.go +++ b/server/service/system/sys_user.go @@ -70,6 +70,9 @@ func (userService *UserService) GetUserInfoList(info request.PageInfo) (err erro db := global.GVA_DB.Model(&system.SysUser{}) var userList []system.SysUser err = db.Count(&total).Error + if err != nil { + return + } err = db.Limit(limit).Offset(offset).Preload("Authorities").Preload("Authority").Find(&userList).Error return err, userList, total } @@ -125,6 +128,9 @@ func (userService *UserService) SetUserAuthorities(id uint, authorityIds []strin func (userService *UserService) DeleteUser(id float64) (err error) { var user system.SysUser err = global.GVA_DB.Where("id = ?", id).Delete(&user).Error + if err != nil { + return err + } err = global.GVA_DB.Delete(&[]system.SysUseAuthority{}, "sys_user_id = ?", id).Error return err } diff --git a/server/utils/file_operations.go b/server/utils/file_operations.go index 0e747773..0444a74c 100644 --- a/server/utils/file_operations.go +++ b/server/utils/file_operations.go @@ -65,5 +65,4 @@ func TrimSpace(target interface{}) { v.Field(i).SetString(strings.TrimSpace(v.Field(i).String())) } } - return } diff --git a/server/utils/md5.go b/server/utils/md5.go index 59ac0e14..252e8b0c 100644 --- a/server/utils/md5.go +++ b/server/utils/md5.go @@ -11,8 +11,8 @@ import ( //@param: str []byte //@return: string -func MD5V(str []byte) string { +func MD5V(str []byte, b ...byte) string { h := md5.New() h.Write(str) - return hex.EncodeToString(h.Sum(nil)) + return hex.EncodeToString(h.Sum(b)) } diff --git a/server/utils/plugin/plugin_uinx.go b/server/utils/plugin/plugin_uinx.go index 5d234ec2..8317f1f0 100644 --- a/server/utils/plugin/plugin_uinx.go +++ b/server/utils/plugin/plugin_uinx.go @@ -82,7 +82,8 @@ func loadPlugin(path string, f fs.FileInfo) error { fmt.Println("loadPlugin err ", fmt.Sprintf("path:%s 没有实现 %s 接口", filepath.Base(fPath), OnlyFuncName)) return errors.New("没有实现指定接口") } else { - + // todo + fmt.Println("todo...") } fmt.Println("loadPlugin add ", filepath.Base(fPath)) ManagementPlugin.SetPlugin(filepath.Base(fPath), p) diff --git a/server/utils/timer/timed_task.go b/server/utils/timer/timed_task.go index 881fddeb..336e84db 100644 --- a/server/utils/timer/timed_task.go +++ b/server/utils/timer/timed_task.go @@ -62,7 +62,6 @@ func (t *timer) StartTask(taskName string) { if v, ok := t.taskList[taskName]; ok { v.Start() } - return } // StopTask 停止任务 @@ -72,7 +71,6 @@ func (t *timer) StopTask(taskName string) { if v, ok := t.taskList[taskName]; ok { v.Stop() } - return } // Remove 从taskName 删除指定任务 @@ -82,7 +80,6 @@ func (t *timer) Remove(taskName string, id int) { if v, ok := t.taskList[taskName]; ok { v.Remove(cron.EntryID(id)) } - return } // Clear 清除任务 diff --git a/server/utils/timer/timed_task_test.go b/server/utils/timer/timed_task_test.go new file mode 100644 index 00000000..560beb77 --- /dev/null +++ b/server/utils/timer/timed_task_test.go @@ -0,0 +1,65 @@ +package timer + +import ( + "fmt" + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +var job = mockJob{} + +type mockJob struct{} + +func (job mockJob) Run() { + mockFunc() +} +func mockFunc() { + time.Sleep(time.Second) + fmt.Println("1s...") +} +func TestNewTimerTask(t *testing.T) { + tm := NewTimerTask() + _tm := tm.(*timer) + + { + _, err := tm.AddTaskByFunc("func", "@every 1s", mockFunc) + assert.Nil(t, err) + _, ok := _tm.taskList["func"] + if !ok { + t.Error("no find func") + } + } + + { + _, err := tm.AddTaskByJob("job", "@every 1s", job) + assert.Nil(t, err) + _, ok := _tm.taskList["job"] + if !ok { + t.Error("no find job") + } + } + + { + _, ok := tm.FindCron("func") + if !ok { + t.Error("no find func") + } + _, ok = tm.FindCron("job") + if !ok { + t.Error("no find job") + } + _, ok = tm.FindCron("none") + if ok { + t.Error("find none") + } + } + { + tm.Clear("func") + _, ok := tm.FindCron("func") + if ok { + t.Error("find func") + } + } +} diff --git a/web/src/view/login/index.vue b/web/src/view/login/index.vue index 77379126..aa49d5c4 100644 --- a/web/src/view/login/index.vue +++ b/web/src/view/login/index.vue @@ -3,14 +3,10 @@
- +