From 44d196eaefcb6c664742b95a9a5436ce5393c5be Mon Sep 17 00:00:00 2001 From: wenjianzhang Date: Sun, 25 Apr 2021 17:06:52 +0800 Subject: [PATCH 01/11] =?UTF-8?q?config=F0=9F=94=A7=20=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/settings.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config/settings.yml b/config/settings.yml index 1f41a29a5..8544457e0 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -44,6 +44,9 @@ settings: dbname: dbname # 代码生成是使用前端代码存放位置,需要指定到src文件夹,相对路径 frontpath: ../go-admin-ui/src + queue: + memory: + poolSize: 100 extend: # 扩展项使用说明 demo: - name: data \ No newline at end of file + name: data From 5957fb280caec42ba02355467d289fa154eca821 Mon Sep 17 00:00:00 2001 From: wenjianzhang Date: Sun, 25 Apr 2021 17:07:41 +0800 Subject: [PATCH 02/11] =?UTF-8?q?config=F0=9F=94=A7=20=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/settings.full.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config/settings.full.yml b/config/settings.full.yml index dfe72695b..165383889 100644 --- a/config/settings.full.yml +++ b/config/settings.full.yml @@ -50,6 +50,9 @@ settings: dbname: dbname # 代码生成是使用前端代码存放位置,需要指定到src文件夹,相对路径 frontpath: ../go-admin-ui/src + queue: + memory: + poolSize: 100 extend: # 扩展项使用说明 demo: - name: data \ No newline at end of file + name: data From 13ff9d9e63072342ac10a84bc1787ff7875305ce Mon Sep 17 00:00:00 2001 From: linwenxiang <991154416@qq.com> Date: Tue, 27 Apr 2021 10:01:36 +0800 Subject: [PATCH 03/11] =?UTF-8?q?feat=20:sparkles:=20=E4=BC=98=E5=8C=96api?= =?UTF-8?q?=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/apis/monitor/server.go | 5 +- app/admin/apis/public/file.go | 34 ++--- .../sys_china_area_data.go | 67 +++++----- app/admin/apis/sys_file/sys_file_dir.go | 69 +++++----- app/admin/apis/sys_file/sys_file_info.go | 71 ++++++----- app/admin/apis/sys_job/sys_job.go | 25 ++-- app/admin/apis/sys_user/sys_user.go | 113 +++++++++-------- app/admin/apis/system/captcha.go | 9 +- app/admin/apis/system/dict/sys_dict_data.go | 80 ++++++------ app/admin/apis/system/dict/sys_dict_type.go | 76 +++++------ app/admin/apis/system/settings.go | 26 ++-- .../apis/system/sys_config/sys_config.go | 119 +++++++++--------- app/admin/apis/system/sys_dept/sys_dept.go | 93 +++++++------- .../system/sys_login_log/sys_login_log.go | 71 ++++++----- app/admin/apis/system/sys_menu/sys_menu.go | 106 ++++++++-------- .../system/sys_opera_log/sys_opera_log.go | 65 +++++----- app/admin/apis/system/sys_post/sys_post.go | 65 +++++----- app/admin/apis/system/sys_role/sys_role.go | 86 +++++++------ app/admin/apis/tools/dbcolumns.go | 9 +- app/admin/apis/tools/dbtables.go | 11 +- app/admin/apis/tools/gen.go | 77 ++++++------ app/admin/apis/tools/systables.go | 79 ++++++------ app/admin/router/sys_config.go | 2 +- app/admin/router/sys_dept.go | 2 +- app/admin/router/sys_file_dir.go | 2 +- app/admin/router/sys_file_info.go | 2 +- app/admin/router/sys_job.go | 2 +- app/admin/router/sys_login_log.go | 2 +- app/admin/router/sys_menu.go | 2 +- app/admin/router/sys_opera_log.go | 2 +- app/admin/router/sys_post.go | 2 +- app/admin/router/sys_role.go | 2 +- app/admin/router/sys_router.go | 20 +-- app/admin/router/sys_user.go | 2 +- app/admin/router/syschinaareadata.go | 2 +- cmd/api/server.go | 20 +-- common/apis/api.go | 27 ++-- go.mod | 2 +- 38 files changed, 777 insertions(+), 672 deletions(-) diff --git a/app/admin/apis/monitor/server.go b/app/admin/apis/monitor/server.go index 8f8488bdc..9e5b23290 100644 --- a/app/admin/apis/monitor/server.go +++ b/app/admin/apis/monitor/server.go @@ -29,7 +29,8 @@ type Monitor struct { // @Tags 系统信息 // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/v1/settings/serverInfo [get] -func (e *Monitor) ServerInfo(c *gin.Context) { +func (e Monitor) ServerInfo(c *gin.Context) { + e.Context = c osDic := make(map[string]interface{}, 0) osDic["goOs"] = runtime.GOOS @@ -65,7 +66,7 @@ func (e *Monitor) ServerInfo(c *gin.Context) { cpuDic["Percent"] = pkg.Round(percent[0], 2) cpuDic["cpuNum"], _ = cpu.Counts(false) - e.Custom(c, gin.H{ + e.Custom(gin.H{ "code": 200, "os": osDic, "mem": memDic, diff --git a/app/admin/apis/public/file.go b/app/admin/apis/public/file.go index c69241c30..42a4aca7a 100644 --- a/app/admin/apis/public/file.go +++ b/app/admin/apis/public/file.go @@ -39,12 +39,14 @@ type File struct { // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/public/uploadFile [post] -func (e *File) UploadFile(c *gin.Context) { +func (e File) UploadFile(c *gin.Context) { + e.Context = c + tag, _ := c.GetPostForm("type") urlPerfix := fmt.Sprintf("http://%s/", c.Request.Host) var fileResponse FileResponse if tag == "" { - e.Error(c, 500, nil, "缺少标识") + e.Error(500, nil, "缺少标识") //app.Error(c, 200, errors.New(""), "缺少标识") return } else { @@ -55,20 +57,20 @@ func (e *File) UploadFile(c *gin.Context) { if done { return } - e.OK(c, fileResponse, "上传成功") + e.OK(fileResponse, "上传成功") return case "2": // 多图 multipartFile := e.multipleFile(c, urlPerfix) - e.OK(c, multipartFile, "上传成功") + e.OK(multipartFile, "上传成功") return case "3": // base64 fileResponse = e.baseImg(c, fileResponse, urlPerfix) - e.OK(c, fileResponse, "上传成功") + e.OK(fileResponse, "上传成功") } } } -func (e *File) baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix string) FileResponse { +func (e File) baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix string) FileResponse { files, _ := c.GetPostForm("file") file2list := strings.Split(files, ",") ddd, _ := base64.StdEncoding.DecodeString(file2list[1]) @@ -76,7 +78,7 @@ func (e *File) baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix stri fileName := guid + ".jpg" err := utils.IsNotExistMkDir(path) if err != nil { - e.Error(c, 500, errors.New(""), "初始化文件路径失败") + e.Error(500, errors.New(""), "初始化文件路径失败") } base64File := path + fileName _ = ioutil.WriteFile(base64File, ddd, 0666) @@ -91,7 +93,7 @@ func (e *File) baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix stri source, _ := c.GetPostForm("source") err = thirdUpload(source, fileName, base64File) if err != nil { - e.Error(c, 200, errors.New(""), "上传第三方失败") + e.Error(200, errors.New(""), "上传第三方失败") return fileResponse } if source != "1" { @@ -101,7 +103,7 @@ func (e *File) baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix stri return fileResponse } -func (e *File) multipleFile(c *gin.Context, urlPerfix string) []FileResponse { +func (e File) multipleFile(c *gin.Context, urlPerfix string) []FileResponse { files := c.Request.MultipartForm.File["file"] source, _ := c.GetPostForm("source") var multipartFile []FileResponse @@ -111,7 +113,7 @@ func (e *File) multipleFile(c *gin.Context, urlPerfix string) []FileResponse { err := utils.IsNotExistMkDir(path) if err != nil { - e.Error(c, 500, errors.New(""), "初始化文件路径失败") + e.Error(500, errors.New(""), "初始化文件路径失败") } multipartFileName := path + fileName err1 := c.SaveUploadedFile(f, multipartFileName) @@ -119,7 +121,7 @@ func (e *File) multipleFile(c *gin.Context, urlPerfix string) []FileResponse { if err1 == nil { err := thirdUpload(source, fileName, multipartFileName) if err != nil { - e.Error(c, 500, errors.New(""), "上传第三方失败") + e.Error(500, errors.New(""), "上传第三方失败") } else { fileResponse := FileResponse{ Size: pkg.GetFileSize(multipartFileName), @@ -139,11 +141,11 @@ func (e *File) multipleFile(c *gin.Context, urlPerfix string) []FileResponse { return multipartFile } -func (e *File) singleFile(c *gin.Context, fileResponse FileResponse, urlPerfix string) (FileResponse, bool) { +func (e File) singleFile(c *gin.Context, fileResponse FileResponse, urlPerfix string) (FileResponse, bool) { files, err := c.FormFile("file") if err != nil { - e.Error(c, 200, errors.New(""), "图片不能为空") + e.Error(200, errors.New(""), "图片不能为空") return FileResponse{}, true } // 上传文件至指定目录 @@ -153,7 +155,7 @@ func (e *File) singleFile(c *gin.Context, fileResponse FileResponse, urlPerfix s err = utils.IsNotExistMkDir(path) if err != nil { - e.Error(c, 500, errors.New(""), "初始化文件路径失败") + e.Error(500, errors.New(""), "初始化文件路径失败") } singleFile := path + fileName _ = c.SaveUploadedFile(files, singleFile) @@ -168,7 +170,7 @@ func (e *File) singleFile(c *gin.Context, fileResponse FileResponse, urlPerfix s source, _ := c.GetPostForm("source") err = thirdUpload(source, fileName, singleFile) if err != nil { - e.Error(c, 200, errors.New(""), "上传第三方失败") + e.Error(200, errors.New(""), "上传第三方失败") return FileResponse{}, true } fileResponse.Path = "https://youshikeji.oss-cn-shanghai.aliyuncs.com/img/" + fileName @@ -194,4 +196,4 @@ func ossUpload(name string, path string) error { func qiniuUpload(name string, path string) error { oss := file_store.ALiYunOSS{} return oss.UpLoad(name, path) -} \ No newline at end of file +} diff --git a/app/admin/apis/sys_china_area_data/sys_china_area_data.go b/app/admin/apis/sys_china_area_data/sys_china_area_data.go index 6eddf3476..80599aa40 100644 --- a/app/admin/apis/sys_china_area_data/sys_china_area_data.go +++ b/app/admin/apis/sys_china_area_data/sys_china_area_data.go @@ -17,10 +17,11 @@ type SysChinaAreaData struct { apis.Api } -func (e *SysChinaAreaData) GetSysChinaAreaDataList(c *gin.Context) { - log := e.GetLogger(c) +func (e SysChinaAreaData) GetSysChinaAreaDataList(c *gin.Context) { + e.Context = c + log := e.GetLogger() d := new(dto.SysChinaAreaDataSearch) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -29,7 +30,7 @@ func (e *SysChinaAreaData) GetSysChinaAreaDataList(c *gin.Context) { //查询列表 err = d.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -43,17 +44,18 @@ func (e *SysChinaAreaData) GetSysChinaAreaDataList(c *gin.Context) { serviceStudent.Orm = db err = serviceStudent.GetSysChinaAreaDataPage(d, p, &list, &count) if err != nil { - e.Error(c, http.StatusInternalServerError, err, "查询失败") + e.Error(http.StatusInternalServerError, err, "查询失败") return } - e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功") + e.PageOK(list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功") } -func (e *SysChinaAreaData) GetSysChinaAreaData(c *gin.Context) { - log := e.GetLogger(c) +func (e SysChinaAreaData) GetSysChinaAreaData(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysChinaAreaDataById) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -62,7 +64,7 @@ func (e *SysChinaAreaData) GetSysChinaAreaData(c *gin.Context) { //查看详情 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } var object models.SysChinaAreaData @@ -75,17 +77,18 @@ func (e *SysChinaAreaData) GetSysChinaAreaData(c *gin.Context) { serviceSysChinaAreaData.Orm = db err = serviceSysChinaAreaData.GetSysChinaAreaData(control, p, &object) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } - e.OK(c, object, "查看成功") + e.OK(object, "查看成功") } -func (e *SysChinaAreaData) InsertSysChinaAreaData(c *gin.Context) { - log := e.GetLogger(c) +func (e SysChinaAreaData) InsertSysChinaAreaData(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysChinaAreaDataControl) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -94,12 +97,12 @@ func (e *SysChinaAreaData) InsertSysChinaAreaData(c *gin.Context) { //新增操作 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.Generate() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } // 设置创建人 @@ -111,17 +114,18 @@ func (e *SysChinaAreaData) InsertSysChinaAreaData(c *gin.Context) { err = serviceSysChinaAreaData.InsertSysChinaAreaData(object) if err != nil { log.Error(err) - e.Error(c, http.StatusInternalServerError, err, "创建失败") + e.Error(http.StatusInternalServerError, err, "创建失败") return } - e.OK(c, object.GetId(), "创建成功") + e.OK(object.GetId(), "创建成功") } -func (e *SysChinaAreaData) UpdateSysChinaAreaData(c *gin.Context) { - log := e.GetLogger(c) +func (e SysChinaAreaData) UpdateSysChinaAreaData(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysChinaAreaDataControl) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -130,12 +134,12 @@ func (e *SysChinaAreaData) UpdateSysChinaAreaData(c *gin.Context) { //更新操作 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.Generate() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } object.SetUpdateBy(user.GetUserId(c)) @@ -151,13 +155,14 @@ func (e *SysChinaAreaData) UpdateSysChinaAreaData(c *gin.Context) { log.Error(err) return } - e.OK(c, object.GetId(), "更新成功") + e.OK(object.GetId(), "更新成功") } -func (e *SysChinaAreaData) DeleteSysChinaAreaData(c *gin.Context) { - log := e.GetLogger(c) +func (e SysChinaAreaData) DeleteSysChinaAreaData(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysChinaAreaDataById) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -167,7 +172,7 @@ func (e *SysChinaAreaData) DeleteSysChinaAreaData(c *gin.Context) { err = control.Bind(c) if err != nil { log.Errorf("Bind error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -183,8 +188,8 @@ func (e *SysChinaAreaData) DeleteSysChinaAreaData(c *gin.Context) { err = serviceSysChinaAreaData.RemoveSysChinaAreaData(control, p) if err != nil { log.Errorf("RemoveSysChinaAreaData error, %s", err) - e.Error(c, http.StatusInternalServerError, err, "删除失败") + e.Error(http.StatusInternalServerError, err, "删除失败") return } - e.OK(c, control.GetId(), "删除成功") + e.OK(control.GetId(), "删除成功") } diff --git a/app/admin/apis/sys_file/sys_file_dir.go b/app/admin/apis/sys_file/sys_file_dir.go index 333205bbe..d275638cc 100644 --- a/app/admin/apis/sys_file/sys_file_dir.go +++ b/app/admin/apis/sys_file/sys_file_dir.go @@ -18,10 +18,11 @@ type SysFileDir struct { apis.Api } -func (e *SysFileDir) GetSysFileDirList(c *gin.Context) { - log := e.GetLogger(c) +func (e SysFileDir) GetSysFileDirList(c *gin.Context) { + e.Context = c + log := e.GetLogger() search := new(dto.SysFileDirSearch) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -39,17 +40,18 @@ func (e *SysFileDir) GetSysFileDirList(c *gin.Context) { list, err = serviceStudent.SetSysFileDir(search) if err != nil { log.Errorf("SetSysFileDir error, %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } - e.OK(c, list, "查询成功") + e.OK(list, "查询成功") } -func (e *SysFileDir) GetSysFileDir(c *gin.Context) { +func (e SysFileDir) GetSysFileDir(c *gin.Context) { control := new(dto.SysFileDirById) - log := e.GetLogger(c) - db, err := e.GetOrm(c) + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -59,7 +61,7 @@ func (e *SysFileDir) GetSysFileDir(c *gin.Context) { err = c.ShouldBindUri(control) if err != nil { log.Warnf("ShouldBindUri error: %s", err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") } var object models.SysFileDir @@ -70,17 +72,18 @@ func (e *SysFileDir) GetSysFileDir(c *gin.Context) { err = serviceSysFileDir.GetSysFileDir(control, &object) if err != nil { log.Errorf("GetSysFileDir error, %s", err) - e.Error(c, http.StatusInternalServerError, err, "查询失败") + e.Error(http.StatusInternalServerError, err, "查询失败") return } - e.OK(c, object, "查看成功") + e.OK(object, "查看成功") } -func (e *SysFileDir) InsertSysFileDir(c *gin.Context) { +func (e SysFileDir) InsertSysFileDir(c *gin.Context) { control := new(dto.SysFileDirControl) - log := e.GetLogger(c) - db, err := e.GetOrm(c) + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -90,13 +93,13 @@ func (e *SysFileDir) InsertSysFileDir(c *gin.Context) { err = c.ShouldBindUri(control) if err != nil { log.Warnf("ShouldBindUri error: %s", err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } err = c.ShouldBind(control) if err != nil { log.Warnf("ShouldBind error: %s", err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } // 设置创建人 @@ -108,17 +111,18 @@ func (e *SysFileDir) InsertSysFileDir(c *gin.Context) { err = serviceSysFileDir.InsertSysFileDir(control) if err != nil { log.Errorf("InsertSysFileDir error, %s", err) - e.Error(c, http.StatusInternalServerError, err, "创建失败") + e.Error(http.StatusInternalServerError, err, "创建失败") return } - e.OK(c, control.ID, "创建成功") + e.OK(control.ID, "创建成功") } -func (e *SysFileDir) UpdateSysFileDir(c *gin.Context) { +func (e SysFileDir) UpdateSysFileDir(c *gin.Context) { control := new(dto.SysFileDirControl) - log := e.GetLogger(c) - db, err := e.GetOrm(c) + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -127,12 +131,12 @@ func (e *SysFileDir) UpdateSysFileDir(c *gin.Context) { err = c.ShouldBindUri(control) if err != nil { log.Warnf("ShouldBindUri error: %s", err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") } err = c.ShouldBind(control) if err != nil { log.Warnf("ShouldBind error: %#v", err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") } // 设置创建人 control.UpdateBy = user.GetUserId(c) @@ -146,16 +150,17 @@ func (e *SysFileDir) UpdateSysFileDir(c *gin.Context) { err = serviceSysFileDir.UpdateSysFileDir(control, p) if err != nil { log.Errorf("UpdateSysFileDir error, %s", err) - e.Error(c, http.StatusInternalServerError, err, "更新失败") + e.Error(http.StatusInternalServerError, err, "更新失败") return } - e.OK(c, control.ID, "更新成功") + e.OK(control.ID, "更新成功") } -func (e *SysFileDir) DeleteSysFileDir(c *gin.Context) { +func (e SysFileDir) DeleteSysFileDir(c *gin.Context) { control := new(dto.SysFileDirById) - log := e.GetLogger(c) - db, err := e.GetOrm(c) + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -166,12 +171,12 @@ func (e *SysFileDir) DeleteSysFileDir(c *gin.Context) { err = c.ShouldBindUri(control) if err != nil { log.Warnf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") } err = c.ShouldBind(control) if err != nil { log.Warnf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") } // 设置编辑人 @@ -186,8 +191,8 @@ func (e *SysFileDir) DeleteSysFileDir(c *gin.Context) { err = serviceSysFileDir.RemoveSysFileDir(control, p) if err != nil { log.Errorf("RemoveSysFileDir error, %s", err) - e.Error(c, http.StatusInternalServerError, err, "删除失败") + e.Error(http.StatusInternalServerError, err, "删除失败") return } - e.OK(c, control.Id, "删除成功") + e.OK(control.Id, "删除成功") } diff --git a/app/admin/apis/sys_file/sys_file_info.go b/app/admin/apis/sys_file/sys_file_info.go index a45c7c3ae..637743bfa 100644 --- a/app/admin/apis/sys_file/sys_file_info.go +++ b/app/admin/apis/sys_file/sys_file_info.go @@ -17,10 +17,11 @@ type SysFileInfo struct { apis.Api } -func (e *SysFileInfo) GetSysFileInfoList(c *gin.Context) { - log := e.GetLogger(c) +func (e SysFileInfo) GetSysFileInfoList(c *gin.Context) { + e.Context = c + log := e.GetLogger() search := new(dto.SysFileInfoSearch) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -28,7 +29,7 @@ func (e *SysFileInfo) GetSysFileInfoList(c *gin.Context) { err = c.ShouldBind(search) if err != nil { log.Warnf("参数验证错误, error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -43,17 +44,18 @@ func (e *SysFileInfo) GetSysFileInfoList(c *gin.Context) { err = serviceStudent.GetSysFileInfoPage(search, p, &list, &count) if err != nil { log.Errorf("GetSysFileInfoPage error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "查询失败") + e.Error(http.StatusInternalServerError, err, "查询失败") return } - e.PageOK(c, list, int(count), search.PageIndex, search.PageSize, "查询成功") + e.PageOK(list, int(count), search.PageIndex, search.PageSize, "查询成功") } -func (e *SysFileInfo) GetSysFileInfo(c *gin.Context) { +func (e SysFileInfo) GetSysFileInfo(c *gin.Context) { control := new(dto.SysFileInfoById) - log := e.GetLogger(c) - db, err := e.GetOrm(c) + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -63,7 +65,7 @@ func (e *SysFileInfo) GetSysFileInfo(c *gin.Context) { err = c.ShouldBindUri(control) if err != nil { log.Warnf("参数验证错误, error:%s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -78,17 +80,18 @@ func (e *SysFileInfo) GetSysFileInfo(c *gin.Context) { err = serviceSysFileInfo.GetSysFileInfo(control, p, &object) if err != nil { log.Errorf("GetSysFileInfo error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "查询失败") + e.Error(http.StatusInternalServerError, err, "查询失败") return } - e.OK(c, object, "查看成功") + e.OK(object, "查看成功") } -func (e *SysFileInfo) InsertSysFileInfo(c *gin.Context) { +func (e SysFileInfo) InsertSysFileInfo(c *gin.Context) { control := new(dto.SysFileInfoControl) - log := e.GetLogger(c) - db, err := e.GetOrm(c) + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -98,13 +101,13 @@ func (e *SysFileInfo) InsertSysFileInfo(c *gin.Context) { err = c.ShouldBindUri(control) if err != nil { log.Warnf("参数验证错误, error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } err = c.ShouldBind(control) if err != nil { log.Warnf("参数验证错误, error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } // 设置创建人 @@ -116,17 +119,18 @@ func (e *SysFileInfo) InsertSysFileInfo(c *gin.Context) { err = serviceSysFileInfo.InsertSysFileInfo(control) if err != nil { log.Errorf("InsertSysFileInfo error: %s", err) - e.Error(c, http.StatusInternalServerError, err, "创建失败") + e.Error(http.StatusInternalServerError, err, "创建失败") return } - e.OK(c, control.ID, "创建成功") + e.OK(control.ID, "创建成功") } -func (e *SysFileInfo) UpdateSysFileInfo(c *gin.Context) { +func (e SysFileInfo) UpdateSysFileInfo(c *gin.Context) { control := new(dto.SysFileInfoControl) - log := e.GetLogger(c) - db, err := e.GetOrm(c) + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -135,13 +139,13 @@ func (e *SysFileInfo) UpdateSysFileInfo(c *gin.Context) { err = c.ShouldBindUri(control) if err != nil { log.Warnf("参数验证错误, error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } err = c.ShouldBind(control) if err != nil { log.Warnf("参数验证错误, error:%s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } // 设置创建人 @@ -156,16 +160,17 @@ func (e *SysFileInfo) UpdateSysFileInfo(c *gin.Context) { err = serviceSysFileInfo.UpdateSysFileInfo(control, p) if err != nil { log.Errorf("UpdateSysFileInfo error: %s", err) - e.Error(c, http.StatusInternalServerError, err, "创建失败") + e.Error(http.StatusInternalServerError, err, "创建失败") return } - e.OK(c, control.ID, "更新成功") + e.OK(control.ID, "更新成功") } -func (e *SysFileInfo) DeleteSysFileInfo(c *gin.Context) { +func (e SysFileInfo) DeleteSysFileInfo(c *gin.Context) { control := new(dto.SysFileInfoById) - log := e.GetLogger(c) - db, err := e.GetOrm(c) + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -175,13 +180,13 @@ func (e *SysFileInfo) DeleteSysFileInfo(c *gin.Context) { err = c.ShouldBindUri(control) if err != nil { log.Warnf("参数验证错误, error: %s", err) - e.Error(c, 422, err, "参数验证失败") + e.Error(422, err, "参数验证失败") return } err = c.ShouldBind(control) if err != nil { log.Warnf("参数验证错误, error: %s", err) - e.Error(c, 422, err, "参数验证失败") + e.Error(422, err, "参数验证失败") return } @@ -197,8 +202,8 @@ func (e *SysFileInfo) DeleteSysFileInfo(c *gin.Context) { err = serviceSysFileInfo.RemoveSysFileInfo(control, p) if err != nil { log.Errorf("RemoveSysFileInfo error: %s", err) - e.Error(c, http.StatusInternalServerError, err, "创建失败") + e.Error(http.StatusInternalServerError, err, "创建失败") return } - e.OK(c, control.Id, "删除成功") + e.OK(control.Id, "删除成功") } diff --git a/app/admin/apis/sys_job/sys_job.go b/app/admin/apis/sys_job/sys_job.go index d528a3199..95b65b8ce 100644 --- a/app/admin/apis/sys_job/sys_job.go +++ b/app/admin/apis/sys_job/sys_job.go @@ -15,9 +15,9 @@ type SysJob struct { } // RemoveJobForService 调用service实现 -func (e *SysJob) RemoveJobForService(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysJob) RemoveJobForService(c *gin.Context) { + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -26,7 +26,7 @@ func (e *SysJob) RemoveJobForService(c *gin.Context) { err = c.BindUri(&v) if err != nil { log.Warnf("参数验证错误, error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } s := service.SysJob{} @@ -36,16 +36,17 @@ func (e *SysJob) RemoveJobForService(c *gin.Context) { err = s.RemoveJob(&v) if err != nil { log.Errorf("RemoveJob error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "") + e.Error(http.StatusInternalServerError, err, "") return } - e.OK(c, nil, s.Msg) + e.OK(nil, s.Msg) } // StartJobForService 启动job service实现 -func (e *SysJob) StartJobForService(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysJob) StartJobForService(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -54,7 +55,7 @@ func (e *SysJob) StartJobForService(c *gin.Context) { err = c.BindUri(&v) if err != nil { log.Warnf("参数验证错误, error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } s := service.SysJob{} @@ -64,8 +65,8 @@ func (e *SysJob) StartJobForService(c *gin.Context) { err = s.StartJob(&v) if err != nil { log.Errorf("GetCrontabKey error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "") + e.Error(http.StatusInternalServerError, err, "") return } - e.OK(c, nil, s.Msg) + e.OK(nil, s.Msg) } diff --git a/app/admin/apis/sys_user/sys_user.go b/app/admin/apis/sys_user/sys_user.go index 4fdeb9a5a..3a04a1a78 100644 --- a/app/admin/apis/sys_user/sys_user.go +++ b/app/admin/apis/sys_user/sys_user.go @@ -28,10 +28,11 @@ type SysUser struct { // @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}" // @Router /api/v1/sysUser [get] // @Security Bearer -func (e *SysUser) GetSysUserList(c *gin.Context) { - log := e.GetLogger(c) +func (e SysUser) GetSysUserList(c *gin.Context) { + e.Context = c + log := e.GetLogger() d := new(dto.SysUserSearch) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -43,7 +44,7 @@ func (e *SysUser) GetSysUserList(c *gin.Context) { err = req.Bind(c) if err != nil { log.Warnf("Bind error: %s", err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -57,11 +58,11 @@ func (e *SysUser) GetSysUserList(c *gin.Context) { serviceStudent.Orm = db err = serviceStudent.GetSysUserPage(req, p, &list, &count) if err != nil { - e.Error(c, http.StatusInternalServerError, err, "查询失败") + e.Error(http.StatusInternalServerError, err, "查询失败") return } - e.PageOK(c, list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功") + e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功") } // @Summary 获取用户 @@ -71,10 +72,11 @@ func (e *SysUser) GetSysUserList(c *gin.Context) { // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/v1/sysUser/{userId} [get] // @Security Bearer -func (e *SysUser) GetSysUser(c *gin.Context) { - log := e.GetLogger(c) +func (e SysUser) GetSysUser(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysUserById) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -84,7 +86,7 @@ func (e *SysUser) GetSysUser(c *gin.Context) { req := control.Generate() err = req.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } var object system.SysUser @@ -97,11 +99,11 @@ func (e *SysUser) GetSysUser(c *gin.Context) { serviceSysUser.Orm = db err = serviceSysUser.GetSysUser(req, p, &object) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } - e.OK(c, object, "查看成功") + e.OK(object, "查看成功") } // @Summary 创建用户 @@ -113,10 +115,11 @@ func (e *SysUser) GetSysUser(c *gin.Context) { // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/sysUser [post] -func (e *SysUser) InsertSysUser(c *gin.Context) { - log := e.GetLogger(c) +func (e SysUser) InsertSysUser(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysUserControl) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -126,13 +129,13 @@ func (e *SysUser) InsertSysUser(c *gin.Context) { req := control.Generate() err = req.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } var object common.ActiveRecord object, err = req.GenerateM() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } // 设置创建人 @@ -144,11 +147,11 @@ func (e *SysUser) InsertSysUser(c *gin.Context) { err = serviceSysUser.InsertSysUser(object) if err != nil { log.Error(err) - e.Error(c, http.StatusInternalServerError, err, "创建失败") + e.Error(http.StatusInternalServerError, err, "创建失败") return } - e.OK(c, object.GetId(), "创建成功") + e.OK(object.GetId(), "创建成功") } // @Summary 修改用户数据 @@ -160,11 +163,12 @@ func (e *SysUser) InsertSysUser(c *gin.Context) { // @Success 200 {string} string "{"code": 200, "message": "修改成功"}" // @Success 200 {string} string "{"code": -1, "message": "修改失败"}" // @Router /api/v1/sysuser/{userId} [put] -func (e *SysUser) UpdateSysUser(c *gin.Context) { +func (e SysUser) UpdateSysUser(c *gin.Context) { control := new(dto.SysUserControl) - log := e.GetLogger(c) - db, err := e.GetOrm(c) + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -174,13 +178,13 @@ func (e *SysUser) UpdateSysUser(c *gin.Context) { //更新操作 err = req.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } var object common.ActiveRecord object, err = req.GenerateM() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } object.SetUpdateBy(user.GetUserId(c)) @@ -196,7 +200,7 @@ func (e *SysUser) UpdateSysUser(c *gin.Context) { log.Error(err) return } - e.OK(c, object.GetId(), "更新成功") + e.OK(object.GetId(), "更新成功") } // @Summary 删除用户数据 @@ -206,11 +210,12 @@ func (e *SysUser) UpdateSysUser(c *gin.Context) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": -1, "message": "删除失败"}" // @Router /api/v1/sysuser/{userId} [delete] -func (e *SysUser) DeleteSysUser(c *gin.Context) { - log := e.GetLogger(c) +func (e SysUser) DeleteSysUser(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysUserById) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -221,13 +226,13 @@ func (e *SysUser) DeleteSysUser(c *gin.Context) { err = req.Bind(c) if err != nil { log.Errorf("Bind error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } var object common.ActiveRecord object, err = req.GenerateM() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } @@ -245,7 +250,7 @@ func (e *SysUser) DeleteSysUser(c *gin.Context) { log.Error(err) return } - e.OK(c, object.GetId(), "删除成功") + e.OK(object.GetId(), "删除成功") } // @Summary 修改头像 @@ -256,9 +261,10 @@ func (e *SysUser) DeleteSysUser(c *gin.Context) { // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/user/avatar [post] -func (e *SysUser) InsetSysUserAvatar(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysUser) InsetSysUserAvatar(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -277,7 +283,7 @@ func (e *SysUser) InsetSysUserAvatar(c *gin.Context) { err = c.SaveUploadedFile(file, filPath) if err != nil { log.Errorf("save file error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "") + e.Error(http.StatusInternalServerError, err, "") return } } @@ -294,7 +300,7 @@ func (e *SysUser) InsetSysUserAvatar(c *gin.Context) { log.Error(err) return } - e.OK(c, filPath, "修改成功") + e.OK(filPath, "修改成功") } // @Summary 重置密码 @@ -306,9 +312,10 @@ func (e *SysUser) InsetSysUserAvatar(c *gin.Context) { // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/v1/user/pwd [post] // @Security Bearer -func (e *SysUser) SysUserUpdatePwd(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysUser) SysUserUpdatePwd(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -318,7 +325,7 @@ func (e *SysUser) SysUserUpdatePwd(c *gin.Context) { err = c.Bind(&pwd) if err != nil { log.Errorf("Bind error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -331,10 +338,10 @@ func (e *SysUser) SysUserUpdatePwd(c *gin.Context) { err = serviceSysUser.UpdateSysUserPwd(user.GetUserId(c), pwd.OldPassword, pwd.NewPassword, p) if err != nil { log.Error(err) - e.Error(c, http.StatusForbidden, err, "密码修改失败") + e.Error(http.StatusForbidden, err, "密码修改失败") return } - e.OK(c, nil, "密码修改成功") + e.OK(nil, "密码修改成功") } // @Summary 获取个人中心用户 @@ -343,9 +350,10 @@ func (e *SysUser) SysUserUpdatePwd(c *gin.Context) { // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/v1/user/profile [get] // @Security Bearer -func (e *SysUser) GetSysUserProfile(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysUser) GetSysUserProfile(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -361,10 +369,10 @@ func (e *SysUser) GetSysUserProfile(c *gin.Context) { err = serviceSysUser.GetSysUserProfile(id, user, &roles, &posts) if err != nil { log.Errorf("get user profile error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "获取用户信息失败") + e.Error(http.StatusInternalServerError, err, "获取用户信息失败") return } - e.OK(c, gin.H{ + e.OK(gin.H{ "user": user, "roles": roles, "posts": posts, @@ -402,10 +410,11 @@ func (e *SysUser) GetSysUserProfile(c *gin.Context) { //}) } -func (e *SysUser) GetInfo(c *gin.Context) { - log := e.GetLogger(c) +func (e SysUser) GetInfo(c *gin.Context) { + e.Context = c + log := e.GetLogger() - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -445,7 +454,7 @@ func (e *SysUser) GetInfo(c *gin.Context) { serviceSysUser.Orm = db err = serviceSysUser.GetSysUser(req, p, &sysUser) if err != nil { - e.Error(c, http.StatusUnauthorized, err, "登录失败") + e.Error(http.StatusUnauthorized, err, "登录失败") return } @@ -459,5 +468,5 @@ func (e *SysUser) GetInfo(c *gin.Context) { mp["userId"] = sysUser.UserId mp["deptId"] = sysUser.DeptId mp["name"] = sysUser.NickName - e.OK(c, mp, "") + e.OK(mp, "") } diff --git a/app/admin/apis/system/captcha.go b/app/admin/apis/system/captcha.go index 03c20c9a6..511fb7841 100644 --- a/app/admin/apis/system/captcha.go +++ b/app/admin/apis/system/captcha.go @@ -10,15 +10,16 @@ type System struct { apis.Api } -func (e *System) GenerateCaptchaHandler(c *gin.Context) { - log := e.GetLogger(c) +func (e System) GenerateCaptchaHandler(c *gin.Context) { + e.Context = c + log := e.GetLogger() id, b64s, err := captcha.DriverDigitFunc() if err != nil { log.Errorf("DriverDigitFunc error, %s", err.Error()) - e.Error(c, 500, err, "验证码获取失败") + e.Error(500, err, "验证码获取失败") return } - e.Custom(c, gin.H{ + e.Custom(gin.H{ "code": 200, "data": b64s, "id": id, diff --git a/app/admin/apis/system/dict/sys_dict_data.go b/app/admin/apis/system/dict/sys_dict_data.go index f440bccc3..94d16df7f 100644 --- a/app/admin/apis/system/dict/sys_dict_data.go +++ b/app/admin/apis/system/dict/sys_dict_data.go @@ -29,9 +29,10 @@ type SysDictData struct { // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/v1/dict/data [get] // @Security Bearer -func (e *SysDictData) GetSysDictDataList(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysDictData) GetSysDictDataList(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -43,7 +44,7 @@ func (e *SysDictData) GetSysDictDataList(c *gin.Context) { err = req.Bind(c) if err != nil { log.Warnf("Bind error: %s", err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -55,11 +56,11 @@ func (e *SysDictData) GetSysDictDataList(c *gin.Context) { err = s.GetPage(req, &list, &count) if err != nil { log.Errorf("GetPage error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "查询失败") + e.Error(http.StatusInternalServerError, err, "查询失败") return } - e.PageOK(c, list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功") + e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功") } // @Summary 通过编码获取字典数据 @@ -69,9 +70,10 @@ func (e *SysDictData) GetSysDictDataList(c *gin.Context) { // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/v1/dict/data/{dictCode} [get] // @Security Bearer -func (e *SysDictData) GetSysDictData(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysDictData) GetSysDictData(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -82,7 +84,7 @@ func (e *SysDictData) GetSysDictData(c *gin.Context) { err = req.Bind(c) if err != nil { log.Warnf("Bind error: %s", err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } var object system.SysDictData @@ -93,11 +95,11 @@ func (e *SysDictData) GetSysDictData(c *gin.Context) { err = s.Get(req, &object) if err != nil { log.Warnf("Get error: %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "查询失败") + e.Error(http.StatusInternalServerError, err, "查询失败") return } - e.OK(c, object, "查看成功") + e.OK(object, "查看成功") } // @Summary 添加字典数据 @@ -110,9 +112,10 @@ func (e *SysDictData) GetSysDictData(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/dict/data [post] // @Security Bearer -func (e *SysDictData) InsertSysDictData(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysDictData) InsertSysDictData(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -123,7 +126,7 @@ func (e *SysDictData) InsertSysDictData(c *gin.Context) { err = req.Bind(c) if err != nil { log.Warnf("Bind error: %s", err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, _ := req.GenerateM() @@ -136,11 +139,11 @@ func (e *SysDictData) InsertSysDictData(c *gin.Context) { err = s.Insert(object.(*system.SysDictData)) if err != nil { log.Errorf("Insert error, %s", err) - e.Error(c, http.StatusInternalServerError, err, "创建失败") + e.Error(http.StatusInternalServerError, err, "创建失败") return } - e.OK(c, object.GetId(), "创建成功") + e.OK(object.GetId(), "创建成功") } // @Summary 修改字典数据 @@ -153,9 +156,10 @@ func (e *SysDictData) InsertSysDictData(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/dict/data/{dictCode} [put] // @Security Bearer -func (e *SysDictData) UpdateSysDictData(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysDictData) UpdateSysDictData(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -166,7 +170,7 @@ func (e *SysDictData) UpdateSysDictData(c *gin.Context) { err = req.Bind(c) if err != nil { log.Warnf("request validate error, %s", err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, _ := req.GenerateM() @@ -178,10 +182,10 @@ func (e *SysDictData) UpdateSysDictData(c *gin.Context) { err = s.Update(object.(*system.SysDictData)) if err != nil { log.Errorf("Update error, %s", err) - e.Error(c, http.StatusInternalServerError, err, "更新失败") + e.Error(http.StatusInternalServerError, err, "更新失败") return } - e.OK(c, object.GetId(), "更新成功") + e.OK(object.GetId(), "更新成功") } // @Summary 删除字典数据 @@ -191,9 +195,10 @@ func (e *SysDictData) UpdateSysDictData(c *gin.Context) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": -1, "message": "删除失败"}" // @Router /api/v1/dict/data/{dictCode} [delete] -func (e *SysDictData) DeleteSysDictData(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysDictData) DeleteSysDictData(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -204,14 +209,14 @@ func (e *SysDictData) DeleteSysDictData(c *gin.Context) { err = req.Bind(c) if err != nil { log.Warnf("Bind error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } var object common.ActiveRecord object, err = req.GenerateM() if err != nil { log.Errorf("GenerateM error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } @@ -224,15 +229,16 @@ func (e *SysDictData) DeleteSysDictData(c *gin.Context) { err = s.Remove(req, object.(*system.SysDictData)) if err != nil { log.Errorf("Remove error, %s", err) - e.Error(c, http.StatusInternalServerError, err, "删除失败") + e.Error(http.StatusInternalServerError, err, "删除失败") return } - e.OK(c, object.GetId(), "删除成功") + e.OK(object.GetId(), "删除成功") } -func (e *SysDictData) GetSysDictDataAll(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysDictData) GetSysDictDataAll(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -244,7 +250,7 @@ func (e *SysDictData) GetSysDictDataAll(c *gin.Context) { err = req.Bind(c) if err != nil { log.Warnf("Bind error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -255,9 +261,9 @@ func (e *SysDictData) GetSysDictDataAll(c *gin.Context) { err = s.GetAll(req, &list) if err != nil { log.Errorf("GetAll error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "查询失败") + e.Error(http.StatusInternalServerError, err, "查询失败") return } - e.OK(c, list, "查询成功") + e.OK(list, "查询成功") } diff --git a/app/admin/apis/system/dict/sys_dict_type.go b/app/admin/apis/system/dict/sys_dict_type.go index 6a0c5293d..c2a05296a 100644 --- a/app/admin/apis/system/dict/sys_dict_type.go +++ b/app/admin/apis/system/dict/sys_dict_type.go @@ -29,9 +29,10 @@ type SysDictType struct { // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/v1/dict/type [get] // @Security Bearer -func (e *SysDictType) GetSysDictTypeList(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysDictType) GetSysDictTypeList(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -42,7 +43,7 @@ func (e *SysDictType) GetSysDictTypeList(c *gin.Context) { //查询列表 err = req.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -53,11 +54,11 @@ func (e *SysDictType) GetSysDictTypeList(c *gin.Context) { s.Orm = db.Debug() err = s.GetPage(req, &list, &count) if err != nil { - e.Error(c, http.StatusInternalServerError, err, "查询失败") + e.Error(http.StatusInternalServerError, err, "查询失败") return } - e.PageOK(c, list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功") + e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功") } // @Summary 通过字典id获取字典类型 @@ -67,9 +68,10 @@ func (e *SysDictType) GetSysDictTypeList(c *gin.Context) { // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/v1/dict/type/{dictId} [get] // @Security Bearer -func (e *SysDictType) GetSysDictType(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysDictType) GetSysDictType(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -79,7 +81,7 @@ func (e *SysDictType) GetSysDictType(c *gin.Context) { req := &dto.SysDictTypeById{} err = req.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } var object system.SysDictType @@ -89,11 +91,11 @@ func (e *SysDictType) GetSysDictType(c *gin.Context) { s.Orm = db err = s.Get(req, &object) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } - e.OK(c, object, "查看成功") + e.OK(object, "查看成功") } // @Summary 添加字典类型 @@ -106,9 +108,10 @@ func (e *SysDictType) GetSysDictType(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/dict/type [post] // @Security Bearer -func (e *SysDictType) InsertSysDictType(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysDictType) InsertSysDictType(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -118,7 +121,7 @@ func (e *SysDictType) InsertSysDictType(c *gin.Context) { req := &dto.SysDictTypeControl{} err = req.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, _ := req.GenerateM() @@ -131,11 +134,11 @@ func (e *SysDictType) InsertSysDictType(c *gin.Context) { err = s.Insert(object.(*system.SysDictType)) if err != nil { log.Error(err) - e.Error(c, http.StatusInternalServerError, err, "创建失败") + e.Error(http.StatusInternalServerError, err, "创建失败") return } - e.OK(c, object.GetId(), "创建成功") + e.OK(object.GetId(), "创建成功") } // @Summary 修改字典类型 @@ -148,9 +151,10 @@ func (e *SysDictType) InsertSysDictType(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/dict/type/{dictId} [put] // @Security Bearer -func (e *SysDictType) UpdateSysDictType(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysDictType) UpdateSysDictType(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -160,7 +164,7 @@ func (e *SysDictType) UpdateSysDictType(c *gin.Context) { //更新操作 err = req.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, _ := req.GenerateM() @@ -174,7 +178,7 @@ func (e *SysDictType) UpdateSysDictType(c *gin.Context) { log.Error(err) return } - e.OK(c, object.GetId(), "更新成功") + e.OK(object.GetId(), "更新成功") } // @Summary 删除字典类型 @@ -184,9 +188,10 @@ func (e *SysDictType) UpdateSysDictType(c *gin.Context) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": -1, "message": "删除失败"}" // @Router /api/v1/dict/type/{dictId} [delete] -func (e *SysDictType) DeleteSysDictType(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysDictType) DeleteSysDictType(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -197,13 +202,13 @@ func (e *SysDictType) DeleteSysDictType(c *gin.Context) { err = req.Bind(c) if err != nil { log.Errorf("Bind error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } var object common.ActiveRecord object, err = req.GenerateM() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } @@ -218,7 +223,7 @@ func (e *SysDictType) DeleteSysDictType(c *gin.Context) { log.Error(err) return } - e.OK(c, object.GetId(), "删除成功") + e.OK(object.GetId(), "删除成功") } // @Summary 字典类型全部数据 @@ -230,9 +235,10 @@ func (e *SysDictType) DeleteSysDictType(c *gin.Context) { // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/v1/dict/type-option-select [get] // @Security Bearer -func (e *SysDictType) GetSysDictTypeAll(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysDictType) GetSysDictTypeAll(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -243,7 +249,7 @@ func (e *SysDictType) GetSysDictTypeAll(c *gin.Context) { //查询列表 err = req.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -253,9 +259,9 @@ func (e *SysDictType) GetSysDictTypeAll(c *gin.Context) { s.Orm = db err = s.GetAll(req, &list) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } - e.OK(c, list, "查询成功") + e.OK(list, "查询成功") } diff --git a/app/admin/apis/system/settings.go b/app/admin/apis/system/settings.go index 2b16fdf47..af53e0ebf 100644 --- a/app/admin/apis/system/settings.go +++ b/app/admin/apis/system/settings.go @@ -23,9 +23,10 @@ type SysSetting struct { // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/setting [get] -func (e *SysSetting) GetSetting(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysSetting) GetSetting(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -37,7 +38,7 @@ func (e *SysSetting) GetSetting(c *gin.Context) { var model = models.SysSetting{} err = sysSettingService.GetSysSetting(&model) if err != nil { - e.Error(c, http.StatusInternalServerError, err, "查询失败") + e.Error(http.StatusInternalServerError, err, "查询失败") return } @@ -47,7 +48,7 @@ func (e *SysSetting) GetSetting(c *gin.Context) { } } - e.OK(c, model, "查询成功") + e.OK(model, "查询成功") } // @Summary 更新或提交系统信息 @@ -57,10 +58,11 @@ func (e *SysSetting) GetSetting(c *gin.Context) { // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/system/setting [post] -func (e *SysSetting) CreateOrUpdateSetting(c *gin.Context) { +func (e SysSetting) CreateOrUpdateSetting(c *gin.Context) { control := new(dto.SysSettingControl) - log := e.GetLogger(c) - db, err := e.GetOrm(c) + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -69,12 +71,12 @@ func (e *SysSetting) CreateOrUpdateSetting(c *gin.Context) { //更新操作 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.Generate() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } @@ -83,7 +85,7 @@ func (e *SysSetting) CreateOrUpdateSetting(c *gin.Context) { sysSettingService.Orm = db err = sysSettingService.UpdateSysSetting(object) if err != nil { - e.Error(c, http.StatusInternalServerError, err, "更新失败") + e.Error(http.StatusInternalServerError, err, "更新失败") return } @@ -92,5 +94,5 @@ func (e *SysSetting) CreateOrUpdateSetting(c *gin.Context) { object.Logo = fmt.Sprintf("http://%s/%s", c.Request.Host, object.Logo) } } - e.OK(c, object, "提交成功") + e.OK(object, "提交成功") } diff --git a/app/admin/apis/system/sys_config/sys_config.go b/app/admin/apis/system/sys_config/sys_config.go index 431ae0ce3..977de4f89 100644 --- a/app/admin/apis/system/sys_config/sys_config.go +++ b/app/admin/apis/system/sys_config/sys_config.go @@ -16,10 +16,11 @@ type SysConfig struct { apis.Api } -func (e *SysConfig) GetSysConfigList(c *gin.Context) { - log := e.GetLogger(c) +func (e SysConfig) GetSysConfigList(c *gin.Context) { + e.Context = c + log := e.GetLogger() d := new(dto.SysConfigSearch) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -29,7 +30,7 @@ func (e *SysConfig) GetSysConfigList(c *gin.Context) { err = d.Bind(c) if err != nil { log.Errorf("参数验证失败, error:%s", err) - e.Error(c, 500, err, "参数验证失败") + e.Error(500, err, "参数验证失败") return } @@ -41,17 +42,18 @@ func (e *SysConfig) GetSysConfigList(c *gin.Context) { err = s.GetSysConfigPage(d, &list, &count) if err != nil { log.Errorf("GetSysConfigPage 查询失败, error:%s", err) - e.Error(c, 500, err, "查询失败") + e.Error(500, err, "查询失败") return } - e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功") + e.PageOK(list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功") } // GetSysConfigBySysApp 获取系统配置信息,主要注意这里不在验证数据权限 -func (e *SysConfig) GetSysConfigBySysApp(c *gin.Context) { - log := e.GetLogger(c) +func (e SysConfig) GetSysConfigBySysApp(c *gin.Context) { + e.Context = c + log := e.GetLogger() d := new(dto.SysConfigSearch) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -59,7 +61,7 @@ func (e *SysConfig) GetSysConfigBySysApp(c *gin.Context) { err = d.Bind(c) if err != nil { log.Errorf("参数验证失败, error:%s", err) - e.Error(c, 500, err, "参数验证失败") + e.Error(500, err, "参数验证失败") return } @@ -73,7 +75,7 @@ func (e *SysConfig) GetSysConfigBySysApp(c *gin.Context) { err = s.GetSysConfigByKey(d, &list) if err != nil { log.Errorf("GetSysConfigPage 查询失败, error:%s", err) - e.Error(c, 500, err, "查询失败") + e.Error(500, err, "查询失败") return } mp := make(map[string]string) @@ -83,13 +85,14 @@ func (e *SysConfig) GetSysConfigBySysApp(c *gin.Context) { mp[key] = list[i].ConfigValue } } - e.OK(c, mp, "查询成功") + e.OK(mp, "查询成功") } -func (e *SysConfig) GetSysConfig(c *gin.Context) { - log := e.GetLogger(c) +func (e SysConfig) GetSysConfig(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysConfigById) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -97,9 +100,9 @@ func (e *SysConfig) GetSysConfig(c *gin.Context) { //查看详情 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") log.Errorf("Orm获取失败, error:%s", err) - e.Error(c, 500, err, "Orm获取失败") + e.Error(500, err, "Orm获取失败") return } var object system.SysConfig @@ -109,19 +112,20 @@ func (e *SysConfig) GetSysConfig(c *gin.Context) { serviceSysLoginLog.Orm = db err = serviceSysLoginLog.GetSysConfig(control, &object) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") log.Errorf("Orm获取失败, error:%s", err) - e.Error(c, 500, err, "Orm获取失败") + e.Error(500, err, "Orm获取失败") return } - e.OK(c, object, "查看成功") + e.OK(object, "查看成功") } -func (e *SysConfig) InsertSysConfig(c *gin.Context) { - log := e.GetLogger(c) +func (e SysConfig) InsertSysConfig(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysConfigControl) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -130,16 +134,16 @@ func (e *SysConfig) InsertSysConfig(c *gin.Context) { //新增操作 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") log.Errorf("Orm获取失败, error:%s", err) - e.Error(c, 500, err, "Orm获取失败") + e.Error(500, err, "Orm获取失败") return } object, err := control.Generate() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") log.Errorf("Orm获取失败, error:%s", err) - e.Error(c, 500, err, "Orm获取失败") + e.Error(500, err, "Orm获取失败") return } // 设置创建人 @@ -151,19 +155,20 @@ func (e *SysConfig) InsertSysConfig(c *gin.Context) { err = serviceSysLoginLog.InsertSysConfig(object) if err != nil { log.Error(err) - e.Error(c, http.StatusInternalServerError, err, "创建失败") + e.Error(http.StatusInternalServerError, err, "创建失败") log.Errorf("Orm获取失败, error:%s", err) - e.Error(c, 500, err, "Orm获取失败") + e.Error(500, err, "Orm获取失败") return } - e.OK(c, object.GetId(), "创建成功") + e.OK(object.GetId(), "创建成功") } -func (e *SysConfig) UpdateSysConfig(c *gin.Context) { - log := e.GetLogger(c) +func (e SysConfig) UpdateSysConfig(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysConfigControl) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -173,16 +178,16 @@ func (e *SysConfig) UpdateSysConfig(c *gin.Context) { err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") log.Errorf("Orm获取失败, error:%s", err) - e.Error(c, 500, err, "Orm获取失败") + e.Error(500, err, "Orm获取失败") return } object, err := control.Generate() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") log.Errorf("Orm获取失败, error:%s", err) - e.Error(c, 500, err, "Orm获取失败") + e.Error(500, err, "Orm获取失败") return } object.SetUpdateBy(user.GetUserId(c)) @@ -192,18 +197,19 @@ func (e *SysConfig) UpdateSysConfig(c *gin.Context) { serviceSysLoginLog.Log = log err = serviceSysLoginLog.UpdateSysConfig(object) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "更新失败") + e.Error(http.StatusUnprocessableEntity, err, "更新失败") log.Errorf("Orm获取失败, error:%s", err) - e.Error(c, 500, err, "Orm获取失败") + e.Error(500, err, "Orm获取失败") return } - e.OK(c, object.GetId(), "更新成功") + e.OK(object.GetId(), "更新成功") } -func (e *SysConfig) DeleteSysConfig(c *gin.Context) { - log := e.GetLogger(c) +func (e SysConfig) DeleteSysConfig(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysConfigById) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -213,16 +219,16 @@ func (e *SysConfig) DeleteSysConfig(c *gin.Context) { err = control.Bind(c) if err != nil { log.Errorf("Bind error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") log.Errorf("Orm获取失败, error:%s", err) - e.Error(c, 500, err, "Orm获取失败") + e.Error(500, err, "Orm获取失败") return } object, err := control.GenerateM() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") log.Errorf("Orm获取失败, error:%s", err) - e.Error(c, 500, err, "Orm获取失败") + e.Error(500, err, "Orm获取失败") return } @@ -234,18 +240,19 @@ func (e *SysConfig) DeleteSysConfig(c *gin.Context) { serviceSysLoginLog.Log = log err = serviceSysLoginLog.RemoveSysConfig(control, object) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "删除失败") + e.Error(http.StatusUnprocessableEntity, err, "删除失败") log.Errorf("Orm获取失败, error:%s", err) - e.Error(c, 500, err, "Orm获取失败") + e.Error(500, err, "Orm获取失败") return } - e.OK(c, object.GetId(), "删除成功") + e.OK(object.GetId(), "删除成功") } // GetSysConfigByKEYForService 根据Key获取SysConfig的Service -func (e *SysConfig) GetSysConfigByKEYForService(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysConfig) GetSysConfigByKEYForService(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -254,7 +261,7 @@ func (e *SysConfig) GetSysConfigByKEYForService(c *gin.Context) { err = v.Bind(c) if err != nil { log.Errorf("参数验证错误, error:%s", err) - e.Error(c, 422, err, "参数验证失败") + e.Error(422, err, "参数验证失败") return } s := service.SysConfig{} @@ -263,8 +270,8 @@ func (e *SysConfig) GetSysConfigByKEYForService(c *gin.Context) { err = s.GetSysConfigByKEY(&v) if err != nil { log.Errorf("通过Key获取配置失败, error:%s", err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } - e.OK(c, v, s.Msg) + e.OK(v, s.Msg) } diff --git a/app/admin/apis/system/sys_dept/sys_dept.go b/app/admin/apis/system/sys_dept/sys_dept.go index e0074778c..71cfa0212 100644 --- a/app/admin/apis/system/sys_dept/sys_dept.go +++ b/app/admin/apis/system/sys_dept/sys_dept.go @@ -27,10 +27,11 @@ type SysDept struct { // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/v1/dept [get] // @Security Bearer -func (e *SysDept) GetSysDeptList(c *gin.Context) { - log := e.GetLogger(c) +func (e SysDept) GetSysDeptList(c *gin.Context) { + e.Context = c + log := e.GetLogger() d := new(dto.SysDeptSearch) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -39,7 +40,7 @@ func (e *SysDept) GetSysDeptList(c *gin.Context) { //查询列表 err = d.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -49,11 +50,11 @@ func (e *SysDept) GetSysDeptList(c *gin.Context) { serviceStudent.Orm = db list, err = serviceStudent.SetDeptPage(d) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } - e.OK(c, list, "查询成功") + e.OK(list, "查询成功") } // @Summary 部门列表数据 @@ -64,10 +65,11 @@ func (e *SysDept) GetSysDeptList(c *gin.Context) { // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/v1/dept/{deptId} [get] // @Security Bearer -func (e *SysDept) GetSysDept(c *gin.Context) { - log := e.GetLogger(c) +func (e SysDept) GetSysDept(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysDeptById) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -76,7 +78,7 @@ func (e *SysDept) GetSysDept(c *gin.Context) { //查看详情 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } var object system.SysDept @@ -86,11 +88,11 @@ func (e *SysDept) GetSysDept(c *gin.Context) { serviceSysOperlog.Orm = db err = serviceSysOperlog.GetSysDept(control, &object) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } - e.OK(c, object, "查看成功") + e.OK(object, "查看成功") } // @Summary 添加部门 @@ -103,10 +105,11 @@ func (e *SysDept) GetSysDept(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/dept [post] // @Security Bearer -func (e *SysDept) InsertSysDept(c *gin.Context) { - log := e.GetLogger(c) +func (e SysDept) InsertSysDept(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysDeptControl) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -115,12 +118,12 @@ func (e *SysDept) InsertSysDept(c *gin.Context) { //新增操作 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.Generate() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } // 设置创建人 @@ -132,11 +135,11 @@ func (e *SysDept) InsertSysDept(c *gin.Context) { err = serviceSysDept.InsertSysDept(object) if err != nil { log.Error(err) - e.Error(c, http.StatusInternalServerError, err, "创建失败") + e.Error(http.StatusInternalServerError, err, "创建失败") return } - e.OK(c, object.GetId(), "创建成功") + e.OK(object.GetId(), "创建成功") } // @Summary 修改部门 @@ -150,10 +153,11 @@ func (e *SysDept) InsertSysDept(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/dept/{deptId} [put] // @Security Bearer -func (e *SysDept) UpdateSysDept(c *gin.Context) { - log := e.GetLogger(c) +func (e SysDept) UpdateSysDept(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysDeptControl) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -162,12 +166,12 @@ func (e *SysDept) UpdateSysDept(c *gin.Context) { //更新操作 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.Generate() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } object.SetUpdateBy(user.GetUserId(c)) @@ -180,7 +184,7 @@ func (e *SysDept) UpdateSysDept(c *gin.Context) { log.Error(err) return } - e.OK(c, object.GetId(), "更新成功") + e.OK(object.GetId(), "更新成功") } // @Summary 删除部门 @@ -190,10 +194,11 @@ func (e *SysDept) UpdateSysDept(c *gin.Context) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": -1, "message": "删除失败"}" // @Router /api/v1/dept [delete] -func (e *SysDept) DeleteSysDept(c *gin.Context) { - log := e.GetLogger(c) +func (e SysDept) DeleteSysDept(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysDeptById) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -203,7 +208,7 @@ func (e *SysDept) DeleteSysDept(c *gin.Context) { err = control.Bind(c) if err != nil { log.Errorf("Bind error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -213,17 +218,18 @@ func (e *SysDept) DeleteSysDept(c *gin.Context) { err = serviceSysDept.RemoveSysDept(control) if err != nil { log.Errorf("RemoveSysDept error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "删除失败") + e.Error(http.StatusInternalServerError, err, "删除失败") return } - e.OK(c, control.GetId(), "删除成功") + e.OK(control.GetId(), "删除成功") } // GetDeptTree 用户管理 左侧部门树 -func (e *SysDept) GetDeptTree(c *gin.Context) { - log := e.GetLogger(c) +func (e SysDept) GetDeptTree(c *gin.Context) { + e.Context = c + log := e.GetLogger() d := new(dto.SysDeptSearch) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -232,7 +238,7 @@ func (e *SysDept) GetDeptTree(c *gin.Context) { //查询列表 err = d.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -242,7 +248,7 @@ func (e *SysDept) GetDeptTree(c *gin.Context) { serviceStudent.Orm = db list, err = serviceStudent.SetDeptTree(d) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } @@ -252,12 +258,13 @@ func (e *SysDept) GetDeptTree(c *gin.Context) { //Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId")) //result, err := Dept.SetDept(false) //tools.HasError(err, "抱歉未找到相关信息", -1) - e.OK(c, list, "") + e.OK(list, "") } -func (e *SysDept) GetDeptTreeRoleSelect(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysDept) GetDeptTreeRoleSelect(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -270,17 +277,17 @@ func (e *SysDept) GetDeptTreeRoleSelect(c *gin.Context) { result, err := s.SetDeptLabel() if err != nil { log.Errorf("SetDeptLabel error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "") + e.Error(http.StatusInternalServerError, err, "") } menuIds := make([]int, 0) if id != 0 { menuIds, err = s.GetRoleDeptId(id) if err != nil { log.Errorf("抱歉未找到相关信息, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "") + e.Error(http.StatusInternalServerError, err, "") } } - e.OK(c, gin.H{ + e.OK(gin.H{ "depts": result, "checkedKeys": menuIds, }, "") diff --git a/app/admin/apis/system/sys_login_log/sys_login_log.go b/app/admin/apis/system/sys_login_log/sys_login_log.go index 1940823ae..2c3cbe3cb 100644 --- a/app/admin/apis/system/sys_login_log/sys_login_log.go +++ b/app/admin/apis/system/sys_login_log/sys_login_log.go @@ -16,10 +16,11 @@ type SysLoginLog struct { apis.Api } -func (e *SysLoginLog) GetSysLoginLogList(c *gin.Context) { - log := e.GetLogger(c) +func (e SysLoginLog) GetSysLoginLogList(c *gin.Context) { + e.Context = c + log := e.GetLogger() d := new(dto.SysLoginLogSearch) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -28,7 +29,7 @@ func (e *SysLoginLog) GetSysLoginLogList(c *gin.Context) { //查询列表 err = d.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -39,17 +40,18 @@ func (e *SysLoginLog) GetSysLoginLogList(c *gin.Context) { serviceStudent.Orm = db err = serviceStudent.GetSysLoginLogPage(d, &list, &count) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } - e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功") + e.PageOK(list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功") } -func (e *SysLoginLog) GetSysLoginLog(c *gin.Context) { - log := e.GetLogger(c) +func (e SysLoginLog) GetSysLoginLog(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysLoginLogById) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -58,7 +60,7 @@ func (e *SysLoginLog) GetSysLoginLog(c *gin.Context) { //查看详情 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } var object system.SysLoginLog @@ -68,17 +70,18 @@ func (e *SysLoginLog) GetSysLoginLog(c *gin.Context) { serviceSysLoginLog.Orm = db err = serviceSysLoginLog.GetSysLoginLog(control, &object) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } - e.OK(c, object, "查看成功") + e.OK(object, "查看成功") } -func (e *SysLoginLog) InsertSysLoginLog(c *gin.Context) { - log := e.GetLogger(c) +func (e SysLoginLog) InsertSysLoginLog(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysLoginLogControl) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -87,12 +90,12 @@ func (e *SysLoginLog) InsertSysLoginLog(c *gin.Context) { //新增操作 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.Generate() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } // 设置创建人 @@ -104,17 +107,18 @@ func (e *SysLoginLog) InsertSysLoginLog(c *gin.Context) { err = serviceSysLoginLog.InsertSysLoginLog(object) if err != nil { log.Errorf("InsertSysLoginLog error, %s", err) - e.Error(c, http.StatusInternalServerError, err, "创建失败") + e.Error(http.StatusInternalServerError, err, "创建失败") return } - e.OK(c, object.GetId(), "创建成功") + e.OK(object.GetId(), "创建成功") } -func (e *SysLoginLog) UpdateSysLoginLog(c *gin.Context) { - log := e.GetLogger(c) +func (e SysLoginLog) UpdateSysLoginLog(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysLoginLogControl) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -123,12 +127,12 @@ func (e *SysLoginLog) UpdateSysLoginLog(c *gin.Context) { //更新操作 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.Generate() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } object.SetUpdateBy(user.GetUserId(c)) @@ -139,16 +143,17 @@ func (e *SysLoginLog) UpdateSysLoginLog(c *gin.Context) { err = serviceSysLoginLog.UpdateSysLoginLog(object) if err != nil { log.Errorf("UpdateSysLoginLog error, %s", err) - e.Error(c, http.StatusInternalServerError, err, "更新失败") + e.Error(http.StatusInternalServerError, err, "更新失败") return } - e.OK(c, object.GetId(), "更新成功") + e.OK(object.GetId(), "更新成功") } -func (e *SysLoginLog) DeleteSysLoginLog(c *gin.Context) { - log := e.GetLogger(c) +func (e SysLoginLog) DeleteSysLoginLog(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysLoginLogById) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -158,12 +163,12 @@ func (e *SysLoginLog) DeleteSysLoginLog(c *gin.Context) { err = control.Bind(c) if err != nil { log.Errorf("Bind error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.GenerateM() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } @@ -176,8 +181,8 @@ func (e *SysLoginLog) DeleteSysLoginLog(c *gin.Context) { err = serviceSysLoginLog.RemoveSysLoginLog(control, object) if err != nil { log.Errorf("RemoveSysLoginLog error, %s", err) - e.Error(c, http.StatusInternalServerError, err, "删除失败") + e.Error(http.StatusInternalServerError, err, "删除失败") return } - e.OK(c, object.GetId(), "删除成功") + e.OK(object.GetId(), "删除成功") } diff --git a/app/admin/apis/system/sys_menu/sys_menu.go b/app/admin/apis/system/sys_menu/sys_menu.go index 2c237a9df..7654b7863 100644 --- a/app/admin/apis/system/sys_menu/sys_menu.go +++ b/app/admin/apis/system/sys_menu/sys_menu.go @@ -24,10 +24,11 @@ type SysMenu struct { // @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}" // @Router /api/v1/menulist [get] // @Security Bearer -func (e *SysMenu) GetSysMenuList(c *gin.Context) { - log := e.GetLogger(c) +func (e SysMenu) GetSysMenuList(c *gin.Context) { + e.Context = c + log := e.GetLogger() d := new(dto.SysMenuSearch) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -36,7 +37,7 @@ func (e *SysMenu) GetSysMenuList(c *gin.Context) { //查询列表 err = d.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -46,11 +47,11 @@ func (e *SysMenu) GetSysMenuList(c *gin.Context) { serviceSysMenu.Orm = db list, err = serviceSysMenu.GetSysMenuPage(d) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } - e.OK(c, list, "查询成功") + e.OK(list, "查询成功") } // @Summary Menu详情数据 @@ -61,12 +62,13 @@ func (e *SysMenu) GetSysMenuList(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}" // @Router /api/v1/menu/{id} [get] // @Security Bearer -func (e *SysMenu) GetSysMenu(c *gin.Context) { +func (e SysMenu) GetSysMenu(c *gin.Context) { control := new(dto.SysMenuById) - log := e.GetLogger(c) + e.Context = c + log := e.GetLogger() - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -75,7 +77,7 @@ func (e *SysMenu) GetSysMenu(c *gin.Context) { //查看详情 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } var object system.SysMenu @@ -85,11 +87,11 @@ func (e *SysMenu) GetSysMenu(c *gin.Context) { serviceSysMenu.Orm = db err = serviceSysMenu.GetSysMenu(control, &object) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } - e.OK(c, object, "查看成功") + e.OK(object, "查看成功") } // @Summary 创建菜单 @@ -107,12 +109,13 @@ func (e *SysMenu) GetSysMenu(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/menu [post] // @Security Bearer -func (e *SysMenu) InsertSysMenu(c *gin.Context) { +func (e SysMenu) InsertSysMenu(c *gin.Context) { control := new(dto.SysMenuControl) - log := e.GetLogger(c) + e.Context = c + log := e.GetLogger() - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -121,12 +124,12 @@ func (e *SysMenu) InsertSysMenu(c *gin.Context) { //新增操作 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.Generate() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } // 设置创建人 @@ -138,11 +141,11 @@ func (e *SysMenu) InsertSysMenu(c *gin.Context) { err = serviceSysMenu.InsertSysMenu(object) if err != nil { log.Error(err) - e.Error(c, http.StatusInternalServerError, err, "创建失败") + e.Error(http.StatusInternalServerError, err, "创建失败") return } - e.OK(c, object.GetId(), "创建成功") + e.OK(object.GetId(), "创建成功") } // @Summary 修改菜单 @@ -156,12 +159,13 @@ func (e *SysMenu) InsertSysMenu(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "修改失败"}" // @Router /api/v1/menu/{id} [put] // @Security Bearer -func (e *SysMenu) UpdateSysMenu(c *gin.Context) { +func (e SysMenu) UpdateSysMenu(c *gin.Context) { control := new(dto.SysMenuControl) - log := e.GetLogger(c) + e.Context = c + log := e.GetLogger() - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -170,12 +174,12 @@ func (e *SysMenu) UpdateSysMenu(c *gin.Context) { //更新操作 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.Generate() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } object.SetUpdateBy(user.GetUserId(c)) @@ -188,7 +192,7 @@ func (e *SysMenu) UpdateSysMenu(c *gin.Context) { log.Error(err) return } - e.OK(c, object.GetId(), "更新成功") + e.OK(object.GetId(), "更新成功") } // @Summary 删除菜单 @@ -198,12 +202,13 @@ func (e *SysMenu) UpdateSysMenu(c *gin.Context) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": -1, "message": "删除失败"}" // @Router /api/v1/menu/ [delete] -func (e *SysMenu) DeleteSysMenu(c *gin.Context) { +func (e SysMenu) DeleteSysMenu(c *gin.Context) { control := new(dto.SysMenuById) - log := e.GetLogger(c) + e.Context = c + log := e.GetLogger() - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -213,7 +218,7 @@ func (e *SysMenu) DeleteSysMenu(c *gin.Context) { err = control.Bind(c) if err != nil { log.Errorf("Bind error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -223,10 +228,10 @@ func (e *SysMenu) DeleteSysMenu(c *gin.Context) { err = serviceSysMenu.RemoveSysMenu(control) if err != nil { log.Errorf("RemoveSysMenu error, %s", err) - e.Error(c, http.StatusInternalServerError, err, "删除失败") + e.Error(http.StatusInternalServerError, err, "删除失败") return } - e.OK(c, control.GetId(), "删除成功") + e.OK(control.GetId(), "删除成功") } // @Summary 根据角色名称获取菜单列表数据(左菜单使用) @@ -237,9 +242,10 @@ func (e *SysMenu) DeleteSysMenu(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}" // @Router /api/v1/menurole [get] // @Security Bearer -func (e *SysMenu) GetMenuRole(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysMenu) GetMenuRole(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -251,11 +257,11 @@ func (e *SysMenu) GetMenuRole(c *gin.Context) { result, err := serviceSysMenu.SetMenuRole(user.GetRoleName(c)) if err != nil { - e.Error(c, http.StatusInternalServerError, err, "查询失败") + e.Error(http.StatusInternalServerError, err, "查询失败") return } - e.OK(c, result, "") + e.OK(result, "") } // @Summary 获取角色对应的菜单id数组 @@ -266,9 +272,10 @@ func (e *SysMenu) GetMenuRole(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}" // @Router /api/v1/menuids/{id} [get] // @Security Bearer -func (e *SysMenu) GetMenuIDS(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysMenu) GetMenuIDS(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -279,14 +286,14 @@ func (e *SysMenu) GetMenuIDS(c *gin.Context) { result, err := data.GetIDS(db) if err != nil { log.Errorf("GetIDS error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "获取失败") + e.Error(http.StatusInternalServerError, err, "获取失败") return } - e.OK(c, result, "") + e.OK(result, "") } //// GetMenuTreeRoleselect 角色修改中的菜单列表 -//func (e *SysMenu) GetMenuTreeRoleselect(c *gin.Context) { +//func (e SysMenu) GetMenuTreeRoleselect(c *gin.Context) { // var Menu models.Menu // var SysRole models.SysRole // @@ -321,9 +328,10 @@ func (e *SysMenu) GetMenuIDS(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/menuTreeselect [get] // @Security Bearer -func (e *SysMenu) GetMenuTreeSelect(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) +func (e SysMenu) GetMenuTreeSelect(c *gin.Context) { + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -333,7 +341,7 @@ func (e *SysMenu) GetMenuTreeSelect(c *gin.Context) { err = c.BindUri(d) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -342,7 +350,7 @@ func (e *SysMenu) GetMenuTreeSelect(c *gin.Context) { serviceSysMenu.Orm = db result, err := serviceSysMenu.SetSysMenuLabel() if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } s := service.SysRole{} @@ -351,10 +359,10 @@ func (e *SysMenu) GetMenuTreeSelect(c *gin.Context) { menuIds, err := s.GetRoleMenuId(db, d.RoleId) if err != nil { log.Errorf("GetIDS error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "") + e.Error(http.StatusInternalServerError, err, "") return } - e.OK(c, gin.H{ + e.OK(gin.H{ "menus": result, "checkedKeys": menuIds, }, "获取成功") diff --git a/app/admin/apis/system/sys_opera_log/sys_opera_log.go b/app/admin/apis/system/sys_opera_log/sys_opera_log.go index 0998ddc5f..8a1502762 100644 --- a/app/admin/apis/system/sys_opera_log/sys_opera_log.go +++ b/app/admin/apis/system/sys_opera_log/sys_opera_log.go @@ -16,10 +16,11 @@ type SysOperaLog struct { apis.Api } -func (e *SysOperaLog) GetSysOperaLogList(c *gin.Context) { - log := e.GetLogger(c) +func (e SysOperaLog) GetSysOperaLogList(c *gin.Context) { + e.Context = c + log := e.GetLogger() d := new(dto.SysOperaLogSearch) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -28,7 +29,7 @@ func (e *SysOperaLog) GetSysOperaLogList(c *gin.Context) { //查询列表 err = d.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -39,17 +40,18 @@ func (e *SysOperaLog) GetSysOperaLogList(c *gin.Context) { serviceStudent.Orm = db err = serviceStudent.GetSysOperaLogPage(d, &list, &count) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } - e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功") + e.PageOK(list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功") } -func (e *SysOperaLog) GetSysOperaLog(c *gin.Context) { - log := e.GetLogger(c) +func (e SysOperaLog) GetSysOperaLog(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysOperaLogById) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -58,7 +60,7 @@ func (e *SysOperaLog) GetSysOperaLog(c *gin.Context) { //查看详情 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } var object system.SysOperaLog @@ -68,17 +70,18 @@ func (e *SysOperaLog) GetSysOperaLog(c *gin.Context) { serviceSysOperlog.Orm = db err = serviceSysOperlog.GetSysOperaLog(control, &object) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } - e.OK(c, object, "查看成功") + e.OK(object, "查看成功") } -func (e *SysOperaLog) InsertSysOperaLog(c *gin.Context) { - log := e.GetLogger(c) +func (e SysOperaLog) InsertSysOperaLog(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysOperaLogControl) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -87,12 +90,12 @@ func (e *SysOperaLog) InsertSysOperaLog(c *gin.Context) { //新增操作 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.Generate() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } // 设置创建人 @@ -104,17 +107,18 @@ func (e *SysOperaLog) InsertSysOperaLog(c *gin.Context) { err = serviceSysOperaLog.InsertSysOperaLog(object) if err != nil { log.Error(err) - e.Error(c, http.StatusInternalServerError, err, "创建失败") + e.Error(http.StatusInternalServerError, err, "创建失败") return } - e.OK(c, object.GetId(), "创建成功") + e.OK(object.GetId(), "创建成功") } -func (e *SysOperaLog) UpdateSysOperaLog(c *gin.Context) { - log := e.GetLogger(c) +func (e SysOperaLog) UpdateSysOperaLog(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysOperaLogControl) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -123,12 +127,12 @@ func (e *SysOperaLog) UpdateSysOperaLog(c *gin.Context) { //更新操作 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.Generate() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } object.SetUpdateBy(user.GetUserId(c)) @@ -141,13 +145,14 @@ func (e *SysOperaLog) UpdateSysOperaLog(c *gin.Context) { log.Error(err) return } - e.OK(c, object.GetId(), "更新成功") + e.OK(object.GetId(), "更新成功") } -func (e *SysOperaLog) DeleteSysOperaLog(c *gin.Context) { - log := e.GetLogger(c) +func (e SysOperaLog) DeleteSysOperaLog(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysOperaLogById) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -157,7 +162,7 @@ func (e *SysOperaLog) DeleteSysOperaLog(c *gin.Context) { err = control.Bind(c) if err != nil { log.Errorf("Bind error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -169,5 +174,5 @@ func (e *SysOperaLog) DeleteSysOperaLog(c *gin.Context) { log.Error(err) return } - e.OK(c, control.GetId(), "删除成功") + e.OK(control.GetId(), "删除成功") } diff --git a/app/admin/apis/system/sys_post/sys_post.go b/app/admin/apis/system/sys_post/sys_post.go index 4a56d6409..a4789bb4b 100644 --- a/app/admin/apis/system/sys_post/sys_post.go +++ b/app/admin/apis/system/sys_post/sys_post.go @@ -27,10 +27,11 @@ type SysPost struct { // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/v1/post [get] // @Security Bearer -func (e *SysPost) GetSysPostList(c *gin.Context) { - log := e.GetLogger(c) +func (e SysPost) GetSysPostList(c *gin.Context) { + e.Context = c + log := e.GetLogger() d := new(dto.SysPostSearch) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -39,7 +40,7 @@ func (e *SysPost) GetSysPostList(c *gin.Context) { //查询列表 err = d.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -50,11 +51,11 @@ func (e *SysPost) GetSysPostList(c *gin.Context) { serviceStudent.Orm = db err = serviceStudent.GetSysPostPage(d, &list, &count) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } - e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功") + e.PageOK(list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功") } // @Summary 获取岗位信息 @@ -64,10 +65,11 @@ func (e *SysPost) GetSysPostList(c *gin.Context) { // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/v1/post/{postId} [get] // @Security Bearer -func (e *SysPost) GetSysPost(c *gin.Context) { - log := e.GetLogger(c) +func (e SysPost) GetSysPost(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysPostById) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -76,7 +78,7 @@ func (e *SysPost) GetSysPost(c *gin.Context) { //查看详情 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } var object system.SysPost @@ -86,11 +88,11 @@ func (e *SysPost) GetSysPost(c *gin.Context) { serviceSysOperlog.Orm = db err = serviceSysOperlog.GetSysPost(control, &object) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } - e.OK(c, object, "查看成功") + e.OK(object, "查看成功") } // @Summary 添加岗位 @@ -103,10 +105,11 @@ func (e *SysPost) GetSysPost(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/post [post] // @Security Bearer -func (e *SysPost) InsertSysPost(c *gin.Context) { - log := e.GetLogger(c) +func (e SysPost) InsertSysPost(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysPostControl) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -115,12 +118,12 @@ func (e *SysPost) InsertSysPost(c *gin.Context) { //新增操作 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.Generate() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } // 设置创建人 @@ -132,11 +135,11 @@ func (e *SysPost) InsertSysPost(c *gin.Context) { err = serviceSysPost.InsertSysPost(object) if err != nil { log.Error(err) - e.Error(c, http.StatusInternalServerError, err, "创建失败") + e.Error(http.StatusInternalServerError, err, "创建失败") return } - e.OK(c, object.GetId(), "创建成功") + e.OK(object.GetId(), "创建成功") } // @Summary 修改岗位 @@ -149,10 +152,11 @@ func (e *SysPost) InsertSysPost(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/post/ [put] // @Security Bearer -func (e *SysPost) UpdateSysPost(c *gin.Context) { - log := e.GetLogger(c) +func (e SysPost) UpdateSysPost(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysPostControl) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -161,12 +165,12 @@ func (e *SysPost) UpdateSysPost(c *gin.Context) { //更新操作 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.Generate() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } object.SetUpdateBy(user.GetUserId(c)) @@ -179,7 +183,7 @@ func (e *SysPost) UpdateSysPost(c *gin.Context) { log.Error(err) return } - e.OK(c, object.GetId(), "更新成功") + e.OK(object.GetId(), "更新成功") } // @Summary 删除岗位 @@ -189,10 +193,11 @@ func (e *SysPost) UpdateSysPost(c *gin.Context) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 500 {string} string "{"code": 500, "message": "删除失败"}" // @Router /api/v1/post/{postId} [delete] -func (e *SysPost) DeleteSysPost(c *gin.Context) { - log := e.GetLogger(c) +func (e SysPost) DeleteSysPost(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysPostById) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -202,7 +207,7 @@ func (e *SysPost) DeleteSysPost(c *gin.Context) { err = control.Bind(c) if err != nil { log.Errorf("Bind error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -214,5 +219,5 @@ func (e *SysPost) DeleteSysPost(c *gin.Context) { log.Error(err) return } - e.OK(c, control.GetId(), "删除成功") + e.OK(control.GetId(), "删除成功") } diff --git a/app/admin/apis/system/sys_role/sys_role.go b/app/admin/apis/system/sys_role/sys_role.go index b8323d1a5..20544c102 100644 --- a/app/admin/apis/system/sys_role/sys_role.go +++ b/app/admin/apis/system/sys_role/sys_role.go @@ -29,10 +29,11 @@ type SysRole struct { // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/v1/role [get] // @Security Bearer -func (e *SysRole) GetSysRoleList(c *gin.Context) { - log := e.GetLogger(c) +func (e SysRole) GetSysRoleList(c *gin.Context) { + e.Context = c + log := e.GetLogger() d := new(dto.SysRoleSearch) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -41,7 +42,7 @@ func (e *SysRole) GetSysRoleList(c *gin.Context) { //查询列表 err = d.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -52,11 +53,11 @@ func (e *SysRole) GetSysRoleList(c *gin.Context) { s.Orm = db err = s.GetSysRolePage(d, &list, &count) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } - e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功") + e.PageOK(list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功") } // @Summary 获取Role数据 @@ -67,10 +68,11 @@ func (e *SysRole) GetSysRoleList(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}" // @Router /api/v1/role/{id} [get] // @Security Bearer -func (e *SysRole) GetSysRole(c *gin.Context) { - log := e.GetLogger(c) +func (e SysRole) GetSysRole(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysRoleById) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -79,7 +81,7 @@ func (e *SysRole) GetSysRole(c *gin.Context) { //查看详情 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } var object system.SysRole @@ -89,11 +91,11 @@ func (e *SysRole) GetSysRole(c *gin.Context) { s.Orm = db err = s.GetSysRole(control, &object) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "查询失败") + e.Error(http.StatusUnprocessableEntity, err, "查询失败") return } - e.OK(c, object, "查看成功") + e.OK(object, "查看成功") } // @Summary 创建角色 @@ -106,10 +108,11 @@ func (e *SysRole) GetSysRole(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/role [post] // @Security Bearer -func (e *SysRole) InsertSysRole(c *gin.Context) { - log := e.GetLogger(c) +func (e SysRole) InsertSysRole(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysRoleControl) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -118,12 +121,12 @@ func (e *SysRole) InsertSysRole(c *gin.Context) { //新增操作 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.Generate() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } // 设置创建人 @@ -138,15 +141,15 @@ func (e *SysRole) InsertSysRole(c *gin.Context) { err = s.InsertSysRole(object) if err != nil { log.Error(err) - e.Error(c, http.StatusInternalServerError, err, "创建失败") + e.Error(http.StatusInternalServerError, err, "创建失败") return } _, err = global.LoadPolicy(c) if err != nil { - e.Error(c, http.StatusInternalServerError, err, "") + e.Error(http.StatusInternalServerError, err, "") return } - e.OK(c, object.GetId(), "创建成功") + e.OK(object.GetId(), "创建成功") } // @Summary 修改用户角色 @@ -159,10 +162,11 @@ func (e *SysRole) InsertSysRole(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "修改失败"}" // @Router /api/v1/role/{id} [put] // @Security Bearer -func (e *SysRole) UpdateSysRole(c *gin.Context) { - log := e.GetLogger(c) +func (e SysRole) UpdateSysRole(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysRoleControl) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -171,12 +175,12 @@ func (e *SysRole) UpdateSysRole(c *gin.Context) { //更新操作 err = control.Bind(c) if err != nil { - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.Generate() if err != nil { - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error(http.StatusInternalServerError, err, "模型生成失败") return } object.UpdateBy = user.GetUserId(c) @@ -191,10 +195,10 @@ func (e *SysRole) UpdateSysRole(c *gin.Context) { } _, err = global.LoadPolicy(c) if err != nil { - e.Error(c, http.StatusInternalServerError, err, "") + e.Error(http.StatusInternalServerError, err, "") return } - e.OK(c, object.GetId(), "更新成功") + e.OK(object.GetId(), "更新成功") } // @Summary 删除用户角色 @@ -205,10 +209,11 @@ func (e *SysRole) UpdateSysRole(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "删除失败"}" // @Router /api/v1/role [delete] // @Security Bearer -func (e *SysRole) DeleteSysRole(c *gin.Context) { - log := e.GetLogger(c) +func (e SysRole) DeleteSysRole(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.SysRoleById) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -218,7 +223,7 @@ func (e *SysRole) DeleteSysRole(c *gin.Context) { err = control.Bind(c) if err != nil { log.Errorf("Bind error: %s", err) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -228,21 +233,22 @@ func (e *SysRole) DeleteSysRole(c *gin.Context) { err = s.RemoveSysRole(control) if err != nil { log.Error(err) - e.Error(c, http.StatusInternalServerError, err, "") + e.Error(http.StatusInternalServerError, err, "") return } _, err = global.LoadPolicy(c) if err != nil { - e.Error(c, http.StatusInternalServerError, err, "") + e.Error(http.StatusInternalServerError, err, "") return } - e.OK(c, control.GetId(), "删除成功") + e.OK(control.GetId(), "删除成功") } -func (e *SysRole) UpdateRoleDataScope(c *gin.Context) { - log := e.GetLogger(c) +func (e SysRole) UpdateRoleDataScope(c *gin.Context) { + e.Context = c + log := e.GetLogger() control := new(dto.RoleDataScopeReq) - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -252,7 +258,7 @@ func (e *SysRole) UpdateRoleDataScope(c *gin.Context) { err = c.Bind(control) if err != nil { log.Errorf("request bind error, %s", err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error(http.StatusUnprocessableEntity, err, "参数验证失败") return } data := &system.SysRole{ @@ -266,8 +272,8 @@ func (e *SysRole) UpdateRoleDataScope(c *gin.Context) { s.Log = log err = s.UpdateDataScope(data) if err != nil { - e.Error(c, http.StatusInternalServerError, err, "") + e.Error(http.StatusInternalServerError, err, "") return } - e.OK(c, nil, "操作成功") + e.OK(nil, "操作成功") } diff --git a/app/admin/apis/tools/dbcolumns.go b/app/admin/apis/tools/dbcolumns.go index caed593f5..aa4ca76e4 100644 --- a/app/admin/apis/tools/dbcolumns.go +++ b/app/admin/apis/tools/dbcolumns.go @@ -19,7 +19,8 @@ import ( // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/v1/db/columns/page [get] func (e *Gen) GetDBColumnList(c *gin.Context) { - log := e.GetLogger(c) + e.Context = c + log := e.GetLogger() var data tools.DBColumns var err error var pageSize = 10 @@ -36,7 +37,7 @@ func (e *Gen) GetDBColumnList(c *gin.Context) { db, err := pkg.GetOrm(c) if err != nil { log.Errorf("get db connection error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败") + e.Error(http.StatusInternalServerError, err, "数据库连接获取失败") return } @@ -45,8 +46,8 @@ func (e *Gen) GetDBColumnList(c *gin.Context) { result, count, err := data.GetPage(db, pageSize, pageIndex) if err != nil { log.Errorf("GetPage error, %s", err.Error()) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } - e.PageOK(c, result, count, pageIndex, pageSize, "查询成功") + e.PageOK(result, count, pageIndex, pageSize, "查询成功") } diff --git a/app/admin/apis/tools/dbtables.go b/app/admin/apis/tools/dbtables.go index eb4abc6e7..12f6ae46a 100644 --- a/app/admin/apis/tools/dbtables.go +++ b/app/admin/apis/tools/dbtables.go @@ -26,11 +26,12 @@ func (e *Gen) GetDBTableList(c *gin.Context) { var err error var pageSize = 10 var pageIndex = 1 - log := e.GetLogger(c) + e.Context = c + log := e.GetLogger() if config.DatabaseConfig.Driver == "sqlite3" || config.DatabaseConfig.Driver == "postgres" { err = errors.New("对不起,sqlite3 或 postgres 不支持代码生成!") log.Warn(err) - e.Error(c, 403, err, "") + e.Error(403, err, "") //c.JSON(http.StatusOK, res.ReturnError(500)) return } @@ -46,7 +47,7 @@ func (e *Gen) GetDBTableList(c *gin.Context) { db, err := pkg.GetOrm(c) if err != nil { log.Errorf("get db connection error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败") + e.Error(http.StatusInternalServerError, err, "数据库连接获取失败") return } @@ -54,8 +55,8 @@ func (e *Gen) GetDBTableList(c *gin.Context) { result, count, err := data.GetPage(db, pageSize, pageIndex) if err != nil { log.Errorf("GetPage error, %s", err.Error()) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } - e.PageOK(c, result, count, pageIndex, pageSize, "查询成功") + e.PageOK(result, count, pageIndex, pageSize, "查询成功") } diff --git a/app/admin/apis/tools/gen.go b/app/admin/apis/tools/gen.go index bc4daedda..44c58bc6e 100644 --- a/app/admin/apis/tools/gen.go +++ b/app/admin/apis/tools/gen.go @@ -22,62 +22,63 @@ type Gen struct { } func (e *Gen) Preview(c *gin.Context) { - log := e.GetLogger(c) + e.Context = c + log := e.GetLogger() table := tools.SysTables{} id, err := pkg.StringToInt(c.Param("tableId")) if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } table.TableId = id t1, err := template.ParseFiles("template/v4/model.go.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } t2, err := template.ParseFiles("template/v4/no_actions/apis.go.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } t3, err := template.ParseFiles("template/v4/js.go.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } t4, err := template.ParseFiles("template/v4/vue.go.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } t5, err := template.ParseFiles("template/v4/no_actions/router_check_role.go.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } t6, err := template.ParseFiles("template/v4/dto.go.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } t7, err := template.ParseFiles("template/v4/no_actions/service.go.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } db, err := pkg.GetOrm(c) if err != nil { log.Errorf("get db connection error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败") + e.Error(http.StatusInternalServerError, err, "数据库连接获取失败") return } @@ -105,23 +106,24 @@ func (e *Gen) Preview(c *gin.Context) { mp["template/router.go.template"] = b5.String() mp["template/dto.go.template"] = b6.String() mp["template/service.go.template"] = b7.String() - e.OK(c, mp, "") + e.OK(mp, "") } func (e *Gen) GenCodeV3(c *gin.Context) { - log := e.GetLogger(c) + e.Context = c + log := e.GetLogger() table := tools.SysTables{} id, err := pkg.StringToInt(c.Param("tableId")) if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } db, err := pkg.GetOrm(c) if err != nil { log.Errorf("get db connection error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败") + e.Error(http.StatusInternalServerError, err, "数据库连接获取失败") return } @@ -134,23 +136,24 @@ func (e *Gen) GenCodeV3(c *gin.Context) { e.NOActionsGenV3(c, tab) } - e.OK(c, "", "Code generated successfully!") + e.OK("", "Code generated successfully!") } func (e *Gen) GenApiToFile(c *gin.Context) { - log := e.GetLogger(c) + e.Context = c + log := e.GetLogger() table := tools.SysTables{} id, err := pkg.StringToInt(c.Param("tableId")) if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } db, err := pkg.GetOrm(c) if err != nil { log.Errorf("get db connection error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败") + e.Error(http.StatusInternalServerError, err, "数据库连接获取失败") return } @@ -158,11 +161,12 @@ func (e *Gen) GenApiToFile(c *gin.Context) { tab, _ := table.Get(db) e.genApiToFile(c, tab) - e.OK(c, "", "Code generated successfully!") + e.OK("", "Code generated successfully!") } func (e *Gen) NOActionsGenV3(c *gin.Context, tab tools.SysTables) { - log := e.GetLogger(c) + e.Context = c + log := e.GetLogger() basePath := "template/v4/" routerFile := basePath + "no_actions/router_check_role.go.template" @@ -174,43 +178,43 @@ func (e *Gen) NOActionsGenV3(c *gin.Context, tab tools.SysTables) { t1, err := template.ParseFiles(basePath + "model.go.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } t2, err := template.ParseFiles(basePath + "no_actions/apis.go.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } t3, err := template.ParseFiles(routerFile) if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } t4, err := template.ParseFiles(basePath + "js.go.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } t5, err := template.ParseFiles(basePath + "vue.go.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } t6, err := template.ParseFiles(basePath + "dto.go.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } t7, err := template.ParseFiles(basePath + "no_actions/service.go.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } @@ -246,14 +250,15 @@ func (e *Gen) NOActionsGenV3(c *gin.Context, tab tools.SysTables) { } func (e *Gen) genApiToFile(c *gin.Context, tab tools.SysTables) { - log := e.GetLogger(c) + e.Context = c + log := e.GetLogger() basePath := "template/" t1, err := template.ParseFiles(basePath + "api_migrate.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } i := strconv.FormatInt(time.Now().UnixNano()/1e6, 10) @@ -279,31 +284,31 @@ func (e *Gen) ActionsGenV3(c *gin.Context, tab tools.SysTables) { t1, err := template.ParseFiles(basePath + "model.go.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } t3, err := template.ParseFiles(routerFile) if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } t4, err := template.ParseFiles(basePath + "js.go.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } t5, err := template.ParseFiles(basePath + "vue.go.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } t6, err := template.ParseFiles(basePath + "dto.go.template") if err != nil { log.Error(err) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } @@ -342,7 +347,7 @@ func (e *Gen) GenMenuAndApi(c *gin.Context) { db, err := pkg.GetOrm(c) if err != nil { log.Errorf("get db connection error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败") + e.Error(http.StatusInternalServerError, err, "数据库连接获取失败") return } @@ -572,5 +577,5 @@ func (e *Gen) GenMenuAndApi(c *gin.Context) { ADelete.UpdatedAt = timeNow ADelete.MenuId, err = ADelete.Create(db) - e.OK(c, "", "数据生成成功!") + e.OK("", "数据生成成功!") } diff --git a/app/admin/apis/tools/systables.go b/app/admin/apis/tools/systables.go index 8b01bdf79..9e95d83ec 100644 --- a/app/admin/apis/tools/systables.go +++ b/app/admin/apis/tools/systables.go @@ -27,7 +27,8 @@ type SysTable struct { // @Success 200 {object} response.Response "{"code": 200, "data": [...]}" // @Router /api/v1/sys/tables/page [get] func (e *SysTable) GetSysTableList(c *gin.Context) { - log := e.GetLogger(c) + e.Context = c + log := e.GetLogger() var data tools.SysTables var err error var pageSize = 10 @@ -41,10 +42,10 @@ func (e *SysTable) GetSysTableList(c *gin.Context) { pageIndex, err = pkg.StringToInt(index) } - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Errorf("get db connection error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败") + e.Error(http.StatusInternalServerError, err, "数据库连接获取失败") return } @@ -53,10 +54,10 @@ func (e *SysTable) GetSysTableList(c *gin.Context) { result, count, err := data.GetPage(db, pageSize, pageIndex) if err != nil { log.Errorf("GetPage error, %s", err.Error()) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } - e.PageOK(c, result, count, pageIndex, pageSize, "查询成功") + e.PageOK(result, count, pageIndex, pageSize, "查询成功") } // @Summary 获取配置 @@ -67,11 +68,12 @@ func (e *SysTable) GetSysTableList(c *gin.Context) { // @Router /api/v1/sys/tables/info/{tableId} [get] // @Security Bearer func (e *SysTable) GetSysTables(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Errorf("get db connection error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败") + e.Error(http.StatusInternalServerError, err, "数据库连接获取失败") return } @@ -80,22 +82,23 @@ func (e *SysTable) GetSysTables(c *gin.Context) { result, err := data.Get(db) if err != nil { log.Errorf("Get error, %s", err.Error()) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } mp := make(map[string]interface{}) mp["list"] = result.Columns mp["info"] = result - e.OK(c, mp, "") + e.OK(mp, "") } func (e *SysTable) GetSysTablesInfo(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Errorf("get db connection error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败") + e.Error(http.StatusInternalServerError, err, "数据库连接获取失败") return } @@ -106,24 +109,25 @@ func (e *SysTable) GetSysTablesInfo(c *gin.Context) { result, err := data.Get(db) if err != nil { log.Errorf("Get error, %s", err.Error()) - e.Error(c, 500, err, "抱歉未找到相关信息") + e.Error(500, err, "抱歉未找到相关信息") return } mp := make(map[string]interface{}) mp["list"] = result.Columns mp["info"] = result - e.OK(c, mp, "") + e.OK(mp, "") //res.Data = mp //c.JSON(http.StatusOK, res.ReturnOK()) } func (e *SysTable) GetSysTablesTree(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Errorf("get db connection error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败") + e.Error(http.StatusInternalServerError, err, "数据库连接获取失败") return } @@ -131,11 +135,11 @@ func (e *SysTable) GetSysTablesTree(c *gin.Context) { result, err := data.GetTree(db) if err != nil { log.Errorf("GetTree error, %s", err.Error()) - e.Error(c, 500, err, "抱歉未找到相关信息") + e.Error(500, err, "抱歉未找到相关信息") return } - e.OK(c, result, "") + e.OK(result, "") } // @Summary 添加表结构 @@ -149,11 +153,12 @@ func (e *SysTable) GetSysTablesTree(c *gin.Context) { // @Router /api/v1/sys/tables/info [post] // @Security Bearer func (e *SysTable) InsertSysTable(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Errorf("get db connection error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败") + e.Error(http.StatusInternalServerError, err, "数据库连接获取失败") return } @@ -163,18 +168,18 @@ func (e *SysTable) InsertSysTable(c *gin.Context) { data, err := genTableInit(db, tablesList, i, c) if err != nil { log.Errorf("genTableInit error, %s", err.Error()) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } _, err = data.Create(db) if err != nil { log.Errorf("Create error, %s", err.Error()) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } } - e.OK(c, nil, "添加成功") + e.OK(nil, "添加成功") } @@ -296,11 +301,12 @@ func (e *SysTable) UpdateSysTable(c *gin.Context) { err := c.Bind(&data) pkg.HasError(err, "数据解析失败", 500) - log := e.GetLogger(c) - db, err := e.GetOrm(c) + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Errorf("get db connection error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败") + e.Error(http.StatusInternalServerError, err, "数据库连接获取失败") return } @@ -308,10 +314,10 @@ func (e *SysTable) UpdateSysTable(c *gin.Context) { result, err := data.Update(db) if err != nil { log.Errorf("Update error, %s", err.Error()) - e.Error(c, 500, err, "") + e.Error(500, err, "") return } - e.OK(c, result, "修改成功") + e.OK(result, "修改成功") } // @Summary 删除表结构 @@ -322,11 +328,12 @@ func (e *SysTable) UpdateSysTable(c *gin.Context) { // @Success 200 {string} string "{"code": -1, "message": "删除失败"}" // @Router /api/v1/sys/tables/info/{tableId} [delete] func (e *SysTable) DeleteSysTables(c *gin.Context) { - log := e.GetLogger(c) - db, err := e.GetOrm(c) + e.Context = c + log := e.GetLogger() + db, err := e.GetOrm() if err != nil { log.Errorf("get db connection error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败") + e.Error(http.StatusInternalServerError, err, "数据库连接获取失败") return } @@ -335,8 +342,8 @@ func (e *SysTable) DeleteSysTables(c *gin.Context) { _, err = data.BatchDelete(db, IDS) if err != nil { log.Errorf("BatchDelete error, %s", err.Error()) - e.Error(c, 500, err, "删除失败") + e.Error(500, err, "删除失败") return } - e.OK(c, nil, "删除成功") + e.OK(nil, "删除成功") } diff --git a/app/admin/router/sys_config.go b/app/admin/router/sys_config.go index b10ee60d0..9b90da77e 100644 --- a/app/admin/router/sys_config.go +++ b/app/admin/router/sys_config.go @@ -13,7 +13,7 @@ func init() { // 需认证的路由代码 func registerSysConfigRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { - api := &sys_config.SysConfig{} + api := sys_config.SysConfig{} r := v1.Group("/config").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole()) { diff --git a/app/admin/router/sys_dept.go b/app/admin/router/sys_dept.go index bc9ef1e57..7ce7eddb9 100644 --- a/app/admin/router/sys_dept.go +++ b/app/admin/router/sys_dept.go @@ -13,7 +13,7 @@ func init() { // 需认证的路由代码 func registerSysDeptRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { - api := &sys_dept.SysDept{} + api := sys_dept.SysDept{} r := v1.Group("/dept").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole()) { r.GET("", api.GetSysDeptList) diff --git a/app/admin/router/sys_file_dir.go b/app/admin/router/sys_file_dir.go index 74adf1645..d2d471932 100644 --- a/app/admin/router/sys_file_dir.go +++ b/app/admin/router/sys_file_dir.go @@ -13,7 +13,7 @@ func init() { // 需认证的路由代码 func registerSysFileDirRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { - api := &sys_file.SysFileDir{} + api := sys_file.SysFileDir{} r := v1.Group("/sysfiledir").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole()) { r.GET("", api.GetSysFileDirList) diff --git a/app/admin/router/sys_file_info.go b/app/admin/router/sys_file_info.go index f4e0f2fc4..5cd1d4583 100644 --- a/app/admin/router/sys_file_info.go +++ b/app/admin/router/sys_file_info.go @@ -13,7 +13,7 @@ func init() { // 需认证的路由代码 func registerSysFileInfoRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { - api := &sys_file.SysFileInfo{} + api := sys_file.SysFileInfo{} r := v1.Group("/sysfileinfo").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole()) { r.GET("", api.GetSysFileInfoList) diff --git a/app/admin/router/sys_job.go b/app/admin/router/sys_job.go index 81c571b7e..a6985b8cf 100644 --- a/app/admin/router/sys_job.go +++ b/app/admin/router/sys_job.go @@ -31,7 +31,7 @@ func registerSysJobRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlew r.PUT("", actions.PermissionAction(), actions.UpdateAction(new(dto.SysJobControl))) r.DELETE("", actions.PermissionAction(), actions.DeleteAction(new(dto.SysJobById))) } - sysJob := &sys_job.SysJob{} + sysJob := sys_job.SysJob{} v1.GET("/job/remove/:id", sysJob.RemoveJobForService) v1.GET("/job/start/:id", sysJob.StartJobForService) diff --git a/app/admin/router/sys_login_log.go b/app/admin/router/sys_login_log.go index 91458e0ff..b813357aa 100644 --- a/app/admin/router/sys_login_log.go +++ b/app/admin/router/sys_login_log.go @@ -13,7 +13,7 @@ func init() { // 需认证的路由代码 func registerSysLoginLogRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { - api := &sys_login_log.SysLoginLog{} + api := sys_login_log.SysLoginLog{} r := v1.Group("/sys-login-log").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole()) { r.GET("", api.GetSysLoginLogList) diff --git a/app/admin/router/sys_menu.go b/app/admin/router/sys_menu.go index 6a8148d1b..8d7b300a8 100644 --- a/app/admin/router/sys_menu.go +++ b/app/admin/router/sys_menu.go @@ -13,7 +13,7 @@ func init() { // 需认证的路由代码 func registerSysMenuRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { - api := &sys_menu.SysMenu{} + api := sys_menu.SysMenu{} //menu := v1.Group("/menu").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole()) //{ // menu.GET("/:id", system.GetMenu) diff --git a/app/admin/router/sys_opera_log.go b/app/admin/router/sys_opera_log.go index 2e348728d..37e0db536 100644 --- a/app/admin/router/sys_opera_log.go +++ b/app/admin/router/sys_opera_log.go @@ -13,7 +13,7 @@ func init() { // 需认证的路由代码 func registerSysOperaLogRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { - api := &sys_opera_log.SysOperaLog{} + api := sys_opera_log.SysOperaLog{} r := v1.Group("/sys-opera-log").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole()) { r.GET("", api.GetSysOperaLogList) diff --git a/app/admin/router/sys_post.go b/app/admin/router/sys_post.go index af38a5bd3..a77f8616f 100644 --- a/app/admin/router/sys_post.go +++ b/app/admin/router/sys_post.go @@ -13,7 +13,7 @@ func init() { // 需认证的路由代码 func registerSyPostRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { - api := &sys_post.SysPost{} + api := sys_post.SysPost{} r := v1.Group("/post").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole()) { r.GET("", api.GetSysPostList) diff --git a/app/admin/router/sys_role.go b/app/admin/router/sys_role.go index 4d52c099e..9ad9efa16 100644 --- a/app/admin/router/sys_role.go +++ b/app/admin/router/sys_role.go @@ -13,7 +13,7 @@ func init() { // 需认证的路由代码 func registerSysRoleRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { - api := &sys_role.SysRole{} + api := sys_role.SysRole{} r := v1.Group("/role").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole()) { r.GET("", api.GetSysRoleList) diff --git a/app/admin/router/sys_router.go b/app/admin/router/sys_router.go index 4ad6a14b5..b059f7f04 100644 --- a/app/admin/router/sys_router.go +++ b/app/admin/router/sys_router.go @@ -58,17 +58,17 @@ func sysSwaggerRouter(r *gin.RouterGroup) { func sysNoCheckRoleRouter(r *gin.RouterGroup) { v1 := r.Group("/api/v1") - m := &monitor.Monitor{} + m := monitor.Monitor{} v1.GET("/monitor/server", m.ServerInfo) - sys := &system.System{} + sys := system.System{} v1.GET("/getCaptcha", sys.GenerateCaptchaHandler) - gen := &tools.Gen{} + gen := tools.Gen{} v1.GET("/gen/preview/:tableId", gen.Preview) v1.GET("/gen/toproject/:tableId", gen.GenCodeV3) v1.GET("/gen/apitofile/:tableId", gen.GenApiToFile) v1.GET("/gen/todb/:tableId", gen.GenMenuAndApi) - sysTable := &tools.SysTable{} + sysTable := tools.SysTable{} v1.GET("/gen/tabletree", sysTable.GetSysTablesTree) registerDBRouter(v1) @@ -80,7 +80,7 @@ func sysNoCheckRoleRouter(r *gin.RouterGroup) { func registerDBRouter(api *gin.RouterGroup) { db := api.Group("/db") { - gen := &tools.Gen{} + gen := tools.Gen{} db.GET("/tables/page", gen.GetDBTableList) db.GET("/columns/page", gen.GetDBColumnList) } @@ -89,7 +89,7 @@ func registerDBRouter(api *gin.RouterGroup) { func registerSysTableRouter(v1 *gin.RouterGroup) { systables := v1.Group("/sys/tables") { - sysTable := &tools.SysTable{} + sysTable := tools.SysTable{} systables.GET("/page", sysTable.GetSysTableList) tablesinfo := systables.Group("/info") { @@ -169,8 +169,8 @@ func registerBaseRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlewar //} func registerDictRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { - dictApi := &dict.SysDictType{} - dataApi := &dict.SysDictData{} + dictApi := dict.SysDictType{} + dataApi := dict.SysDictData{} dicts := v1.Group("/dict").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole()) { @@ -201,7 +201,7 @@ func registerDictRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlewar //} func registerSysSettingRouter(v1 *gin.RouterGroup) { api := system.SysSetting{} - m := &monitor.Monitor{} + m := monitor.Monitor{} setting := v1.Group("/setting") { setting.GET("", api.GetSetting) @@ -213,7 +213,7 @@ func registerSysSettingRouter(v1 *gin.RouterGroup) { func registerPublicRouter(v1 *gin.RouterGroup) { p := v1.Group("/public") { - file := &public.File{} + file := public.File{} p.POST("/uploadFile", file.UploadFile) } } diff --git a/app/admin/router/sys_user.go b/app/admin/router/sys_user.go index 1b0e83a39..59e4a67e2 100644 --- a/app/admin/router/sys_user.go +++ b/app/admin/router/sys_user.go @@ -14,7 +14,7 @@ func init() { // 需认证的路由代码 func registerSysUserRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { - api := &sys_user.SysUser{} + api := sys_user.SysUser{} r := v1.Group("/sysUser").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole()).Use(actions.PermissionAction()) { r.GET("", api.GetSysUserList) diff --git a/app/admin/router/syschinaareadata.go b/app/admin/router/syschinaareadata.go index 6f47b8998..0dca1098c 100644 --- a/app/admin/router/syschinaareadata.go +++ b/app/admin/router/syschinaareadata.go @@ -13,7 +13,7 @@ func init() { // 需认证的路由代码 func registerSysChinaAreaDataRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { - api := &sys_china_area_data.SysChinaAreaData{} + api := sys_china_area_data.SysChinaAreaData{} r := v1.Group("/sys_china_area_data").Use(authMiddleware.MiddlewareFunc()).Use(middleware2.AuthCheckRole()) { r.GET("", api.GetSysChinaAreaDataList) diff --git a/cmd/api/server.go b/cmd/api/server.go index 0592919dc..48b13d675 100644 --- a/cmd/api/server.go +++ b/cmd/api/server.go @@ -76,18 +76,22 @@ func setup() { captcha.SetStore(captcha.NewCacheStore(cacheAdapter, 600)) //6. 设置队列 - queueAdapter, err := config.QueueConfig.Setup() - if err != nil { - log.Fatalf("queue setup error, %s\n", err.Error()) + if !config.QueueConfig.Empty() { + queueAdapter, err := config.QueueConfig.Setup() + if err != nil { + log.Fatalf("queue setup error, %s\n", err.Error()) + } + sdk.Runtime.SetQueueAdapter(queueAdapter) } - sdk.Runtime.SetQueueAdapter(queueAdapter) //7. 设置分布式锁 - lockerAdapter, err := config.LockerConfig.Setup() - if err != nil { - log.Fatalf("locker setup error, %s\n", err.Error()) + if !config.LockerConfig.Empty() { + lockerAdapter, err := config.LockerConfig.Setup() + if err != nil { + log.Fatalf("locker setup error, %s\n", err.Error()) + } + sdk.Runtime.SetLockerAdapter(lockerAdapter) } - sdk.Runtime.SetLockerAdapter(lockerAdapter) usageStr := `starting api server...` log.Println(usageStr) diff --git a/common/apis/api.go b/common/apis/api.go index 11e73195f..3c14fb739 100644 --- a/common/apis/api.go +++ b/common/apis/api.go @@ -12,39 +12,40 @@ import ( ) type Api struct { + Context *gin.Context } // GetLogger 获取上下文提供的日志 -func (e *Api) GetLogger(c *gin.Context) *logger.Logger { - return api.GetRequestLogger(c) +func (e Api) GetLogger() *logger.Logger { + return api.GetRequestLogger(e.Context) } // GetOrm 获取Orm DB -func (e *Api) GetOrm(c *gin.Context) (*gorm.DB, error) { - db, err := pkg.GetOrm(c) +func (e Api) GetOrm() (*gorm.DB, error) { + db, err := pkg.GetOrm(e.Context) if err != nil { - e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败") + e.Error(http.StatusInternalServerError, err, "数据库连接获取失败") return nil, err } return db, nil } // Error 通常错误数据处理 -func (e *Api) Error(c *gin.Context, code int, err error, msg string) { - response.Error(c, code, err, msg) +func (e Api) Error(code int, err error, msg string) { + response.Error(e.Context, code, err, msg) } // OK 通常成功数据处理 -func (e *Api) OK(c *gin.Context, data interface{}, msg string) { - response.OK(c, data, msg) +func (e Api) OK(data interface{}, msg string) { + response.OK(e.Context, data, msg) } // PageOK 分页数据处理 -func (e *Api) PageOK(c *gin.Context, result interface{}, count int, pageIndex int, pageSize int, msg string) { - response.PageOK(c, result, count, pageIndex, pageSize, msg) +func (e Api) PageOK(result interface{}, count int, pageIndex int, pageSize int, msg string) { + response.PageOK(e.Context, result, count, pageIndex, pageSize, msg) } // Custom 兼容函数 -func (e *Api) Custom(c *gin.Context, data gin.H) { - response.Custum(c, data) +func (e Api) Custom(data gin.H) { + response.Custum(e.Context, data) } diff --git a/go.mod b/go.mod index 84e3addbc..2adfaa40d 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/casbin/casbin/v2 v2.25.1 github.com/gin-gonic/gin v1.6.3 github.com/go-admin-team/go-admin-core v1.3.5-rc.0 - github.com/go-admin-team/go-admin-core/sdk v1.3.5-rc.0 + github.com/go-admin-team/go-admin-core/sdk v1.3.0-rc.3.0.20210427015751-b42693c49c6c github.com/google/uuid v1.2.0 github.com/mssola/user_agent v0.5.2 github.com/opentracing/opentracing-go v1.1.0 From 009866ee31e5256e9d315deb932c3958944bb284 Mon Sep 17 00:00:00 2001 From: wenjianzhang Date: Fri, 7 May 2021 17:56:15 +0800 Subject: [PATCH 04/11] =?UTF-8?q?feat=E2=9C=A8=20=EF=BC=9A=E6=9B=B4?= =?UTF-8?q?=E6=96=B0api=E5=86=99=E6=B3=95=EF=BC=8C=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=A8=A1=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sys_china_area_data.go | 12 ++++---- app/admin/apis/sys_file/sys_file_dir.go | 8 ++--- common/apis/api.go | 27 +++++++++++++++-- common/apis/request_logger.go | 22 +++++--------- go.mod | 2 +- template/v4/dto.go.template | 17 ++--------- template/v4/no_actions/apis.go.template | 29 +++++++++++-------- 7 files changed, 62 insertions(+), 55 deletions(-) diff --git a/app/admin/apis/sys_china_area_data/sys_china_area_data.go b/app/admin/apis/sys_china_area_data/sys_china_area_data.go index 80599aa40..bdf829823 100644 --- a/app/admin/apis/sys_china_area_data/sys_china_area_data.go +++ b/app/admin/apis/sys_china_area_data/sys_china_area_data.go @@ -18,7 +18,7 @@ type SysChinaAreaData struct { } func (e SysChinaAreaData) GetSysChinaAreaDataList(c *gin.Context) { - e.Context = c + e.SetContext(c) log := e.GetLogger() d := new(dto.SysChinaAreaDataSearch) db, err := e.GetOrm() @@ -52,7 +52,7 @@ func (e SysChinaAreaData) GetSysChinaAreaDataList(c *gin.Context) { } func (e SysChinaAreaData) GetSysChinaAreaData(c *gin.Context) { - e.Context = c + e.SetContext(c) log := e.GetLogger() control := new(dto.SysChinaAreaDataById) db, err := e.GetOrm() @@ -85,7 +85,7 @@ func (e SysChinaAreaData) GetSysChinaAreaData(c *gin.Context) { } func (e SysChinaAreaData) InsertSysChinaAreaData(c *gin.Context) { - e.Context = c + e.SetContext(c) log := e.GetLogger() control := new(dto.SysChinaAreaDataControl) db, err := e.GetOrm() @@ -122,7 +122,7 @@ func (e SysChinaAreaData) InsertSysChinaAreaData(c *gin.Context) { } func (e SysChinaAreaData) UpdateSysChinaAreaData(c *gin.Context) { - e.Context = c + e.SetContext(c) log := e.GetLogger() control := new(dto.SysChinaAreaDataControl) db, err := e.GetOrm() @@ -159,7 +159,7 @@ func (e SysChinaAreaData) UpdateSysChinaAreaData(c *gin.Context) { } func (e SysChinaAreaData) DeleteSysChinaAreaData(c *gin.Context) { - e.Context = c + e.SetContext(c) log := e.GetLogger() control := new(dto.SysChinaAreaDataById) db, err := e.GetOrm() @@ -192,4 +192,4 @@ func (e SysChinaAreaData) DeleteSysChinaAreaData(c *gin.Context) { return } e.OK(control.GetId(), "删除成功") -} +} \ No newline at end of file diff --git a/app/admin/apis/sys_file/sys_file_dir.go b/app/admin/apis/sys_file/sys_file_dir.go index d275638cc..8d8f349ab 100644 --- a/app/admin/apis/sys_file/sys_file_dir.go +++ b/app/admin/apis/sys_file/sys_file_dir.go @@ -19,7 +19,7 @@ type SysFileDir struct { } func (e SysFileDir) GetSysFileDirList(c *gin.Context) { - e.Context = c + e.SetContext(c) log := e.GetLogger() search := new(dto.SysFileDirSearch) db, err := e.GetOrm() @@ -49,7 +49,7 @@ func (e SysFileDir) GetSysFileDirList(c *gin.Context) { func (e SysFileDir) GetSysFileDir(c *gin.Context) { control := new(dto.SysFileDirById) - e.Context = c + e.SetContext(c) log := e.GetLogger() db, err := e.GetOrm() if err != nil { @@ -81,7 +81,7 @@ func (e SysFileDir) GetSysFileDir(c *gin.Context) { func (e SysFileDir) InsertSysFileDir(c *gin.Context) { control := new(dto.SysFileDirControl) - e.Context = c + e.SetContext(c) log := e.GetLogger() db, err := e.GetOrm() if err != nil { @@ -195,4 +195,4 @@ func (e SysFileDir) DeleteSysFileDir(c *gin.Context) { return } e.OK(control.Id, "删除成功") -} +} \ No newline at end of file diff --git a/common/apis/api.go b/common/apis/api.go index 3c14fb739..c85ef686a 100644 --- a/common/apis/api.go +++ b/common/apis/api.go @@ -1,6 +1,7 @@ package apis import ( + "github.com/gin-gonic/gin/binding" "net/http" "github.com/gin-gonic/gin" @@ -13,11 +14,33 @@ import ( type Api struct { Context *gin.Context + Logger *logger.Logger +} + +func (e Api) SetContext(c *gin.Context) { + e.Context = c + e.Logger = api.GetRequestLogger(c) } // GetLogger 获取上下文提供的日志 func (e Api) GetLogger() *logger.Logger { - return api.GetRequestLogger(e.Context) + return e.Logger +} + +func (e Api) Bind(d interface{}, bindings ...binding.Binding) error { + var err error + for i := range bindings { + switch bindings[i] { + case binding.JSON: + err = e.Context.ShouldBindWith(d, binding.JSON) + default: + err = e.Context.ShouldBindUri(d) + } + if err != nil { + return err + } + } + return nil } // GetOrm 获取Orm DB @@ -48,4 +71,4 @@ func (e Api) PageOK(result interface{}, count int, pageIndex int, pageSize int, // Custom 兼容函数 func (e Api) Custom(data gin.H) { response.Custum(e.Context, data) -} +} \ No newline at end of file diff --git a/common/apis/request_logger.go b/common/apis/request_logger.go index 71f7a7ef3..d3df51c46 100644 --- a/common/apis/request_logger.go +++ b/common/apis/request_logger.go @@ -1,18 +1,10 @@ package apis -import ( - "github.com/gin-gonic/gin" - "github.com/go-admin-team/go-admin-core/sdk" - "github.com/go-admin-team/go-admin-core/sdk/pkg" - "github.com/go-admin-team/go-admin-core/sdk/pkg/logger" - "strings" -) - // GetRequestLogger 获取上下文提供的日志 -func GetRequestLogger(c *gin.Context) *logger.Logger { - requestId := pkg.GenerateMsgIDFromContext(c) - log := sdk.Runtime.GetLogger().Fields(map[string]interface{}{ - strings.ToLower(pkg.TrafficKey): requestId, - }) - return &logger.Logger{Logger: log} -} +//func GetRequestLogger(c *gin.Context) *logger.Logger { +// requestId := pkg.GenerateMsgIDFromContext(c) +// log := sdk.Runtime.GetLogger().Fields(map[string]interface{}{ +// strings.ToLower(pkg.TrafficKey): requestId, +// }) +// return &logger.Logger{Logger: log} +//} \ No newline at end of file diff --git a/go.mod b/go.mod index 2adfaa40d..d1c744e1d 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/bytedance/go-tagexpr/v2 v2.7.10 github.com/casbin/casbin/v2 v2.25.1 github.com/gin-gonic/gin v1.6.3 - github.com/go-admin-team/go-admin-core v1.3.5-rc.0 + github.com/go-admin-team/go-admin-core v1.3.5-rc.0.0.20210423072631-e3580b68ee26 github.com/go-admin-team/go-admin-core/sdk v1.3.0-rc.3.0.20210427015751-b42693c49c6c github.com/google/uuid v1.2.0 github.com/mssola/user_agent v0.5.2 diff --git a/template/v4/dto.go.template b/template/v4/dto.go.template index 5b9ce2084..d53c432a4 100644 --- a/template/v4/dto.go.template +++ b/template/v4/dto.go.template @@ -2,7 +2,6 @@ package dto import ( "errors" - vd "github.com/bytedance/go-tagexpr/v2/validator" "github.com/gin-gonic/gin" "github.com/go-admin-team/go-admin-core/sdk/api" @@ -12,12 +11,12 @@ import ( ) type {{.ClassName}}Search struct { - dto.Pagination `search:"-" vd:"-"` + dto.Pagination `search:"-"` {{ $tablename := .TBName -}} {{ range .Columns -}} {{$z := .IsQuery}} {{- if ($z) -}} - {{.GoField}} {{.GoType}} `form:"{{.JsonField}}" vd:"?" search:"type:{{if eq .QueryType "EQ"}}exact{{ else if eq .QueryType "NE"}}iexact{{ else if eq .QueryType "LIKE"}}contains{{ else if eq .QueryType "GT"}}gt{{ else if eq .QueryType "GTE"}}gte{{ else if eq .QueryType "LT"}}lt{{ else if eq .QueryType "LTE"}}lte{{- end }};column:{{.ColumnName}};table:{{$tablename}}" comment:"{{.ColumnComment}}"` + {{.GoField}} {{.GoType}} `form:"{{.JsonField}}" search:"type:{{if eq .QueryType "EQ"}}exact{{ else if eq .QueryType "NE"}}iexact{{ else if eq .QueryType "LIKE"}}contains{{ else if eq .QueryType "GT"}}gt{{ else if eq .QueryType "GTE"}}gte{{ else if eq .QueryType "LT"}}lt{{ else if eq .QueryType "LTE"}}lte{{- end }};column:{{.ColumnName}};table:{{$tablename}}" comment:"{{.ColumnComment}}"` {{ end -}} {{- end }} } @@ -37,10 +36,6 @@ func (m *{{.ClassName}}Search) Bind(ctx *gin.Context) error { if err != nil { log.Errorf("ShouldBind error: %s", err.Error()) } - if err1 := vd.Validate(s); err != nil { - log.Errorf("Validate error: %s", err1.Error()) - return err1 - } return err } @@ -77,10 +72,6 @@ func (s *{{.ClassName}}Control) Bind(ctx *gin.Context) error { log.Errorf("ShouldBind error: %s", err.Error()) err = errors.New("数据绑定出错") } - if err1 := vd.Validate(s); err != nil { - log.Errorf("Validate error: %s", err1.Error()) - return err1 - } return err } @@ -130,10 +121,6 @@ func (s *{{.ClassName}}ById) Bind(ctx *gin.Context) error { log.Errorf("ShouldBind error: %s", err.Error()) err = errors.New("数据绑定出错") } - if err1 := vd.Validate(s); err != nil { - log.Errorf("Validate error: %s", err1.Error()) - return err1 - } return err } diff --git a/template/v4/no_actions/apis.go.template b/template/v4/no_actions/apis.go.template index 4af74e228..7c0255238 100644 --- a/template/v4/no_actions/apis.go.template +++ b/template/v4/no_actions/apis.go.template @@ -31,8 +31,9 @@ type {{.ClassName}} struct { // @Router /api/v1/{{.ModuleName}} [get] // @Security Bearer // Get{{.ClassName}}List 获取{{.TableComment}}列表 -func (e *{{.ClassName}}) Get{{.ClassName}}List(c *gin.Context) { - log := e.GetLogger(c) +func (e {{.ClassName}}) Get{{.ClassName}}List(c *gin.Context) { + e.SetContext(c) + log := e.GetLogger() db, err := e.GetOrm(c) if err != nil { log.Error(err) @@ -74,8 +75,9 @@ func (e *{{.ClassName}}) Get{{.ClassName}}List(c *gin.Context) { // @Router /api/v1/{{.ModuleName}}/{id} [get] // @Security Bearer // Get{{.ClassName}} 获取{{.TableComment}} -func (e *{{.ClassName}}) Get{{.ClassName}}(c *gin.Context) { - log := e.GetLogger(c) +func (e {{.ClassName}}) Get{{.ClassName}}(c *gin.Context) { + e.SetContext(c) + log := e.GetLogger() db, err := e.GetOrm(c) if err != nil { log.Error(err) @@ -118,8 +120,9 @@ func (e *{{.ClassName}}) Get{{.ClassName}}(c *gin.Context) { // @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}" // @Router /api/v1/{{.ModuleName}} [post] // Insert{{.ClassName}} 创建{{.TableComment}} -func (e *{{.ClassName}}) Insert{{.ClassName}}(c *gin.Context) { - log := e.GetLogger(c) +func (e {{.ClassName}}) Insert{{.ClassName}}(c *gin.Context) { + e.SetContext(c) + log := e.GetLogger() db, err := e.GetOrm(c) if err != nil { log.Error(err) @@ -164,10 +167,11 @@ func (e *{{.ClassName}}) Insert{{.ClassName}}(c *gin.Context) { // @Product application/json // @Param data body dto.{{.ClassName}}Control true "body" // @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}" -// @Router /api/v1/{{.ModuleName}} [put] +// @Router /api/v1/{{.ModuleName}}/{id} [put] // Update{{.ClassName}} 修改{{.TableComment}} -func (e *{{.ClassName}}) Update{{.ClassName}}(c *gin.Context) { - log := e.GetLogger(c) +func (e {{.ClassName}}) Update{{.ClassName}}(c *gin.Context) { + e.SetContext(c) + log := e.GetLogger() db, err := e.GetOrm(c) if err != nil { log.Error(err) @@ -213,8 +217,9 @@ func (e *{{.ClassName}}) Update{{.ClassName}}(c *gin.Context) { // @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}" // @Router /api/v1/{{.ModuleName}} [delete] // Delete{{.ClassName}} 删除{{.TableComment}} -func (e *{{.ClassName}}) Delete{{.ClassName}}(c *gin.Context) { - log := e.GetLogger(c) +func (e {{.ClassName}}) Delete{{.ClassName}}(c *gin.Context) { + e.SetContext(c) + log := e.GetLogger() db, err := e.GetOrm(c) if err != nil { log.Error(err) @@ -247,4 +252,4 @@ func (e *{{.ClassName}}) Delete{{.ClassName}}(c *gin.Context) { return } e.OK(c, control.GetId(), "删除成功") -} +} \ No newline at end of file From e219463505ef82d41f8b6a2bb8ec2666ab1e87ad Mon Sep 17 00:00:00 2001 From: wenjianzhang Date: Fri, 7 May 2021 18:46:12 +0800 Subject: [PATCH 05/11] =?UTF-8?q?feat=E2=9C=A8=20=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E6=A8=A1=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/v4/no_actions/apis.go.template | 66 ++++++++++++++----------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/template/v4/no_actions/apis.go.template b/template/v4/no_actions/apis.go.template index 7c0255238..a79630601 100644 --- a/template/v4/no_actions/apis.go.template +++ b/template/v4/no_actions/apis.go.template @@ -18,23 +18,26 @@ type {{.ClassName}} struct { apis.Api } +// Get{{.ClassName}}List 获取{{.TableComment}}列表 // @Summary 获取{{.TableComment}}列表 // @Description 获取{{.TableComment}}列表 // @Tags {{.TableComment}} -{{ $tablename := .TBName -}} -{{ range .Columns -}} +{{- $tablename := .TBName -}} +{{- range .Columns -}} {{$z := .IsQuery}} -{{- if ($z) -}}// @Param {{.JsonField}} query {{.GoType}} false "{{.ColumnComment}}"{{ end -}}{{- end }} +{{- if ($z) }} +// @Param {{.JsonField}} query {{.GoType}} false "{{.ColumnComment}}" +{{- end -}} +{{- end }} // @Param pageSize query int false "页条数" // @Param pageIndex query int false "页码" // @Success 200 {object} response.Response{data=response.Page{list=[]models.{{.ClassName}}}} "{"code": 200, "data": [...]}" // @Router /api/v1/{{.ModuleName}} [get] // @Security Bearer -// Get{{.ClassName}}List 获取{{.TableComment}}列表 func (e {{.ClassName}}) Get{{.ClassName}}List(c *gin.Context) { e.SetContext(c) log := e.GetLogger() - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -45,7 +48,7 @@ func (e {{.ClassName}}) Get{{.ClassName}}List(c *gin.Context) { err = d.Bind(c) if err != nil { log.Warnf("request body bind error, %s", err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error( http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -60,13 +63,14 @@ func (e {{.ClassName}}) Get{{.ClassName}}List(c *gin.Context) { err = service{{.ClassName}}.Get{{.ClassName}}Page(d, p, &list, &count) if err != nil { log.Errorf("Get {{.ClassName}} Page error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "查询失败") + e.Error( http.StatusInternalServerError, err, "查询失败") return } - e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功") + e.PageOK( list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功") } +// Get{{.ClassName}} 获取{{.TableComment}} // @Summary 获取{{.TableComment}} // @Description 获取{{.TableComment}} // @Tags {{.TableComment}} @@ -74,11 +78,10 @@ func (e {{.ClassName}}) Get{{.ClassName}}List(c *gin.Context) { // @Success 200 {object} response.Response{data=models.{{.ClassName}}} "{"code": 200, "data": [...]}" // @Router /api/v1/{{.ModuleName}}/{id} [get] // @Security Bearer -// Get{{.ClassName}} 获取{{.TableComment}} func (e {{.ClassName}}) Get{{.ClassName}}(c *gin.Context) { e.SetContext(c) log := e.GetLogger() - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -90,7 +93,7 @@ func (e {{.ClassName}}) Get{{.ClassName}}(c *gin.Context) { err = control.Bind(c) if err != nil { log.Warnf("request body bind error, %s", err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error( http.StatusUnprocessableEntity, err, "参数验证失败") return } var object models.{{.ClassName}} @@ -104,13 +107,14 @@ func (e {{.ClassName}}) Get{{.ClassName}}(c *gin.Context) { err = service{{.ClassName}}.Get{{.ClassName}}(control, p, &object) if err != nil { log.Errorf("Get {{.ClassName}} error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "查询失败") + e.Error( http.StatusInternalServerError, err, "查询失败") return } - e.OK(c, object, "查看成功") + e.OK( object, "查看成功") } +// Insert{{.ClassName}} 创建{{.TableComment}} // @Summary 创建{{.TableComment}} // @Description 创建{{.TableComment}} // @Tags {{.TableComment}} @@ -119,11 +123,11 @@ func (e {{.ClassName}}) Get{{.ClassName}}(c *gin.Context) { // @Param data body dto.{{.ClassName}}Control true "data" // @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}" // @Router /api/v1/{{.ModuleName}} [post] -// Insert{{.ClassName}} 创建{{.TableComment}} +// @Security Bearer func (e {{.ClassName}}) Insert{{.ClassName}}(c *gin.Context) { e.SetContext(c) log := e.GetLogger() - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -135,13 +139,13 @@ func (e {{.ClassName}}) Insert{{.ClassName}}(c *gin.Context) { err = control.Bind(c) if err != nil { log.Warnf("request body bind error, %s", err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error( http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.GenerateM() if err != nil { log.Errorf("generate {{.ClassName}} model error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error( http.StatusInternalServerError, err, "模型生成失败") return } // 设置创建人 @@ -153,13 +157,14 @@ func (e {{.ClassName}}) Insert{{.ClassName}}(c *gin.Context) { err = service{{.ClassName}}.Insert{{.ClassName}}(object.(*models.{{.ClassName}})) if err != nil { log.Errorf("Insert {{.ClassName}} error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "创建失败") + e.Error( http.StatusInternalServerError, err, "创建失败") return } - e.OK(c, object.GetId(), "创建成功") + e.OK( object.GetId(), "创建成功") } +// Update{{.ClassName}} 修改{{.TableComment}} // @Summary 修改{{.TableComment}} // @Description 修改{{.TableComment}} // @Tags {{.TableComment}} @@ -168,11 +173,11 @@ func (e {{.ClassName}}) Insert{{.ClassName}}(c *gin.Context) { // @Param data body dto.{{.ClassName}}Control true "body" // @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}" // @Router /api/v1/{{.ModuleName}}/{id} [put] -// Update{{.ClassName}} 修改{{.TableComment}} +// @Security Bearer func (e {{.ClassName}}) Update{{.ClassName}}(c *gin.Context) { e.SetContext(c) log := e.GetLogger() - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -184,13 +189,13 @@ func (e {{.ClassName}}) Update{{.ClassName}}(c *gin.Context) { err = control.Bind(c) if err != nil { log.Warnf("request body bind error, %s", err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error( http.StatusUnprocessableEntity, err, "参数验证失败") return } object, err := control.GenerateM() if err != nil { log.Errorf("generate {{.ClassName}} model error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "模型生成失败") + e.Error( http.StatusInternalServerError, err, "模型生成失败") return } object.SetUpdateBy(user.GetUserId(c)) @@ -204,23 +209,24 @@ func (e {{.ClassName}}) Update{{.ClassName}}(c *gin.Context) { err = service{{.ClassName}}.Update{{.ClassName}}(object.(*models.{{.ClassName}}), p) if err != nil { log.Errorf("Update {{.ClassName}} error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "更新失败") + e.Error( http.StatusInternalServerError, err, "更新失败") return } - e.OK(c, object.GetId(), "更新成功") + e.OK( object.GetId(), "更新成功") } +// Delete{{.ClassName}} 删除{{.TableComment}} // @Summary 删除{{.TableComment}} // @Description 删除{{.TableComment}} // @Tags {{.TableComment}} // @Param ids body []int false "ids" // @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}" // @Router /api/v1/{{.ModuleName}} [delete] -// Delete{{.ClassName}} 删除{{.TableComment}} +// @Security Bearer func (e {{.ClassName}}) Delete{{.ClassName}}(c *gin.Context) { e.SetContext(c) log := e.GetLogger() - db, err := e.GetOrm(c) + db, err := e.GetOrm() if err != nil { log.Error(err) return @@ -232,7 +238,7 @@ func (e {{.ClassName}}) Delete{{.ClassName}}(c *gin.Context) { err = control.Bind(c) if err != nil { log.Warnf("request body bind error, %s", err.Error()) - e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败") + e.Error( http.StatusUnprocessableEntity, err, "参数验证失败") return } @@ -248,8 +254,8 @@ func (e {{.ClassName}}) Delete{{.ClassName}}(c *gin.Context) { err = service{{.ClassName}}.Remove{{.ClassName}}(control, p) if err != nil { log.Errorf("Remove {{.ClassName}} error, %s", err.Error()) - e.Error(c, http.StatusInternalServerError, err, "删除失败") + e.Error( http.StatusInternalServerError, err, "删除失败") return } - e.OK(c, control.GetId(), "删除成功") + e.OK( control.GetId(), "删除成功") } \ No newline at end of file From debe808f830c51d2879bde44aee8e7e5400ab39d Mon Sep 17 00:00:00 2001 From: wenjianzhang Date: Fri, 7 May 2021 18:52:42 +0800 Subject: [PATCH 06/11] =?UTF-8?q?feat=E2=9C=A8=20=E4=BC=98=E5=8C=96dto?= =?UTF-8?q?=E6=A8=A1=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/v4/dto.go.template | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/template/v4/dto.go.template b/template/v4/dto.go.template index d53c432a4..dc594e3d8 100644 --- a/template/v4/dto.go.template +++ b/template/v4/dto.go.template @@ -12,12 +12,12 @@ import ( type {{.ClassName}}Search struct { dto.Pagination `search:"-"` - {{ $tablename := .TBName -}} - {{ range .Columns -}} + {{- $tablename := .TBName -}} + {{- range .Columns -}} {{$z := .IsQuery}} - {{- if ($z) -}} + {{- if ($z) }} {{.GoField}} {{.GoType}} `form:"{{.JsonField}}" search:"type:{{if eq .QueryType "EQ"}}exact{{ else if eq .QueryType "NE"}}iexact{{ else if eq .QueryType "LIKE"}}contains{{ else if eq .QueryType "GT"}}gt{{ else if eq .QueryType "GTE"}}gte{{ else if eq .QueryType "LT"}}lt{{ else if eq .QueryType "LTE"}}lte{{- end }};column:{{.ColumnName}};table:{{$tablename}}" comment:"{{.ColumnComment}}"` - {{ end -}} + {{- end }} {{- end }} } @@ -40,18 +40,18 @@ func (m *{{.ClassName}}Search) Bind(ctx *gin.Context) error { } type {{.ClassName}}Control struct { - {{ range .Columns -}} + {{- range .Columns -}} {{$x := .Pk}} {{- if ($x) }} - {{.GoField}} {{.GoType}} `uri:"{{.JsonField}}" comment:"{{.ColumnComment}}" vd:"?"` // {{.ColumnComment}} + {{.GoField}} {{.GoType}} `uri:"{{.JsonField}}" comment:"{{.ColumnComment}}"` // {{.ColumnComment}} {{- else if eq .GoField "CreatedAt" -}} {{- else if eq .GoField "UpdatedAt" -}} {{- else if eq .GoField "DeletedAt" -}} {{- else if eq .GoField "CreateBy" -}} {{- else if eq .GoField "UpdateBy" -}} {{- else }} - {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}" vd:"?"` - {{end -}} + {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"` + {{- end -}} {{- end }} } @@ -77,7 +77,7 @@ func (s *{{.ClassName}}Control) Bind(ctx *gin.Context) error { func (s *{{.ClassName}}Control) GenerateM() (common.ActiveRecord, error) { return &models.{{.ClassName}}{ - {{ range .Columns -}} + {{- range .Columns -}} {{$x := .Pk}} {{- if ($x) }} Model: common.Model{ {{.GoField}}: s.{{.GoField}} }, @@ -88,7 +88,7 @@ func (s *{{.ClassName}}Control) GenerateM() (common.ActiveRecord, error) { {{- else if eq .GoField "UpdateBy" -}} {{- else }} {{.GoField}}: s.{{.GoField}}, - {{- end }} + {{- end -}} {{- end }} }, nil } From c6ccd844f52835bfae81b9679c47ebaa6ca81b25 Mon Sep 17 00:00:00 2001 From: wenjianzhang Date: Fri, 7 May 2021 18:54:11 +0800 Subject: [PATCH 07/11] =?UTF-8?q?feat=E2=9C=A8=20=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=96=B9=E6=B3=95=E7=89=88=E6=9C=AC=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/apis/tools/gen.go | 10 +++++----- app/admin/router/sys_router.go | 7 +++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/admin/apis/tools/gen.go b/app/admin/apis/tools/gen.go index 44c58bc6e..de448333c 100644 --- a/app/admin/apis/tools/gen.go +++ b/app/admin/apis/tools/gen.go @@ -109,7 +109,7 @@ func (e *Gen) Preview(c *gin.Context) { e.OK(mp, "") } -func (e *Gen) GenCodeV3(c *gin.Context) { +func (e *Gen) GenCode(c *gin.Context) { e.Context = c log := e.GetLogger() table := tools.SysTables{} @@ -131,9 +131,9 @@ func (e *Gen) GenCodeV3(c *gin.Context) { tab, _ := table.Get(db) if tab.IsActions == 1 { - e.ActionsGenV3(c, tab) + e.ActionsGen(c, tab) } else { - e.NOActionsGenV3(c, tab) + e.NOActionsGen(c, tab) } e.OK("", "Code generated successfully!") @@ -164,7 +164,7 @@ func (e *Gen) GenApiToFile(c *gin.Context) { e.OK("", "Code generated successfully!") } -func (e *Gen) NOActionsGenV3(c *gin.Context, tab tools.SysTables) { +func (e *Gen) NOActionsGen(c *gin.Context, tab tools.SysTables) { e.Context = c log := e.GetLogger() @@ -272,7 +272,7 @@ func (e *Gen) genApiToFile(c *gin.Context, tab tools.SysTables) { } -func (e *Gen) ActionsGenV3(c *gin.Context, tab tools.SysTables) { +func (e *Gen) ActionsGen(c *gin.Context, tab tools.SysTables) { log := api.GetRequestLogger(c) basePath := "template/v4/" routerFile := basePath + "actions/router_check_role.go.template" diff --git a/app/admin/router/sys_router.go b/app/admin/router/sys_router.go index b059f7f04..ee4addffe 100644 --- a/app/admin/router/sys_router.go +++ b/app/admin/router/sys_router.go @@ -46,7 +46,10 @@ func sysBaseRouter(r *gin.RouterGroup) { } func sysStaticFileRouter(r *gin.RouterGroup) { - mime.AddExtensionType(".js", "application/javascript") + err := mime.AddExtensionType(".js", "application/javascript") + if err != nil { + return + } r.Static("/static", "./static") r.Static("/form-generator", "./static/form-generator") } @@ -64,7 +67,7 @@ func sysNoCheckRoleRouter(r *gin.RouterGroup) { v1.GET("/getCaptcha", sys.GenerateCaptchaHandler) gen := tools.Gen{} v1.GET("/gen/preview/:tableId", gen.Preview) - v1.GET("/gen/toproject/:tableId", gen.GenCodeV3) + v1.GET("/gen/toproject/:tableId", gen.GenCode) v1.GET("/gen/apitofile/:tableId", gen.GenApiToFile) v1.GET("/gen/todb/:tableId", gen.GenMenuAndApi) From 946a53cb2b29167fe3e3577325798db809d589cd Mon Sep 17 00:00:00 2001 From: wenjianzhang Date: Fri, 7 May 2021 19:02:06 +0800 Subject: [PATCH 08/11] =?UTF-8?q?feat=E2=9C=A8=20=E6=A8=A1=E7=89=88?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/v4/no_actions/apis.go.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/template/v4/no_actions/apis.go.template b/template/v4/no_actions/apis.go.template index a79630601..47b69f4c3 100644 --- a/template/v4/no_actions/apis.go.template +++ b/template/v4/no_actions/apis.go.template @@ -118,7 +118,7 @@ func (e {{.ClassName}}) Get{{.ClassName}}(c *gin.Context) { // @Summary 创建{{.TableComment}} // @Description 创建{{.TableComment}} // @Tags {{.TableComment}} -// @Accept application/json +// @Accept application/json // @Product application/json // @Param data body dto.{{.ClassName}}Control true "data" // @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}" @@ -168,7 +168,7 @@ func (e {{.ClassName}}) Insert{{.ClassName}}(c *gin.Context) { // @Summary 修改{{.TableComment}} // @Description 修改{{.TableComment}} // @Tags {{.TableComment}} -// @Accept application/json +// @Accept application/json // @Product application/json // @Param data body dto.{{.ClassName}}Control true "body" // @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}" From 508a18a809f942e3c0f28f904d2e7df4d1776fd5 Mon Sep 17 00:00:00 2001 From: wenjianzhang Date: Fri, 7 May 2021 19:11:39 +0800 Subject: [PATCH 09/11] =?UTF-8?q?feat=E2=9C=A8=20=E6=9B=B4=E6=96=B0readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d6ef44d8b..7d0626e63 100644 --- a/README.md +++ b/README.md @@ -157,14 +157,22 @@ vi ./config/setting.yml ``` #### 初始化数据库,以及服务启动 -``` +``` bash # 首次配置需要初始化数据库资源信息 -./go-admin migrate -c config/settings.yml +# macOS or linux 下使用 +$ ./go-admin migrate -c=config/settings.dev.yml + +# ⚠️注意:windows 下使用 +$ ./go-admin.exe migrate -c=config/settings.dev.yml # 启动项目,也可以用IDE进行调试 -./go-admin server -c config/settings.yml +# macOS or linux 下使用 +$ ./go-admin server -c config/settings.yml + +# ⚠️注意:windows 下使用 +$ ./go-admin.exe server -c config/settings.yml ``` #### 使用docker 编译启动 @@ -188,10 +196,11 @@ go generate #### 交叉编译 ```bash +# windows env GOOS=windows GOARCH=amd64 go build main.go # or - +# linux env GOOS=linux GOARCH=amd64 go build main.go ``` From 50a5d6f48d3748a32b733a1ace6d9889d46b4d6a Mon Sep 17 00:00:00 2001 From: wenjianzhang Date: Fri, 7 May 2021 19:57:09 +0800 Subject: [PATCH 10/11] =?UTF-8?q?feat=E2=9C=A8=20=E6=9B=B4=E6=96=B0service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/v4/no_actions/service.go.template | 48 +++++++++------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/template/v4/no_actions/service.go.template b/template/v4/no_actions/service.go.template index 943a3ea73..aaa60a807 100644 --- a/template/v4/no_actions/service.go.template +++ b/template/v4/no_actions/service.go.template @@ -30,7 +30,7 @@ func (e *{{.ClassName}}) Get{{.ClassName}}Page(c *dto.{{.ClassName}}Search, p *a Find(list).Limit(-1).Offset(-1). Count(count).Error if err != nil { - e.Log.Errorf("db error: %s", err) + e.Log.Errorf("Service Get{{.ClassName}}Page error:%s", err) return err } return nil @@ -38,21 +38,19 @@ func (e *{{.ClassName}}) Get{{.ClassName}}Page(c *dto.{{.ClassName}}Search, p *a // Get{{.ClassName}} 获取{{.ClassName}}对象 func (e *{{.ClassName}}) Get{{.ClassName}}(d *dto.{{.ClassName}}ById, p *actions.DataPermission, model *models.{{.ClassName}}) error { - var err error var data models.{{.ClassName}} - db := e.Orm.Model(&data). + err := e.Orm.Model(&data). Scopes( actions.Permission(data.TableName(), p), ). - First(model, d.GetId()) - err = db.Error + First(model, d.GetId()).Error if err != nil && errors.Is(err, gorm.ErrRecordNotFound) { err = errors.New("查看对象不存在或无权查看") - e.Log.Errorf("db error: %s", err) + e.Log.Errorf("Service Get{{.ClassName}} error:%s", err) return err } - if db.Error != nil { + if err != nil { e.Log.Errorf("db error:%s", err) return err } @@ -61,11 +59,9 @@ func (e *{{.ClassName}}) Get{{.ClassName}}(d *dto.{{.ClassName}}ById, p *actions // Insert{{.ClassName}} 创建{{.ClassName}}对象 func (e *{{.ClassName}}) Insert{{.ClassName}}(c *models.{{.ClassName}}) error { - var err error - - err = e.Orm.Create(c).Error + err := e.Orm.Create(c).Error if err != nil { - e.Log.Errorf("db error: %s", err) + e.Log.Errorf("Service Insert{{.ClassName}} error:%s", err) return err } return nil @@ -73,40 +69,34 @@ func (e *{{.ClassName}}) Insert{{.ClassName}}(c *models.{{.ClassName}}) error { // Update{{.ClassName}} 修改{{.ClassName}}对象 func (e *{{.ClassName}}) Update{{.ClassName}}(c *models.{{.ClassName}}, p *actions.DataPermission) error { - var err error - db := e.Orm.Model(c). Scopes( actions.Permission(c.TableName(), p), ).Where(c.GetId()).Updates(c) - if db.Error != nil { - e.Log.Errorf("db error: %s", err) - return err - } + if err := db.Error; err != nil { + e.Log.Errorf("Service Update{{.ClassName}} error:%s", err) + return err + } if db.RowsAffected == 0 { return errors.New("无权更新该数据") - } return nil } // Remove{{.ClassName}} 删除{{.ClassName}} func (e *{{.ClassName}}) Remove{{.ClassName}}(d *dto.{{.ClassName}}ById, p *actions.DataPermission) error { - var err error var data models.{{.ClassName}} db := e.Orm.Model(&data). Scopes( actions.Permission(data.TableName(), p), ).Delete(&data, d.GetId()) - if db.Error != nil { - err = db.Error - e.Log.Errorf("Delete error: %s", err) - return err - } - if db.RowsAffected == 0 { - err = errors.New("无权删除该数据") - return err - } + if err := db.Error; err != nil { + e.Log.Errorf("Service Remove{{.ClassName}} error:%s", err) + return err + } + if db.RowsAffected == 0 { + return errors.New("无权删除该数据") + } return nil -} +} \ No newline at end of file From c6d94c03fbd91989ff1ac387d3647cc078e7fb54 Mon Sep 17 00:00:00 2001 From: wenjianzhang Date: Fri, 7 May 2021 19:57:45 +0800 Subject: [PATCH 11/11] =?UTF-8?q?feat=E2=9C=A8=20=E6=9B=B4=E6=96=B0service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/apis/tools/gen.go | 16 ++-- app/admin/models/gorm/data.go | 87 ------------------- .../{syscategory.go => sys_category.go} | 0 ...hinaareadata.go => sys_china_area_data.go} | 0 .../models/{syscontent.go => sys_content.go} | 0 app/admin/models/{sysjob.go => sys_job.go} | 0 .../system/{casbinrule.go => casbin_rule.go} | 0 ...hinaareadata.go => sys_china_area_data.go} | 0 ...hinaareadata.go => sys_china_area_data.go} | 45 ++++------ app/admin/service/sys_config.go | 32 ++++--- app/admin/service/sys_opera_log.go | 33 +++---- 11 files changed, 55 insertions(+), 158 deletions(-) delete mode 100644 app/admin/models/gorm/data.go rename app/admin/models/{syscategory.go => sys_category.go} (100%) rename app/admin/models/{syschinaareadata.go => sys_china_area_data.go} (100%) rename app/admin/models/{syscontent.go => sys_content.go} (100%) rename app/admin/models/{sysjob.go => sys_job.go} (100%) rename app/admin/models/system/{casbinrule.go => casbin_rule.go} (100%) rename app/admin/router/{syschinaareadata.go => sys_china_area_data.go} (100%) rename app/admin/service/{syschinaareadata.go => sys_china_area_data.go} (77%) diff --git a/app/admin/apis/tools/gen.go b/app/admin/apis/tools/gen.go index de448333c..06063438a 100644 --- a/app/admin/apis/tools/gen.go +++ b/app/admin/apis/tools/gen.go @@ -21,7 +21,7 @@ type Gen struct { apis.Api } -func (e *Gen) Preview(c *gin.Context) { +func (e Gen) Preview(c *gin.Context) { e.Context = c log := e.GetLogger() table := tools.SysTables{} @@ -109,7 +109,7 @@ func (e *Gen) Preview(c *gin.Context) { e.OK(mp, "") } -func (e *Gen) GenCode(c *gin.Context) { +func (e Gen) GenCode(c *gin.Context) { e.Context = c log := e.GetLogger() table := tools.SysTables{} @@ -139,7 +139,7 @@ func (e *Gen) GenCode(c *gin.Context) { e.OK("", "Code generated successfully!") } -func (e *Gen) GenApiToFile(c *gin.Context) { +func (e Gen) GenApiToFile(c *gin.Context) { e.Context = c log := e.GetLogger() table := tools.SysTables{} @@ -164,7 +164,7 @@ func (e *Gen) GenApiToFile(c *gin.Context) { e.OK("", "Code generated successfully!") } -func (e *Gen) NOActionsGen(c *gin.Context, tab tools.SysTables) { +func (e Gen) NOActionsGen(c *gin.Context, tab tools.SysTables) { e.Context = c log := e.GetLogger() @@ -249,7 +249,7 @@ func (e *Gen) NOActionsGen(c *gin.Context, tab tools.SysTables) { } -func (e *Gen) genApiToFile(c *gin.Context, tab tools.SysTables) { +func (e Gen) genApiToFile(c *gin.Context, tab tools.SysTables) { e.Context = c log := e.GetLogger() @@ -272,7 +272,7 @@ func (e *Gen) genApiToFile(c *gin.Context, tab tools.SysTables) { } -func (e *Gen) ActionsGen(c *gin.Context, tab tools.SysTables) { +func (e Gen) ActionsGen(c *gin.Context, tab tools.SysTables) { log := api.GetRequestLogger(c) basePath := "template/v4/" routerFile := basePath + "actions/router_check_role.go.template" @@ -336,7 +336,7 @@ func (e *Gen) ActionsGen(c *gin.Context, tab tools.SysTables) { pkg.FileCreate(b6, "./app/"+tab.PackageName+"/service/dto/"+tab.BusinessName+".go") } -func (e *Gen) GenMenuAndApi(c *gin.Context) { +func (e Gen) GenMenuAndApi(c *gin.Context) { log := api.GetRequestLogger(c) table := tools.SysTables{} @@ -578,4 +578,4 @@ func (e *Gen) GenMenuAndApi(c *gin.Context) { ADelete.MenuId, err = ADelete.Create(db) e.OK("", "数据生成成功!") -} +} \ No newline at end of file diff --git a/app/admin/models/gorm/data.go b/app/admin/models/gorm/data.go deleted file mode 100644 index 5f60479a5..000000000 --- a/app/admin/models/gorm/data.go +++ /dev/null @@ -1,87 +0,0 @@ -package gorm - -import ( - "go-admin/app/admin/models/system" - "gorm.io/gorm" -) - -func InitData(db *gorm.DB) { - - list := []system.CasbinRule{ - {"p", "admin", "/api/v1/menulist", "GET", "", "", ""}, - {"p", "admin", "/api/v1/menu", "POST", "", "", ""}, - {"p", "admin", "/api/v1/dict/databytype/", "GET", "", "", ""}, - {"p", "admin", "/api/v1/menu", "PUT", "", "", ""}, - {"p", "admin", "/api/v1/menu/:id", "DELETE", "", "", ""}, - {"p", "admin", "/api/v1/sysUserList", "GET", "", "", ""}, - {"p", "admin", "/api/v1/sysUser/:id", "GET", "", "", ""}, - {"p", "admin", "/api/v1/sysUser/", "GET", "", "", ""}, - {"p", "admin", "/api/v1/sysUser", "POST", "", "", ""}, - {"p", "admin", "/api/v1/sysUser", "PUT", "", "", ""}, - {"p", "admin", "/api/v1/sysUser/:id", "DELETE", "", "", ""}, - {"p", "admin", "/api/v1/user/profile", "GET", "", "", ""}, - {"p", "admin", "/api/v1/rolelist", "GET", "", "", ""}, - {"p", "admin", "/api/v1/role/:id", "GET", "", "", ""}, - {"p", "admin", "/api/v1/role", "POST", "", "", ""}, - {"p", "admin", "/api/v1/role", "PUT", "", "", ""}, - {"p", "admin", "/api/v1/role/:id", "DELETE", "", "", ""}, - {"p", "admin", "/api/v1/configList", "GET", "", "", ""}, - {"p", "admin", "/api/v1/config/:id", "GET", "", "", ""}, - {"p", "admin", "/api/v1/config", "POST", "", "", ""}, - {"p", "admin", "/api/v1/config", "PUT", "", "", ""}, - {"p", "admin", "/api/v1/config/:id", "DELETE", "", "", ""}, - {"p", "admin", "/api/v1/menurole", "GET", "", "", ""}, - {"p", "admin", "/api/v1/roleMenuTreeselect/:id", "GET", "", "", ""}, - {"p", "admin", "/api/v1/menuTreeselect", "GET", "", "", ""}, - {"p", "admin", "/api/v1/rolemenu", "GET", "", "", ""}, - {"p", "admin", "/api/v1/rolemenu", "POST", "", "", ""}, - {"p", "admin", "/api/v1/rolemenu/:id", "DELETE", "", "", ""}, - {"p", "admin", "/api/v1/deptList", "GET", "", "", ""}, - {"p", "admin", "/api/v1/dept/:id", "GET", "", "", ""}, - {"p", "admin", "/api/v1/dept", "POST", "", "", ""}, - {"p", "admin", "/api/v1/dept", "PUT", "", "", ""}, - {"p", "admin", "/api/v1/dept/:id", "DELETE", "", "", ""}, - {"p", "admin", "/api/v1/dict/datalist", "GET", "", "", ""}, - {"p", "admin", "/api/v1/dict/data/:id", "GET", "", "", ""}, - {"p", "admin", "/api/v1/dict/databytype/:id", "GET", "", "", ""}, - {"p", "admin", "/api/v1/dict/data", "POST", "", "", ""}, - {"p", "admin", "/api/v1/dict/data/", "PUT", "", "", ""}, - {"p", "admin", "/api/v1/dict/data/:id", "DELETE", "", "", ""}, - {"p", "admin", "/api/v1/dict/typelist", "GET", "", "", ""}, - {"p", "admin", "/api/v1/dict/type/:id", "GET", "", "", ""}, - {"p", "admin", "/api/v1/dict/type", "POST", "", "", ""}, - {"p", "admin", "/api/v1/dict/type", "PUT", "", "", ""}, - {"p", "admin", "/api/v1/dict/type/:id", "DELETE", "", "", ""}, - {"p", "admin", "/api/v1/postlist", "GET", "", "", ""}, - {"p", "admin", "/api/v1/post/:id", "GET", "", "", ""}, - {"p", "admin", "/api/v1/post", "POST", "", "", ""}, - {"p", "admin", "/api/v1/post", "PUT", "", "", ""}, - {"p", "admin", "/api/v1/post/:id", "DELETE", "", "", ""}, - {"p", "admin", "/api/v1/menu/:id", "GET", "", "", ""}, - {"p", "admin", "/api/v1/menuids", "GET", "", "", ""}, - {"p", "admin", "/api/v1/loginloglist", "GET", "", "", ""}, - {"p", "admin", "/api/v1/loginlog/:id", "DELETE", "", "", ""}, - {"p", "admin", "/api/v1/operloglist", "GET", "", "", ""}, - {"p", "admin", "/api/v1/getinfo", "GET", "", "", ""}, - {"p", "admin", "/api/v1/roledatascope", "PUT", "", "", ""}, - {"p", "admin", "/api/v1/roleDeptTreeselect/:id", "GET", "", "", ""}, - {"p", "admin", "/api/v1/deptTree", "GET", "", "", ""}, - {"p", "admin", "/api/v1/configKey/:id", "GET", "", "", ""}, - {"p", "admin", "/api/v1/logout", "POST", "", "", ""}, - {"p", "admin", "/api/v1/user/avatar", "POST", "", "", ""}, - {"p", "admin", "/api/v1/user/pwd", "PUT", "", "", ""}, - {"p", "admin", "/api/v1/dict/typeoptionselect", "GET", "", "", ""}, - {"p", "admin", "/api/v1/sysjobList", "GET", "", "", ""}, - {"p", "admin", "/api/v1/sysjob/:id", "GET", "", "", ""}, - {"p", "admin", "/api/v1/sysjob", "POST", "", "", ""}, - {"p", "admin", "/api/v1/sysjob", "PUT", "", "", ""}, - {"p", "admin", "/api/v1/sysjob/:id", "DELETE", "", "", ""}, - {"p", "admin", "/api/v1/syssettingList", "GET", "", "", ""}, - {"p", "admin", "/api/v1/syssetting/:id", "GET", "", "", ""}, - {"p", "admin", "/api/v1/syssetting", "POST", "", "", ""}, - {"p", "admin", "/api/v1/syssetting", "PUT", "", "", ""}, - {"p", "admin", "/api/v1/syssetting/:id", "DELETE", "", "", ""}, - } - - db.Table("sys_casbin_rule").Create(list) -} diff --git a/app/admin/models/syscategory.go b/app/admin/models/sys_category.go similarity index 100% rename from app/admin/models/syscategory.go rename to app/admin/models/sys_category.go diff --git a/app/admin/models/syschinaareadata.go b/app/admin/models/sys_china_area_data.go similarity index 100% rename from app/admin/models/syschinaareadata.go rename to app/admin/models/sys_china_area_data.go diff --git a/app/admin/models/syscontent.go b/app/admin/models/sys_content.go similarity index 100% rename from app/admin/models/syscontent.go rename to app/admin/models/sys_content.go diff --git a/app/admin/models/sysjob.go b/app/admin/models/sys_job.go similarity index 100% rename from app/admin/models/sysjob.go rename to app/admin/models/sys_job.go diff --git a/app/admin/models/system/casbinrule.go b/app/admin/models/system/casbin_rule.go similarity index 100% rename from app/admin/models/system/casbinrule.go rename to app/admin/models/system/casbin_rule.go diff --git a/app/admin/router/syschinaareadata.go b/app/admin/router/sys_china_area_data.go similarity index 100% rename from app/admin/router/syschinaareadata.go rename to app/admin/router/sys_china_area_data.go diff --git a/app/admin/service/syschinaareadata.go b/app/admin/service/sys_china_area_data.go similarity index 77% rename from app/admin/service/syschinaareadata.go rename to app/admin/service/sys_china_area_data.go index 5c7fa68c9..2ff6aa6dc 100644 --- a/app/admin/service/syschinaareadata.go +++ b/app/admin/service/sys_china_area_data.go @@ -18,10 +18,9 @@ type SysChinaAreaData struct { // GetSysChinaAreaDataPage 获取SysChinaAreaData列表 func (e *SysChinaAreaData) GetSysChinaAreaDataPage(c *dto.SysChinaAreaDataSearch, p *actions.DataPermission, list *[]models.SysChinaAreaData, count *int64) error { - var err error var data models.SysChinaAreaData - err = e.Orm.Model(&data). + err := e.Orm.Model(&data). Scopes( cDto.MakeCondition(c.GetNeedSearch()), cDto.Paginate(c.GetPageSize(), c.GetPageIndex()), @@ -30,7 +29,7 @@ func (e *SysChinaAreaData) GetSysChinaAreaDataPage(c *dto.SysChinaAreaDataSearch Find(list).Limit(-1).Offset(-1). Count(count).Error if err != nil { - e.Log.Errorf("db error:%s", err) + e.Log.Errorf("Service GetSysChinaAreaDataPage error:%s", err) return err } return nil @@ -38,22 +37,20 @@ func (e *SysChinaAreaData) GetSysChinaAreaDataPage(c *dto.SysChinaAreaDataSearch // GetSysChinaAreaData 获取SysChinaAreaData对象 func (e *SysChinaAreaData) GetSysChinaAreaData(d *dto.SysChinaAreaDataById, p *actions.DataPermission, model *models.SysChinaAreaData) error { - var err error var data models.SysChinaAreaData - db := e.Orm.Model(&data). + err := e.Orm.Model(&data). Scopes( actions.Permission(data.TableName(), p), ). - First(model, d.GetId()) - err = db.Error + First(model, d.GetId()).Error if err != nil && errors.Is(err, gorm.ErrRecordNotFound) { err = errors.New("查看对象不存在或无权查看") e.Log.Errorf("db error:%s", err) return err } - if db.Error != nil { - e.Log.Errorf("db error:%s", err) + if err != nil { + e.Log.Errorf("Service GetSysChinaAreaData error:%s", err) return err } return nil @@ -61,13 +58,12 @@ func (e *SysChinaAreaData) GetSysChinaAreaData(d *dto.SysChinaAreaDataById, p *a // InsertSysChinaAreaData 创建SysChinaAreaData对象 func (e *SysChinaAreaData) InsertSysChinaAreaData(model *models.SysChinaAreaData) error { - var err error var data models.SysChinaAreaData - err = e.Orm.Model(&data). + err := e.Orm.Model(&data). Create(model).Error if err != nil { - e.Log.Errorf("db error:%s", err) + e.Log.Errorf("Service InsertSysChinaAreaData error:%s", err) return err } return nil @@ -75,41 +71,36 @@ func (e *SysChinaAreaData) InsertSysChinaAreaData(model *models.SysChinaAreaData // UpdateSysChinaAreaData 修改SysChinaAreaData对象 func (e *SysChinaAreaData) UpdateSysChinaAreaData(c *models.SysChinaAreaData, p *actions.DataPermission) error { - var err error - var data models.SysChinaAreaData - - db := e.Orm.Model(&data). + db := e.Orm.Model(c). Scopes( - actions.Permission(data.TableName(), p), + actions.Permission(c.TableName(), p), ).Where(c.GetId()).Updates(c) - if db.Error != nil { - e.Log.Errorf("db error:%s", err) + if err := db.Error; err != nil { + e.Log.Errorf("Service UpdateSysChinaAreaData error: %s", err) return err } if db.RowsAffected == 0 { return errors.New("无权更新该数据") - } return nil } // RemoveSysChinaAreaData 删除SysChinaAreaData func (e *SysChinaAreaData) RemoveSysChinaAreaData(d *dto.SysChinaAreaDataById, p *actions.DataPermission) error { - var err error + var data models.SysChinaAreaData db := e.Orm.Model(&data). Scopes( actions.Permission(data.TableName(), p), ).Delete(&data, d.GetId()) - if db.Error != nil { - err = db.Error - e.Log.Errorf("Delete error: %s", err) + + if err := db.Error; err != nil { + e.Log.Errorf("Service RemoveSysChinaAreaData error: %s", err) return err } if db.RowsAffected == 0 { - err = errors.New("无权删除该数据") - return err + return errors.New("无权删除该数据") } return nil -} +} \ No newline at end of file diff --git a/app/admin/service/sys_config.go b/app/admin/service/sys_config.go index c4d1756cf..2cf60a17d 100644 --- a/app/admin/service/sys_config.go +++ b/app/admin/service/sys_config.go @@ -26,7 +26,7 @@ func (e *SysConfig) GetSysConfigPage(c *dto.SysConfigSearch, list *[]system.SysC Find(list).Limit(-1).Offset(-1). Count(count).Error if err != nil { - e.Log.Errorf("db error:%s", err) + e.Log.Errorf("Service GetSysConfigPage error:%s", err) return err } return nil @@ -42,7 +42,7 @@ func (e *SysConfig) GetSysConfigByKey(c *dto.SysConfigSearch, list *[]system.Sys ). Find(list).Error if err != nil { - e.Log.Errorf("db error:%s", err) + e.Log.Errorf("Service GetSysConfigByKey error:%s", err) return err } return nil @@ -50,19 +50,17 @@ func (e *SysConfig) GetSysConfigByKey(c *dto.SysConfigSearch, list *[]system.Sys // GetSysConfig 获取SysConfig对象 func (e *SysConfig) GetSysConfig(d *dto.SysConfigById, model *system.SysConfig) error { - var err error var data system.SysConfig - db := e.Orm.Model(&data). - First(model, d.GetId()) - err = db.Error + err := e.Orm.Model(&data). + First(model, d.GetId()).Error if err != nil && errors.Is(err, gorm.ErrRecordNotFound) { err = errors.New("查看对象不存在或无权查看") - e.Log.Errorf("db error:%s", err) + e.Log.Errorf("Service GetSysConfigPage error:%s", err) return err } - if db.Error != nil { - e.Log.Errorf("db error:%s", err) + if err != nil { + e.Log.Errorf("Service GetSysConfig error:%s", err) return err } return nil @@ -76,7 +74,7 @@ func (e *SysConfig) InsertSysConfig(model *system.SysConfig) error { err = e.Orm.Model(&data). Create(model).Error if err != nil { - e.Log.Errorf("db error:%s", err) + e.Log.Errorf("Service InsertSysConfig error:%s", err) return err } return nil @@ -85,12 +83,12 @@ func (e *SysConfig) InsertSysConfig(model *system.SysConfig) error { // UpdateSysConfig 修改SysConfig对象 func (e *SysConfig) UpdateSysConfig(c *system.SysConfig) error { var err error - var data system.SysConfig - db := e.Orm.Model(&data). + db := e.Orm.Model(c). Where(c.GetId()).Updates(c) - if db.Error != nil { - e.Log.Errorf("db error:%s", err) + err = db.Error + if err != nil { + e.Log.Errorf("Service UpdateSysConfig error:%s", err) return err } if db.RowsAffected == 0 { @@ -109,7 +107,7 @@ func (e *SysConfig) RemoveSysConfig(d *dto.SysConfigById, c *system.SysConfig) e Where(d.GetId()).Delete(c) if db.Error != nil { err = db.Error - e.Log.Errorf("Delete error: %s", err) + e.Log.Errorf("Service RemoveSysConfig error:%s", err) return err } if db.RowsAffected == 0 { @@ -126,9 +124,9 @@ func (e *SysConfig) GetSysConfigByKEY(c *dto.SysConfigControl) error { data.ConfigKey = c.ConfigKey err = e.Orm.Table(data.TableName()).Where("config_key = ?", data.ConfigKey).First(c).Error if err != nil { - e.Log.Errorf("db error:%s", err) + e.Log.Errorf("Service GetSysConfigByKEY error:%s", err) return err } return nil -} +} \ No newline at end of file diff --git a/app/admin/service/sys_opera_log.go b/app/admin/service/sys_opera_log.go index 5dccf3ca9..cb81586b4 100644 --- a/app/admin/service/sys_opera_log.go +++ b/app/admin/service/sys_opera_log.go @@ -26,7 +26,7 @@ func (e *SysOperaLog) GetSysOperaLogPage(c *dto.SysOperaLogSearch, list *[]syste Find(list).Limit(-1).Offset(-1). Count(count).Error if err != nil { - e.Log.Errorf(" db error:%s", err) + e.Log.Errorf("Service GetSysOperaLogPage error:%s", err.Error()) return err } return nil @@ -34,19 +34,17 @@ func (e *SysOperaLog) GetSysOperaLogPage(c *dto.SysOperaLogSearch, list *[]syste // GetSysOperaLog 获取SysOperaLog对象 func (e *SysOperaLog) GetSysOperaLog(d *dto.SysOperaLogById, model *system.SysOperaLog) error { - var err error var data system.SysOperaLog - db := e.Orm.Model(&data). - First(model, d.GetId()) - err = db.Error + err := e.Orm.Model(&data). + First(model, d.GetId()).Error if err != nil && errors.Is(err, gorm.ErrRecordNotFound) { err = errors.New("查看对象不存在或无权查看") - e.Log.Errorf(" db error:%s", err) + e.Log.Errorf("Service GetSysOperaLog error:%s", err.Error()) return err } - if db.Error != nil { - e.Log.Errorf(" db error:%s", err) + if err != nil { + e.Log.Errorf("Service GetSysOperaLog error:%s", err.Error()) return err } return nil @@ -60,7 +58,7 @@ func (e *SysOperaLog) InsertSysOperaLog(model *system.SysOperaLog) error { err = e.Orm.Model(&data). Create(model).Error if err != nil { - e.Log.Errorf(" db error:%s", err) + e.Log.Errorf("Service InsertSysOperaLog error:%s", err.Error()) return err } return nil @@ -69,12 +67,11 @@ func (e *SysOperaLog) InsertSysOperaLog(model *system.SysOperaLog) error { // UpdateSysOperaLog 修改SysOperaLog对象 func (e *SysOperaLog) UpdateSysOperaLog(c *system.SysOperaLog) error { var err error - var data system.SysOperaLog - db := e.Orm.Model(&data). + db := e.Orm.Model(c). Where(c.GetId()).Updates(c) - if db.Error != nil { - e.Log.Errorf(" db error:%s", err) + if err = db.Error; err != nil { + e.Log.Errorf("Service UpdateSysOperaLog error:%s", err.Error()) return err } if db.RowsAffected == 0 { @@ -90,14 +87,12 @@ func (e *SysOperaLog) RemoveSysOperaLog(d *dto.SysOperaLogById) error { var data system.SysOperaLog db := e.Orm.Model(&data).Where(d.Ids).Delete(&data) - if db.Error != nil { - err = db.Error - e.Log.Errorf(" Delete error: %s", err) + if err = db.Error; err != nil { + e.Log.Errorf("Service RemoveSysOperaLog error:%s", err.Error()) return err } if db.RowsAffected == 0 { - err = errors.New("无权删除该数据") - return err + return errors.New("无权删除该数据") } return nil -} +} \ No newline at end of file