From 69c75ee76943b5e36e0f1c9c4005d494b0c626d0 Mon Sep 17 00:00:00 2001 From: qimiao <303176530@qq.com> Date: Thu, 16 Sep 2021 10:19:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83=E6=80=A7?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/v1/example/exa_breakpoint_continue.go | 12 +++++++++++- server/middleware/email.go | 2 +- server/middleware/operation.go | 2 +- server/resource/template/server/service.go.tpl | 3 +++ server/service/autocode/autocodeExample.go | 3 +++ .../service/example/exa_breakpoint_continue.go | 3 +++ server/service/example/exa_customer.go | 3 +++ .../service/example/exa_file_upload_download.go | 6 ++++++ server/service/system/sys_authority.go | 16 +++++++++++++++- server/service/system/sys_autocode_history.go | 3 +++ server/service/system/sys_base_menu.go | 6 ++++++ server/service/system/sys_dictionary.go | 3 +++ server/service/system/sys_dictionary_detail.go | 3 +++ server/service/system/sys_initdb.go | 2 +- server/service/system/sys_operation_record.go | 3 +++ server/service/system/sys_user.go | 6 ++++++ server/utils/file_operations.go | 1 - server/utils/plugin/plugin_uinx.go | 1 + server/utils/timer/timed_task.go | 3 --- 19 files changed, 72 insertions(+), 9 deletions(-) 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/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/plugin/plugin_uinx.go b/server/utils/plugin/plugin_uinx.go index 1f8ca106..8317f1f0 100644 --- a/server/utils/plugin/plugin_uinx.go +++ b/server/utils/plugin/plugin_uinx.go @@ -83,6 +83,7 @@ func loadPlugin(path string, f fs.FileInfo) error { 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 清除任务