diff --git a/apps/develop/api/gen.go b/apps/develop/api/gen.go index c82ec6f..e04bb48 100644 --- a/apps/develop/api/gen.go +++ b/apps/develop/api/gen.go @@ -3,7 +3,6 @@ package api import ( "pandax/apps/develop/gen" "pandax/apps/develop/services" - "pandax/base/ctx" "pandax/base/ginx" ) @@ -18,7 +17,7 @@ type GenApi struct { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /develop/code/gen/preview/{tableId} [get] // @Security X-TOKEN -func (e *GenApi) Preview(rc *ctx.ReqCtx) { +func (e *GenApi) Preview(rc *ginx.ReqCtx) { tableId := ginx.PathParamInt(rc.GinCtx, "tableId") rc.ResData = gen.Preview(int64(tableId)) } @@ -30,7 +29,7 @@ func (e *GenApi) Preview(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /develop/code/gen/code/{tableId} [get] // @Security X-TOKEN -func (e *GenApi) GenCode(rc *ctx.ReqCtx) { +func (e *GenApi) GenCode(rc *ginx.ReqCtx) { tableId := ginx.PathParamInt(rc.GinCtx, "tableId") gen.GenCode(int64(tableId)) } @@ -42,7 +41,7 @@ func (e *GenApi) GenCode(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /develop/code/gen/configure/{tableId} [get] // @Security X-TOKEN -func (e *GenApi) GenConfigure(rc *ctx.ReqCtx) { +func (e *GenApi) GenConfigure(rc *ginx.ReqCtx) { tableId := ginx.PathParamInt(rc.GinCtx, "tableId") menuId := ginx.QueryInt(rc.GinCtx, "menuId", 0) gen.GenConfigure(tableId, menuId) diff --git a/apps/develop/api/table.go b/apps/develop/api/table.go index bef7f2e..a100e6c 100644 --- a/apps/develop/api/table.go +++ b/apps/develop/api/table.go @@ -4,7 +4,6 @@ import ( "pandax/apps/develop/entity" "pandax/apps/develop/gen" "pandax/apps/develop/services" - "pandax/base/ctx" "pandax/base/ginx" "pandax/base/utils" "strings" @@ -23,7 +22,7 @@ type GenTableApi struct { // @Param pageNum query int false "pageNum / 页码" // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /develop/code/table/db/list [get] -func (g *GenTableApi) GetDBTableList(rc *ctx.ReqCtx) { +func (g *GenTableApi) GetDBTableList(rc *ginx.ReqCtx) { pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) tableName := rc.GinCtx.Query("tableName") @@ -45,7 +44,7 @@ func (g *GenTableApi) GetDBTableList(rc *ctx.ReqCtx) { // @Param pageIndex query int false "pageIndex / 页码" // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /develop/code/table/list [get] -func (g *GenTableApi) GetTablePage(rc *ctx.ReqCtx) { +func (g *GenTableApi) GetTablePage(rc *ginx.ReqCtx) { pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) tableName := rc.GinCtx.Query("tableName") @@ -66,7 +65,7 @@ func (g *GenTableApi) GetTablePage(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /develop/code/table/info/{tableId} [get] // @Security Bearer -func (g *GenTableApi) GetTableInfo(rc *ctx.ReqCtx) { +func (g *GenTableApi) GetTableInfo(rc *ginx.ReqCtx) { tableId := ginx.PathParamInt(rc.GinCtx, "tableId") result := g.GenTableApp.FindOne(entity.DevGenTable{TableId: int64(tableId)}, true) mp := make(map[string]any) @@ -82,7 +81,7 @@ func (g *GenTableApi) GetTableInfo(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /develop/code/table/info/tableName [get] // @Security X-TOKEN -func (g *GenTableApi) GetTableInfoByName(rc *ctx.ReqCtx) { +func (g *GenTableApi) GetTableInfoByName(rc *ginx.ReqCtx) { tableName := rc.GinCtx.Query("tableName") result := g.GenTableApp.FindOne(entity.DevGenTable{TableName: tableName}, true) mp := make(map[string]any) @@ -97,7 +96,7 @@ func (g *GenTableApi) GetTableInfoByName(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /develop/code/table/tableTree [get] // @Security X-TOKEN -func (g *GenTableApi) GetTableTree(rc *ctx.ReqCtx) { +func (g *GenTableApi) GetTableTree(rc *ginx.ReqCtx) { rc.ResData = g.GenTableApp.FindTree(entity.DevGenTable{}) } @@ -111,7 +110,7 @@ func (g *GenTableApi) GetTableTree(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /develop/code/table [post] // @Security Bearer -func (g *GenTableApi) Insert(rc *ctx.ReqCtx) { +func (g *GenTableApi) Insert(rc *ginx.ReqCtx) { tablesList := strings.Split(rc.GinCtx.Query("tables"), ",") wg := sync.WaitGroup{} @@ -137,7 +136,7 @@ func (g *GenTableApi) Insert(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /develop/code/table [put] // @Security Bearer -func (g *GenTableApi) Update(rc *ctx.ReqCtx) { +func (g *GenTableApi) Update(rc *ginx.ReqCtx) { var data entity.DevGenTable ginx.BindJsonAndValid(rc.GinCtx, &data) g.GenTableApp.Update(data) @@ -151,7 +150,7 @@ func (g *GenTableApi) Update(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": -1, "message": "删除失败"}" // @Router /develop/code/table/{tableId} [delete] -func (g *GenTableApi) Delete(rc *ctx.ReqCtx) { +func (g *GenTableApi) Delete(rc *ginx.ReqCtx) { tableIds := rc.GinCtx.Param("tableId") group := utils.IdsStrToIdsIntGroup(tableIds) g.GenTableApp.Delete(group) diff --git a/apps/develop/router/gen.go b/apps/develop/router/gen.go index 27af595..1c46dd2 100644 --- a/apps/develop/router/gen.go +++ b/apps/develop/router/gen.go @@ -4,7 +4,7 @@ import ( "github.com/gin-gonic/gin" "pandax/apps/develop/api" "pandax/apps/develop/services" - "pandax/base/ctx" + "pandax/base/ginx" ) func InitGenRouter(router *gin.RouterGroup) { @@ -14,18 +14,15 @@ func InitGenRouter(router *gin.RouterGroup) { } gen := router.Group("gen") - genViewLog := ctx.NewLogInfo("获取生成代码视图") gen.GET("preview/:tableId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(genViewLog).Handle(genApi.Preview) + ginx.NewReqCtx(c).WithLog("获取生成代码视图").Handle(genApi.Preview) }) - genCodeLog := ctx.NewLogInfo("生成代码") gen.GET("code/:tableId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(genCodeLog).Handle(genApi.GenCode) + ginx.NewReqCtx(c).WithLog("生成代码").Handle(genApi.GenCode) }) - genConfigureLog := ctx.NewLogInfo("生成配置") gen.GET("configure/:tableId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(genConfigureLog).Handle(genApi.GenConfigure) + ginx.NewReqCtx(c).WithLog("生成配置").Handle(genApi.GenConfigure) }) } diff --git a/apps/develop/router/table.go b/apps/develop/router/table.go index 5c16dd4..9bb504b 100644 --- a/apps/develop/router/table.go +++ b/apps/develop/router/table.go @@ -4,7 +4,7 @@ import ( "github.com/gin-gonic/gin" "pandax/apps/develop/api" "pandax/apps/develop/services" - "pandax/base/ctx" + "pandax/base/ginx" ) func InitGenTableRouter(router *gin.RouterGroup) { @@ -14,43 +14,35 @@ func InitGenTableRouter(router *gin.RouterGroup) { } gen := router.Group("table") - genDbListLog := ctx.NewLogInfo("获取数据库列表") gen.GET("/db/list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(genDbListLog).Handle(genApi.GetDBTableList) + ginx.NewReqCtx(c).WithLog("获取数据库列表").Handle(genApi.GetDBTableList) }) - genListLog := ctx.NewLogInfo("获取表列表") gen.GET("list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(genListLog).Handle(genApi.GetTablePage) + ginx.NewReqCtx(c).WithLog("获取表列表").Handle(genApi.GetTablePage) }) - genInfoNameLog := ctx.NewLogInfo("获取表信息By tableName") gen.GET("/info/tableName", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(genInfoNameLog).Handle(genApi.GetTableInfoByName) + ginx.NewReqCtx(c).WithLog("获取表信息By tableName").Handle(genApi.GetTableInfoByName) }) - genInfoLog := ctx.NewLogInfo("获取表信息") gen.GET("info/:tableId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(genInfoLog).Handle(genApi.GetTableInfo) + ginx.NewReqCtx(c).WithLog("获取表信息").Handle(genApi.GetTableInfo) }) - genTreeLog := ctx.NewLogInfo("获取表树") gen.GET("tableTree", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(genTreeLog).Handle(genApi.GetTableTree) + ginx.NewReqCtx(c).WithLog("获取表树").Handle(genApi.GetTableTree) }) - genInsterLog := ctx.NewLogInfo("新增表") gen.POST("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(genInsterLog).Handle(genApi.Insert) + ginx.NewReqCtx(c).WithLog("新增表").Handle(genApi.Insert) }) - genUpdateLog := ctx.NewLogInfo("修改表") gen.PUT("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(genUpdateLog).Handle(genApi.Update) + ginx.NewReqCtx(c).WithLog("修改表").Handle(genApi.Update) }) - genDeleteLog := ctx.NewLogInfo("删除表") gen.DELETE(":tableId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(genDeleteLog).Handle(genApi.Delete) + ginx.NewReqCtx(c).WithLog("删除表").Handle(genApi.Delete) }) } diff --git a/apps/job/api/job.go b/apps/job/api/job.go index a429f94..c7b2d02 100644 --- a/apps/job/api/job.go +++ b/apps/job/api/job.go @@ -6,7 +6,6 @@ import ( "pandax/apps/job/jobs" "pandax/apps/job/services" "pandax/base/biz" - "pandax/base/ctx" "pandax/base/ginx" "pandax/base/utils" ) @@ -25,7 +24,7 @@ type JobApi struct { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /job/job [post] // @Security X-TOKEN -func (j *JobApi) CreateJob(rc *ctx.ReqCtx) { +func (j *JobApi) CreateJob(rc *ginx.ReqCtx) { var job entity.SysJob ginx.BindJsonAndValid(rc.GinCtx, &job) @@ -44,7 +43,7 @@ func (j *JobApi) CreateJob(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /job/list [get] // @Security -func (j *JobApi) GetJobList(rc *ctx.ReqCtx) { +func (j *JobApi) GetJobList(rc *ginx.ReqCtx) { pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) jobName := rc.GinCtx.Query("jobName") @@ -67,7 +66,7 @@ func (j *JobApi) GetJobList(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /job/{jobId} [get] // @Security -func (j *JobApi) GetJob(rc *ctx.ReqCtx) { +func (j *JobApi) GetJob(rc *ginx.ReqCtx) { jobId := ginx.PathParamInt(rc.GinCtx, rc.GinCtx.Param("jobId")) rc.ResData = j.JobApp.FindOne(int64(jobId)) } @@ -82,7 +81,7 @@ func (j *JobApi) GetJob(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /job [put] // @Security X-TOKEN -func (l *JobApi) UpdateJob(rc *ctx.ReqCtx) { +func (l *JobApi) UpdateJob(rc *ginx.ReqCtx) { var job entity.SysJob ginx.BindJsonAndValid(rc.GinCtx, &job) l.JobApp.Update(job) @@ -95,7 +94,7 @@ func (l *JobApi) UpdateJob(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /job/{jobId} [delete] -func (l *JobApi) DeleteJob(rc *ctx.ReqCtx) { +func (l *JobApi) DeleteJob(rc *ginx.ReqCtx) { jobIds := rc.GinCtx.Param("jobId") group := utils.IdsStrToIdsIntGroup(jobIds) l.JobApp.Delete(group) @@ -108,7 +107,7 @@ func (l *JobApi) DeleteJob(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /job/stop/{jobId} [get] -func (l *JobApi) StopJobForService(rc *ctx.ReqCtx) { +func (l *JobApi) StopJobForService(rc *ginx.ReqCtx) { jobId := ginx.PathParamInt(rc.GinCtx, "jobId") job := l.JobApp.FindOne(int64(jobId)) jobs.Remove(jobs.Crontab, job.EntryId) @@ -120,7 +119,7 @@ func (l *JobApi) StopJobForService(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /job/stop/{jobId} [get] -func (l *JobApi) StartJobForService(rc *ctx.ReqCtx) { +func (l *JobApi) StartJobForService(rc *ginx.ReqCtx) { jobId := ginx.PathParamInt(rc.GinCtx, "jobId") job := l.JobApp.FindOne(int64(jobId)) @@ -163,7 +162,7 @@ func (l *JobApi) StartJobForService(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /job/changeStatus [put] // @Security X-TOKEN -func (l *JobApi) UpdateStatusJob(rc *ctx.ReqCtx) { +func (l *JobApi) UpdateStatusJob(rc *ginx.ReqCtx) { var job from.JobStatus ginx.BindJsonAndValid(rc.GinCtx, &job) diff --git a/apps/job/router/job.go b/apps/job/router/job.go index 4f79f51..4b0f996 100644 --- a/apps/job/router/job.go +++ b/apps/job/router/job.go @@ -4,7 +4,7 @@ import ( "github.com/gin-gonic/gin" "pandax/apps/job/api" "pandax/apps/job/services" - "pandax/base/ctx" + "pandax/base/ginx" ) func InitJobRouter(router *gin.RouterGroup) { @@ -14,43 +14,35 @@ func InitJobRouter(router *gin.RouterGroup) { } job := router.Group("") - jobListLog := ctx.NewLogInfo("获取Job列表") job.GET("list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(jobListLog).Handle(jobApi.GetJobList) + ginx.NewReqCtx(c).WithLog("获取Job列表").Handle(jobApi.GetJobList) }) - getJobLog := ctx.NewLogInfo("获取Job信息") job.GET(":jobId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(getJobLog).Handle(jobApi.GetJob) + ginx.NewReqCtx(c).WithLog("获取Job信息").Handle(jobApi.GetJob) }) - insertJobLog := ctx.NewLogInfo("添加Job信息") job.POST("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(insertJobLog).Handle(jobApi.CreateJob) + ginx.NewReqCtx(c).WithLog("添加Job信息").Handle(jobApi.CreateJob) }) - updateJobLog := ctx.NewLogInfo("修改Job信息") job.PUT("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateJobLog).Handle(jobApi.UpdateJob) + ginx.NewReqCtx(c).WithLog("修改Job信息").Handle(jobApi.UpdateJob) }) - deleteJobLog := ctx.NewLogInfo("删除Job信息") job.DELETE(":jobId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteJobLog).Handle(jobApi.DeleteJob) + ginx.NewReqCtx(c).WithLog("删除Job信息").Handle(jobApi.DeleteJob) }) - stopJobLog := ctx.NewLogInfo("停止一个job") job.GET("/stop/:jobId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(stopJobLog).Handle(jobApi.StopJobForService) + ginx.NewReqCtx(c).WithLog("停止一个job").Handle(jobApi.StopJobForService) }) - starteJobLog := ctx.NewLogInfo("开启一个job") job.GET("/start/:jobId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(starteJobLog).Handle(jobApi.StartJobForService) + ginx.NewReqCtx(c).WithLog("开启一个job").Handle(jobApi.StartJobForService) }) - updateStatusJobLog := ctx.NewLogInfo("修改状态") job.PUT("/changeStatus", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateStatusJobLog).Handle(jobApi.UpdateStatusJob) + ginx.NewReqCtx(c).WithLog("修改状态").Handle(jobApi.UpdateStatusJob) }) } diff --git a/apps/log/api/log_job.go b/apps/log/api/log_job.go index cd46b2b..717f614 100644 --- a/apps/log/api/log_job.go +++ b/apps/log/api/log_job.go @@ -3,7 +3,6 @@ package api import ( "pandax/apps/log/entity" "pandax/apps/log/services" - "pandax/base/ctx" "pandax/base/ginx" "pandax/base/utils" ) @@ -23,7 +22,7 @@ type LogJobApi struct { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /log/logJob/list [get] // @Security -func (l *LogJobApi) GetJobLogList(rc *ctx.ReqCtx) { +func (l *LogJobApi) GetJobLogList(rc *ginx.ReqCtx) { pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) name := rc.GinCtx.Query("name") @@ -46,7 +45,7 @@ func (l *LogJobApi) GetJobLogList(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /log/logJob/{logId} [delete] -func (l *LogJobApi) DeleteJobLog(rc *ctx.ReqCtx) { +func (l *LogJobApi) DeleteJobLog(rc *ginx.ReqCtx) { logIds := rc.GinCtx.Param("logId") group := utils.IdsStrToIdsIntGroup(logIds) l.LogJobApp.Delete(group) @@ -58,6 +57,6 @@ func (l *LogJobApi) DeleteJobLog(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /log/logJob/all [delete] -func (l *LogJobApi) DeleteAll(rc *ctx.ReqCtx) { +func (l *LogJobApi) DeleteAll(rc *ginx.ReqCtx) { l.LogJobApp.DeleteAll() } diff --git a/apps/log/api/log_login.go b/apps/log/api/log_login.go index 765dd6c..af4fee4 100644 --- a/apps/log/api/log_login.go +++ b/apps/log/api/log_login.go @@ -3,7 +3,6 @@ package api import ( "pandax/apps/log/entity" "pandax/apps/log/services" - "pandax/base/ctx" "pandax/base/ginx" "pandax/base/utils" ) @@ -22,7 +21,7 @@ type LogLoginApi struct { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /log/logLogin/list [get] // @Security -func (l *LogLoginApi) GetLoginLogList(rc *ctx.ReqCtx) { +func (l *LogLoginApi) GetLoginLogList(rc *ginx.ReqCtx) { pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) loginLocation := rc.GinCtx.Query("loginLocation") @@ -43,7 +42,7 @@ func (l *LogLoginApi) GetLoginLogList(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /log/logLogin/{infoId} [get] // @Security -func (l *LogLoginApi) GetLoginLog(rc *ctx.ReqCtx) { +func (l *LogLoginApi) GetLoginLog(rc *ginx.ReqCtx) { infoId := ginx.PathParamInt(rc.GinCtx, rc.GinCtx.Param("infoId")) rc.ResData = l.LogLoginApp.FindOne(int64(infoId)) } @@ -58,7 +57,7 @@ func (l *LogLoginApi) GetLoginLog(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /log/logLogin [put] // @Security X-TOKEN -func (l *LogLoginApi) UpdateLoginLog(rc *ctx.ReqCtx) { +func (l *LogLoginApi) UpdateLoginLog(rc *ginx.ReqCtx) { var log entity.LogLogin ginx.BindJsonAndValid(rc.GinCtx, &log) l.LogLoginApp.Update(log) @@ -71,7 +70,7 @@ func (l *LogLoginApi) UpdateLoginLog(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /log/logLogin/{infoId} [delete] -func (l *LogLoginApi) DeleteLoginLog(rc *ctx.ReqCtx) { +func (l *LogLoginApi) DeleteLoginLog(rc *ginx.ReqCtx) { infoIds := rc.GinCtx.Param("infoId") group := utils.IdsStrToIdsIntGroup(infoIds) l.LogLoginApp.Delete(group) @@ -83,6 +82,6 @@ func (l *LogLoginApi) DeleteLoginLog(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /log/logLogin/all [delete] -func (l *LogLoginApi) DeleteAll(rc *ctx.ReqCtx) { +func (l *LogLoginApi) DeleteAll(rc *ginx.ReqCtx) { l.LogLoginApp.DeleteAll() } diff --git a/apps/log/api/log_oper.go b/apps/log/api/log_oper.go index 0658d49..a2ba251 100644 --- a/apps/log/api/log_oper.go +++ b/apps/log/api/log_oper.go @@ -4,7 +4,6 @@ import ( "log" "pandax/apps/log/entity" "pandax/apps/log/services" - "pandax/base/ctx" "pandax/base/ginx" "pandax/base/utils" ) @@ -23,7 +22,7 @@ type LogOperApi struct { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /log/logOper/list [get] // @Security -func (l *LogOperApi) GetOperLogList(rc *ctx.ReqCtx) { +func (l *LogOperApi) GetOperLogList(rc *ginx.ReqCtx) { pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) @@ -46,7 +45,7 @@ func (l *LogOperApi) GetOperLogList(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /log/logOper/{operId} [get] // @Security -func (l *LogOperApi) GetOperLog(rc *ctx.ReqCtx) { +func (l *LogOperApi) GetOperLog(rc *ginx.ReqCtx) { operId := ginx.PathParamInt(rc.GinCtx, rc.GinCtx.Param("operId")) rc.ResData = l.LogOperApp.FindOne(int64(operId)) } @@ -58,7 +57,7 @@ func (l *LogOperApi) GetOperLog(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /log/logOper/{operId} [delete] -func (l *LogOperApi) DeleteOperLog(rc *ctx.ReqCtx) { +func (l *LogOperApi) DeleteOperLog(rc *ginx.ReqCtx) { operIds := rc.GinCtx.Param("operId") group := utils.IdsStrToIdsIntGroup(operIds) log.Println("group", group) @@ -71,6 +70,6 @@ func (l *LogOperApi) DeleteOperLog(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /log/logOper/all [delete] -func (l *LogOperApi) DeleteAll(rc *ctx.ReqCtx) { +func (l *LogOperApi) DeleteAll(rc *ginx.ReqCtx) { l.LogOperApp.DeleteAll() } diff --git a/apps/log/router/log.go b/apps/log/router/log.go index c80b574..3afc856 100644 --- a/apps/log/router/log.go +++ b/apps/log/router/log.go @@ -4,7 +4,7 @@ import ( "github.com/gin-gonic/gin" "pandax/apps/log/api" "pandax/apps/log/services" - "pandax/base/ctx" + "pandax/base/ginx" ) func InitLogRouter(router *gin.RouterGroup) { @@ -14,29 +14,24 @@ func InitLogRouter(router *gin.RouterGroup) { } logLogin := router.Group("logLogin") - logLoginListLog := ctx.NewLogInfo("获取登录日志列表") logLogin.GET("list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(logLoginListLog).Handle(login.GetLoginLogList) + ginx.NewReqCtx(c).WithLog("获取登录日志列表").Handle(login.GetLoginLogList) }) - getLogLoginLog := ctx.NewLogInfo("获取登录日志信息") logLogin.GET(":infoId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(getLogLoginLog).Handle(login.GetLoginLog) + ginx.NewReqCtx(c).WithLog("获取登录日志信息").Handle(login.GetLoginLog) }) - updateLogLoginLog := ctx.NewLogInfo("修改登录日志信息") logLogin.PUT("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateLogLoginLog).Handle(login.UpdateLoginLog) + ginx.NewReqCtx(c).WithLog("修改登录日志信息").Handle(login.UpdateLoginLog) }) - deleteLogLoginAllLog := ctx.NewLogInfo("清空登录日志信息") logLogin.DELETE("all", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteLogLoginAllLog).Handle(login.DeleteAll) + ginx.NewReqCtx(c).WithLog("清空登录日志信息").Handle(login.DeleteAll) }) - deleteLogLoginLog := ctx.NewLogInfo("删除登录日志信息") logLogin.DELETE(":infoId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteLogLoginLog).Handle(login.DeleteLoginLog) + ginx.NewReqCtx(c).WithLog("删除登录日志信息").Handle(login.DeleteLoginLog) }) // 操作日志 @@ -45,24 +40,20 @@ func InitLogRouter(router *gin.RouterGroup) { } logOper := router.Group("logOper") - logOperListLog := ctx.NewLogInfo("获取操作日志列表") logOper.GET("list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(logOperListLog).Handle(oper.GetOperLogList) + ginx.NewReqCtx(c).WithLog("获取操作日志列表").Handle(oper.GetOperLogList) }) - getLogOperLog := ctx.NewLogInfo("获取操作日志信息") logOper.GET(":operId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(getLogOperLog).Handle(oper.GetOperLog) + ginx.NewReqCtx(c).WithLog("获取操作日志信息").Handle(oper.GetOperLog) }) - deleteLogOperAllLog := ctx.NewLogInfo("清空操作日志信息") logOper.DELETE("all", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteLogOperAllLog).Handle(oper.DeleteAll) + ginx.NewReqCtx(c).WithLog("清空操作日志信息").Handle(oper.DeleteAll) }) - deleteLogOperLog := ctx.NewLogInfo("删除操作日志信息") logOper.DELETE(":operId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteLogOperLog).Handle(oper.DeleteOperLog) + ginx.NewReqCtx(c).WithLog("删除操作日志信息").Handle(oper.DeleteOperLog) }) // Job日志 @@ -71,18 +62,15 @@ func InitLogRouter(router *gin.RouterGroup) { } logJob := router.Group("logJob") - logJobListLog := ctx.NewLogInfo("获取操作日志列表") logJob.GET("list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(logJobListLog).Handle(job.GetJobLogList) + ginx.NewReqCtx(c).WithLog("获取操作日志列表").Handle(job.GetJobLogList) }) - deleteLogJobAllLog := ctx.NewLogInfo("清空操作日志信息") logJob.DELETE("all", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteLogJobAllLog).Handle(job.DeleteAll) + ginx.NewReqCtx(c).WithLog("清空操作日志信息").Handle(job.DeleteAll) }) - deleteLogJobLog := ctx.NewLogInfo("删除操作日志信息") logJob.DELETE(":logId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteLogJobLog).Handle(job.DeleteJobLog) + ginx.NewReqCtx(c).WithLog("删除操作日志信息").Handle(job.DeleteJobLog) }) } diff --git a/apps/resource/api/email.go b/apps/resource/api/email.go index 88534fe..eab460a 100644 --- a/apps/resource/api/email.go +++ b/apps/resource/api/email.go @@ -5,7 +5,6 @@ import ( "pandax/apps/resource/entity" "pandax/apps/resource/services" "pandax/base/biz" - "pandax/base/ctx" "pandax/base/ginx" email "pandax/base/mail" "pandax/base/utils" @@ -30,7 +29,7 @@ type ResEmailsApi struct { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /resource/email/list [get] // @Security -func (p *ResEmailsApi) GetResEmailsList(rc *ctx.ReqCtx) { +func (p *ResEmailsApi) GetResEmailsList(rc *ginx.ReqCtx) { pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) @@ -60,7 +59,7 @@ func (p *ResEmailsApi) GetResEmailsList(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /resource/email/{mailId} [get] // @Security -func (p *ResEmailsApi) GetResEmails(rc *ctx.ReqCtx) { +func (p *ResEmailsApi) GetResEmails(rc *ginx.ReqCtx) { mailId := ginx.PathParamInt(rc.GinCtx, "mailId") p.ResEmailsApp.FindOne(int64(mailId)) } @@ -75,7 +74,7 @@ func (p *ResEmailsApi) GetResEmails(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /resource/email [post] // @Security X-TOKEN -func (p *ResEmailsApi) InsertResEmails(rc *ctx.ReqCtx) { +func (p *ResEmailsApi) InsertResEmails(rc *ginx.ReqCtx) { var data entity.ResEmail ginx.BindJsonAndValid(rc.GinCtx, &data) @@ -92,7 +91,7 @@ func (p *ResEmailsApi) InsertResEmails(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /resource/email [put] // @Security X-TOKEN -func (p *ResEmailsApi) UpdateResEmails(rc *ctx.ReqCtx) { +func (p *ResEmailsApi) UpdateResEmails(rc *ginx.ReqCtx) { var data entity.ResEmail ginx.BindJsonAndValid(rc.GinCtx, &data) if utils.ISDdmMail(data.From) { @@ -111,7 +110,7 @@ func (p *ResEmailsApi) UpdateResEmails(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /resource/email/{mailId} [delete] -func (p *ResEmailsApi) DeleteResEmails(rc *ctx.ReqCtx) { +func (p *ResEmailsApi) DeleteResEmails(rc *ginx.ReqCtx) { mailId := rc.GinCtx.Param("mailId") mailIds := utils.IdsStrToIdsIntGroup(mailId) @@ -128,7 +127,7 @@ func (p *ResEmailsApi) DeleteResEmails(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /resource/oss [put] // @Security X-TOKEN -func (p *ResEmailsApi) UpdateMailStatus(rc *ctx.ReqCtx) { +func (p *ResEmailsApi) UpdateMailStatus(rc *ginx.ReqCtx) { var data entity.ResEmail ginx.BindJsonAndValid(rc.GinCtx, &data) @@ -145,7 +144,7 @@ func (p *ResEmailsApi) UpdateMailStatus(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /resource/email/debugMail [post] // @Security X-TOKEN -func (p *ResEmailsApi) DebugMail(rc *ctx.ReqCtx) { +func (p *ResEmailsApi) DebugMail(rc *ginx.ReqCtx) { var data from.SendMail ginx.BindJsonAndValid(rc.GinCtx, &data) diff --git a/apps/resource/api/oss.go b/apps/resource/api/oss.go index 8053110..c7f318f 100644 --- a/apps/resource/api/oss.go +++ b/apps/resource/api/oss.go @@ -5,7 +5,6 @@ import ( "pandax/apps/resource/entity" "pandax/apps/resource/services" "pandax/base/biz" - "pandax/base/ctx" "pandax/base/ginx" "pandax/base/oss" "pandax/base/utils" @@ -32,7 +31,7 @@ type ResOssesApi struct { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /resource/oss/list [get] // @Security -func (p *ResOssesApi) GetResOssesList(rc *ctx.ReqCtx) { +func (p *ResOssesApi) GetResOssesList(rc *ginx.ReqCtx) { pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) @@ -63,7 +62,7 @@ func (p *ResOssesApi) GetResOssesList(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /resource/oss/{ossId} [get] // @Security -func (p *ResOssesApi) GetResOsses(rc *ctx.ReqCtx) { +func (p *ResOssesApi) GetResOsses(rc *ginx.ReqCtx) { ossId := ginx.PathParamInt(rc.GinCtx, "ossId") p.ResOssesApp.FindOne(int64(ossId)) } @@ -78,7 +77,7 @@ func (p *ResOssesApi) GetResOsses(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /resource/oss [post] // @Security X-TOKEN -func (p *ResOssesApi) InsertResOsses(rc *ctx.ReqCtx) { +func (p *ResOssesApi) InsertResOsses(rc *ginx.ReqCtx) { var data entity.ResOss ginx.BindJsonAndValid(rc.GinCtx, &data) @@ -95,7 +94,7 @@ func (p *ResOssesApi) InsertResOsses(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /resource/oss [put] // @Security X-TOKEN -func (p *ResOssesApi) UpdateResOsses(rc *ctx.ReqCtx) { +func (p *ResOssesApi) UpdateResOsses(rc *ginx.ReqCtx) { var data entity.ResOss ginx.BindJsonAndValid(rc.GinCtx, &data) if utils.IsDdmKey(data.AccessKey) { @@ -114,7 +113,7 @@ func (p *ResOssesApi) UpdateResOsses(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /resource/oss/{ossId} [delete] -func (p *ResOssesApi) DeleteResOsses(rc *ctx.ReqCtx) { +func (p *ResOssesApi) DeleteResOsses(rc *ginx.ReqCtx) { ossId := rc.GinCtx.Param("ossId") ossIds := utils.IdsStrToIdsIntGroup(ossId) @@ -127,7 +126,7 @@ func (p *ResOssesApi) DeleteResOsses(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /resource/oss/uploadFile [post] -func (p *ResOssesApi) UplaodResOsses(rc *ctx.ReqCtx) { +func (p *ResOssesApi) UplaodResOsses(rc *ginx.ReqCtx) { file, _ := rc.GinCtx.FormFile("file") ossCode, _ := rc.GinCtx.GetQuery("ossCode") list := p.ResOssesApp.FindList(entity.ResOss{OssCode: ossCode}) @@ -151,7 +150,7 @@ func (p *ResOssesApi) UplaodResOsses(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /resource/oss [put] // @Security X-TOKEN -func (p *ResOssesApi) UpdateOssStatus(rc *ctx.ReqCtx) { +func (p *ResOssesApi) UpdateOssStatus(rc *ginx.ReqCtx) { var data entity.ResOss ginx.BindJsonAndValid(rc.GinCtx, &data) diff --git a/apps/resource/router/email.go b/apps/resource/router/email.go index c5fa882..e6493a7 100644 --- a/apps/resource/router/email.go +++ b/apps/resource/router/email.go @@ -4,7 +4,7 @@ import ( "github.com/gin-gonic/gin" "pandax/apps/resource/api" "pandax/apps/resource/services" - "pandax/base/ctx" + "pandax/base/ginx" ) /** @@ -19,38 +19,31 @@ func InitResEmailsRouter(router *gin.RouterGroup) { } routerGroup := router.Group("email") - ResEmailsListLog := ctx.NewLogInfo("获取ResEmails分页列表") routerGroup.GET("list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(ResEmailsListLog).Handle(s.GetResEmailsList) + ginx.NewReqCtx(c).WithLog("获取ResEmails分页列表").Handle(s.GetResEmailsList) }) - ResEmailsLog := ctx.NewLogInfo("获取ResEmails信息") routerGroup.GET(":mailId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(ResEmailsLog).Handle(s.GetResEmails) + ginx.NewReqCtx(c).WithLog("获取ResEmails信息").Handle(s.GetResEmails) }) - insertResEmailsLog := ctx.NewLogInfo("添加ResEmails信息") routerGroup.POST("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(insertResEmailsLog).Handle(s.InsertResEmails) + ginx.NewReqCtx(c).WithLog("添加ResEmails信息").Handle(s.InsertResEmails) }) - updateResEmailsLog := ctx.NewLogInfo("修改ResEmails信息") routerGroup.PUT("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateResEmailsLog).Handle(s.UpdateResEmails) + ginx.NewReqCtx(c).WithLog("修改ResEmails信息").Handle(s.UpdateResEmails) }) - deleteResEmailsLog := ctx.NewLogInfo("删除ResEmails信息") routerGroup.DELETE(":mailId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteResEmailsLog).Handle(s.DeleteResEmails) + ginx.NewReqCtx(c).WithLog("删除ResEmails信息").Handle(s.DeleteResEmails) }) - updateStatusEmailLog := ctx.NewLogInfo("修改状态") routerGroup.PUT("changeStatus", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateStatusEmailLog).Handle(s.UpdateMailStatus) + ginx.NewReqCtx(c).WithLog("修改状态").Handle(s.UpdateMailStatus) }) - debugMailEmailLog := ctx.NewLogInfo("修改状态") routerGroup.POST("debugMail", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(debugMailEmailLog).Handle(s.DebugMail) + ginx.NewReqCtx(c).WithLog("修改状态").Handle(s.DebugMail) }) } diff --git a/apps/resource/router/oss.go b/apps/resource/router/oss.go index 8e87247..4b5567e 100644 --- a/apps/resource/router/oss.go +++ b/apps/resource/router/oss.go @@ -4,7 +4,7 @@ import ( "github.com/gin-gonic/gin" "pandax/apps/resource/api" "pandax/apps/resource/services" - "pandax/base/ctx" + "pandax/base/ginx" ) /** @@ -19,38 +19,31 @@ func InitResOssRouter(router *gin.RouterGroup) { } routerGroup := router.Group("oss") - ResOssesListLog := ctx.NewLogInfo("获取ResOsses分页列表") routerGroup.GET("list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(ResOssesListLog).Handle(s.GetResOssesList) + ginx.NewReqCtx(c).WithLog("获取ResOsses分页列表").Handle(s.GetResOssesList) }) - ResOssesLog := ctx.NewLogInfo("获取ResOsses信息") routerGroup.GET(":ossId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(ResOssesLog).Handle(s.GetResOsses) + ginx.NewReqCtx(c).WithLog("获取ResOsses信息").Handle(s.GetResOsses) }) - insertResOssesLog := ctx.NewLogInfo("添加ResOsses信息") routerGroup.POST("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(insertResOssesLog).Handle(s.InsertResOsses) + ginx.NewReqCtx(c).WithLog("添加ResOsses信息").Handle(s.InsertResOsses) }) - updateResOssesLog := ctx.NewLogInfo("修改ResOsses信息") routerGroup.PUT("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateResOssesLog).Handle(s.UpdateResOsses) + ginx.NewReqCtx(c).WithLog("修改ResOsses信息").Handle(s.UpdateResOsses) }) - deleteResOssesLog := ctx.NewLogInfo("删除ResOsses信息") routerGroup.DELETE(":ossId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteResOssesLog).Handle(s.DeleteResOsses) + ginx.NewReqCtx(c).WithLog("删除ResOsses信息").Handle(s.DeleteResOsses) }) - uplaodResOssesLog := ctx.NewLogInfo("测试文件上传") routerGroup.POST("uploadFile", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(uplaodResOssesLog).Handle(s.UplaodResOsses) + ginx.NewReqCtx(c).WithLog("测试文件上传").Handle(s.UplaodResOsses) }) - updateStatusOssLog := ctx.NewLogInfo("修改状态") routerGroup.PUT("/changeStatus", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateStatusOssLog).Handle(s.UpdateOssStatus) + ginx.NewReqCtx(c).WithLog("修改状态").Handle(s.UpdateOssStatus) }) } diff --git a/apps/system/api/api.go b/apps/system/api/api.go index 10244ea..390a755 100644 --- a/apps/system/api/api.go +++ b/apps/system/api/api.go @@ -5,7 +5,6 @@ import ( entity "pandax/apps/system/entity" services "pandax/apps/system/services" "pandax/base/casbin" - "pandax/base/ctx" "pandax/base/ginx" "pandax/base/utils" "strconv" @@ -23,7 +22,7 @@ type SystemApiApi struct { // @Param data body entity.SysApi true "api路径, api中文描述, api组, 方法" // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" // @Router /system/api [post] -func (s *SystemApiApi) CreateApi(rc *ctx.ReqCtx) { +func (s *SystemApiApi) CreateApi(rc *ginx.ReqCtx) { var api entity.SysApi ginx.BindJsonAndValid(rc.GinCtx, &api) log.Println(api) @@ -37,7 +36,7 @@ func (s *SystemApiApi) CreateApi(rc *ctx.ReqCtx) { // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /system/api/{id} [delete] -func (s *SystemApiApi) DeleteApi(rc *ctx.ReqCtx) { +func (s *SystemApiApi) DeleteApi(rc *ginx.ReqCtx) { ids := rc.GinCtx.Param("id") s.ApiApp.Delete(utils.IdsStrToIdsIntGroup(ids)) } @@ -55,7 +54,7 @@ func (s *SystemApiApi) DeleteApi(rc *ctx.ReqCtx) { // @Param pageNum query int false "页码" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /system/api/list [get] -func (s *SystemApiApi) GetApiList(rc *ctx.ReqCtx) { +func (s *SystemApiApi) GetApiList(rc *ginx.ReqCtx) { pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) path := rc.GinCtx.Query("path") @@ -80,7 +79,7 @@ func (s *SystemApiApi) GetApiList(rc *ctx.ReqCtx) { // @Param id path int true "根据id获取api" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /system/api/{id} [get] -func (s *SystemApiApi) GetApiById(rc *ctx.ReqCtx) { +func (s *SystemApiApi) GetApiById(rc *ginx.ReqCtx) { id := ginx.QueryInt(rc.GinCtx, "id", 0) rc.ResData = s.ApiApp.FindOne(int64(id)) @@ -94,7 +93,7 @@ func (s *SystemApiApi) GetApiById(rc *ctx.ReqCtx) { // @Param data body entity.SysApi true "api路径, api中文描述, api组, 方法" // @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}" // @Router /api/api [put] -func (s *SystemApiApi) UpdateApi(rc *ctx.ReqCtx) { +func (s *SystemApiApi) UpdateApi(rc *ginx.ReqCtx) { var api entity.SysApi ginx.BindJsonAndValid(rc.GinCtx, &api) s.ApiApp.Update(api) @@ -107,7 +106,7 @@ func (s *SystemApiApi) UpdateApi(rc *ctx.ReqCtx) { // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /system/api/all [get] -func (s *SystemApiApi) GetAllApis(rc *ctx.ReqCtx) { +func (s *SystemApiApi) GetAllApis(rc *ginx.ReqCtx) { rc.ResData = s.ApiApp.FindList(entity.SysApi{}) } @@ -119,7 +118,7 @@ func (s *SystemApiApi) GetAllApis(rc *ctx.ReqCtx) { // @Param roleKey query string true "权限id, 权限模型列表" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /casbin/getPolicyPathByRoleId [get] -func (s *SystemApiApi) GetPolicyPathByRoleId(rc *ctx.ReqCtx) { +func (s *SystemApiApi) GetPolicyPathByRoleId(rc *ginx.ReqCtx) { roleKey := rc.GinCtx.Query("roleKey") tenantId := strconv.Itoa(int(rc.LoginAccount.TenantId)) rc.ResData = casbin.GetPolicyPathByRoleId(tenantId, roleKey) diff --git a/apps/system/api/config.go b/apps/system/api/config.go index 53183ad..b1e7594 100644 --- a/apps/system/api/config.go +++ b/apps/system/api/config.go @@ -4,7 +4,6 @@ import ( entity "pandax/apps/system/entity" services "pandax/apps/system/services" "pandax/base/biz" - "pandax/base/ctx" "pandax/base/ginx" "pandax/base/utils" ) @@ -24,7 +23,7 @@ type ConfigApi struct { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/config [get] // @Security -func (p *ConfigApi) GetConfigList(rc *ctx.ReqCtx) { +func (p *ConfigApi) GetConfigList(rc *ginx.ReqCtx) { pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) configName := rc.GinCtx.Query("configName") @@ -48,7 +47,7 @@ func (p *ConfigApi) GetConfigList(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/config/configKey [get] // @Security -func (p *ConfigApi) GetConfigListByKey(rc *ctx.ReqCtx) { +func (p *ConfigApi) GetConfigListByKey(rc *ginx.ReqCtx) { configKey := rc.GinCtx.Query("configKey") biz.IsTrue(configKey != "", "请传入配置Key") rc.ResData = p.ConfigApp.FindList(entity.SysConfig{ConfigKey: configKey}) @@ -61,7 +60,7 @@ func (p *ConfigApi) GetConfigListByKey(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/config/{configId} [get] // @Security -func (p *ConfigApi) GetConfig(rc *ctx.ReqCtx) { +func (p *ConfigApi) GetConfig(rc *ginx.ReqCtx) { id := ginx.PathParamInt(rc.GinCtx, "configId") p.ConfigApp.FindOne(int64(id)) } @@ -76,7 +75,7 @@ func (p *ConfigApi) GetConfig(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/config [post] // @Security X-TOKEN -func (p *ConfigApi) InsertConfig(rc *ctx.ReqCtx) { +func (p *ConfigApi) InsertConfig(rc *ginx.ReqCtx) { var config entity.SysConfig ginx.BindJsonAndValid(rc.GinCtx, &config) @@ -93,7 +92,7 @@ func (p *ConfigApi) InsertConfig(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/config [put] // @Security X-TOKEN -func (p *ConfigApi) UpdateConfig(rc *ctx.ReqCtx) { +func (p *ConfigApi) UpdateConfig(rc *ginx.ReqCtx) { var post entity.SysConfig ginx.BindJsonAndValid(rc.GinCtx, &post) p.ConfigApp.Update(post) @@ -106,7 +105,7 @@ func (p *ConfigApi) UpdateConfig(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /system/config/{configId} [delete] -func (p *ConfigApi) DeleteConfig(rc *ctx.ReqCtx) { +func (p *ConfigApi) DeleteConfig(rc *ginx.ReqCtx) { configId := rc.GinCtx.Param("configId") p.ConfigApp.Delete(utils.IdsStrToIdsIntGroup(configId)) } diff --git a/apps/system/api/dept.go b/apps/system/api/dept.go index 8aaf2d1..d4ded1c 100644 --- a/apps/system/api/dept.go +++ b/apps/system/api/dept.go @@ -6,7 +6,6 @@ import ( entity "pandax/apps/system/entity" services "pandax/apps/system/services" "pandax/base/biz" - "pandax/base/ctx" "pandax/base/ginx" "pandax/base/utils" "pandax/pkg/global" @@ -26,13 +25,12 @@ type DeptApi struct { // @Success 200 {string} string "{"code": 400, "message": "抱歉未找到相关信息"}" // @Router /system/menu/menuTreRoleSelect/{roleId} [get] // @Security X-TOKEN -func (m *DeptApi) GetDeptTreeRoleSelect(rc *ctx.ReqCtx) { +func (m *DeptApi) GetDeptTreeRoleSelect(rc *ginx.ReqCtx) { roleId := ginx.PathParamInt(rc.GinCtx, "roleId") var dept entity.SysDept if !IsTenantAdmin(rc.LoginAccount.TenantId) { dept.TenantId = rc.LoginAccount.TenantId } - result := m.DeptApp.SelectDeptLable(dept) deptIds := make([]int64, 0) @@ -54,7 +52,7 @@ func (m *DeptApi) GetDeptTreeRoleSelect(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/dept/deptList [get] // @Security -func (a *DeptApi) GetDeptList(rc *ctx.ReqCtx) { +func (a *DeptApi) GetDeptList(rc *ginx.ReqCtx) { //pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) //pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) deptName := rc.GinCtx.Query("deptName") @@ -77,7 +75,7 @@ func (a *DeptApi) GetDeptList(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/dept/ordinaryDeptLis [get] // @Security -func (a *DeptApi) GetOrdinaryDeptList(rc *ctx.ReqCtx) { +func (a *DeptApi) GetOrdinaryDeptList(rc *ginx.ReqCtx) { var dept entity.SysDept if !IsTenantAdmin(rc.LoginAccount.TenantId) { dept.TenantId = rc.LoginAccount.TenantId @@ -95,7 +93,7 @@ func (a *DeptApi) GetOrdinaryDeptList(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/dept/deptTree [get] // @Security -func (a *DeptApi) GetDeptTree(rc *ctx.ReqCtx) { +func (a *DeptApi) GetDeptTree(rc *ginx.ReqCtx) { deptName := rc.GinCtx.Query("deptName") status := rc.GinCtx.Query("status") deptId := ginx.QueryInt(rc.GinCtx, "deptId", 0) @@ -113,7 +111,7 @@ func (a *DeptApi) GetDeptTree(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/dept/{deptId} [get] // @Security -func (a *DeptApi) GetDept(rc *ctx.ReqCtx) { +func (a *DeptApi) GetDept(rc *ginx.ReqCtx) { deptId := ginx.PathParamInt(rc.GinCtx, "deptId") rc.ResData = a.DeptApp.FindOne(int64(deptId)) } @@ -128,7 +126,7 @@ func (a *DeptApi) GetDept(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/dept [post] // @Security Bearer -func (a *DeptApi) InsertDept(rc *ctx.ReqCtx) { +func (a *DeptApi) InsertDept(rc *ginx.ReqCtx) { var dept entity.SysDept g := rc.GinCtx ginx.BindJsonAndValid(g, &dept) @@ -147,7 +145,7 @@ func (a *DeptApi) InsertDept(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /system/dept [put] // @Security Bearer -func (a *DeptApi) UpdateDept(rc *ctx.ReqCtx) { +func (a *DeptApi) UpdateDept(rc *ginx.ReqCtx) { var dept entity.SysDept g := rc.GinCtx ginx.BindJsonAndValid(g, &dept) @@ -163,7 +161,7 @@ func (a *DeptApi) UpdateDept(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /system/dept/{deptId} [delete] -func (a *DeptApi) DeleteDept(rc *ctx.ReqCtx) { +func (a *DeptApi) DeleteDept(rc *ginx.ReqCtx) { deptId := rc.GinCtx.Param("deptId") deptIds := utils.IdsStrToIdsIntGroup(deptId) diff --git a/apps/system/api/dict.go b/apps/system/api/dict.go index 1fbc8a1..21852bc 100644 --- a/apps/system/api/dict.go +++ b/apps/system/api/dict.go @@ -5,7 +5,6 @@ import ( entity "pandax/apps/system/entity" services "pandax/apps/system/services" "pandax/base/biz" - "pandax/base/ctx" "pandax/base/ginx" "pandax/base/utils" "pandax/pkg/global" @@ -27,7 +26,7 @@ type DictApi struct { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/dict/type/list [get] // @Security -func (p *DictApi) GetDictTypeList(rc *ctx.ReqCtx) { +func (p *DictApi) GetDictTypeList(rc *ginx.ReqCtx) { pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) status := rc.GinCtx.Query("status") @@ -50,7 +49,7 @@ func (p *DictApi) GetDictTypeList(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/dict/type/{dictId} [get] // @Security -func (p *DictApi) GetDictType(rc *ctx.ReqCtx) { +func (p *DictApi) GetDictType(rc *ginx.ReqCtx) { dictId := ginx.PathParamInt(rc.GinCtx, "dictId") p.DictType.FindOne(int64(dictId)) } @@ -65,7 +64,7 @@ func (p *DictApi) GetDictType(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/dict/type [post] // @Security X-TOKEN -func (p *DictApi) InsertDictType(rc *ctx.ReqCtx) { +func (p *DictApi) InsertDictType(rc *ginx.ReqCtx) { var dict entity.SysDictType ginx.BindJsonAndValid(rc.GinCtx, &dict) @@ -83,7 +82,7 @@ func (p *DictApi) InsertDictType(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/dict/type [put] // @Security X-TOKEN -func (p *DictApi) UpdateDictType(rc *ctx.ReqCtx) { +func (p *DictApi) UpdateDictType(rc *ginx.ReqCtx) { var dict entity.SysDictType ginx.BindJsonAndValid(rc.GinCtx, &dict) @@ -98,7 +97,7 @@ func (p *DictApi) UpdateDictType(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /system/dict/type/{dictId} [delete] -func (p *DictApi) DeleteDictType(rc *ctx.ReqCtx) { +func (p *DictApi) DeleteDictType(rc *ginx.ReqCtx) { dictId := rc.GinCtx.Param("dictId") dictIds := utils.IdsStrToIdsIntGroup(dictId) @@ -124,7 +123,7 @@ func (p *DictApi) DeleteDictType(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /system/dict/type/export [get] -func (p *DictApi) ExportDictType(rc *ctx.ReqCtx) { +func (p *DictApi) ExportDictType(rc *ginx.ReqCtx) { filename := rc.GinCtx.Query("filename") status := rc.GinCtx.Query("status") dictName := rc.GinCtx.Query("dictName") @@ -145,7 +144,7 @@ func (p *DictApi) ExportDictType(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/dict/data/list [get] // @Security -func (p *DictApi) GetDictDataList(rc *ctx.ReqCtx) { +func (p *DictApi) GetDictDataList(rc *ginx.ReqCtx) { dictLabel := rc.GinCtx.Query("dictLabel") dictType := rc.GinCtx.Query("dictType") status := rc.GinCtx.Query("status") @@ -159,7 +158,7 @@ func (p *DictApi) GetDictDataList(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/dict/data/type [get] // @Security -func (p *DictApi) GetDictDataListByDictType(rc *ctx.ReqCtx) { +func (p *DictApi) GetDictDataListByDictType(rc *ginx.ReqCtx) { dictType := rc.GinCtx.Query("dictType") biz.IsTrue(dictType != "", "请传入字典类型") rc.ResData = p.DictData.FindList(entity.SysDictData{DictType: dictType}) @@ -172,7 +171,7 @@ func (p *DictApi) GetDictDataListByDictType(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/dict/data/{dictCode} [get] // @Security -func (p *DictApi) GetDictData(rc *ctx.ReqCtx) { +func (p *DictApi) GetDictData(rc *ginx.ReqCtx) { dictCode := ginx.PathParamInt(rc.GinCtx, "dictCode") p.DictData.FindOne(int64(dictCode)) } @@ -187,7 +186,7 @@ func (p *DictApi) GetDictData(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/dict/data [post] // @Security X-TOKEN -func (p *DictApi) InsertDictData(rc *ctx.ReqCtx) { +func (p *DictApi) InsertDictData(rc *ginx.ReqCtx) { var data entity.SysDictData ginx.BindJsonAndValid(rc.GinCtx, &data) @@ -205,7 +204,7 @@ func (p *DictApi) InsertDictData(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/dict/data [put] // @Security X-TOKEN -func (p *DictApi) UpdateDictData(rc *ctx.ReqCtx) { +func (p *DictApi) UpdateDictData(rc *ginx.ReqCtx) { var data entity.SysDictData ginx.BindJsonAndValid(rc.GinCtx, &data) @@ -220,7 +219,7 @@ func (p *DictApi) UpdateDictData(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /system/dict/data/{dictCode} [delete] -func (p *DictApi) DeleteDictData(rc *ctx.ReqCtx) { +func (p *DictApi) DeleteDictData(rc *ginx.ReqCtx) { param := rc.GinCtx.Param("dictCode") p.DictData.Delete(utils.IdsStrToIdsIntGroup(param)) } diff --git a/apps/system/api/menu.go b/apps/system/api/menu.go index b346fbf..ffa00e2 100644 --- a/apps/system/api/menu.go +++ b/apps/system/api/menu.go @@ -4,7 +4,6 @@ import ( entity "pandax/apps/system/entity" services "pandax/apps/system/services" "pandax/base/biz" - "pandax/base/ctx" "pandax/base/ginx" ) @@ -23,7 +22,7 @@ type MenuApi struct { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/menu/menuTreSelect [get] // @Security X-TOKEN -func (m *MenuApi) GetMenuTreeSelect(rc *ctx.ReqCtx) { +func (m *MenuApi) GetMenuTreeSelect(rc *ginx.ReqCtx) { lable := m.MenuApp.SelectMenuLable(entity.SysMenu{}) rc.ResData = lable } @@ -35,7 +34,7 @@ func (m *MenuApi) GetMenuTreeSelect(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "抱歉未找到相关信息"}" // @Router /system/menu/menuRole [get] // @Security X-TOKEN -func (m *MenuApi) GetMenuRole(rc *ctx.ReqCtx) { +func (m *MenuApi) GetMenuRole(rc *ginx.ReqCtx) { roleKey := rc.GinCtx.Query("roleKey") biz.IsTrue(roleKey != "", "请传入角色Key") rc.ResData = Build(*m.MenuApp.SelectMenuRole(roleKey)) @@ -49,7 +48,7 @@ func (m *MenuApi) GetMenuRole(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "抱歉未找到相关信息"}" // @Router /system/menu/menuTreRoleSelect/{roleId} [get] // @Security X-TOKEN -func (m *MenuApi) GetMenuTreeRoleSelect(rc *ctx.ReqCtx) { +func (m *MenuApi) GetMenuTreeRoleSelect(rc *ginx.ReqCtx) { roleId := ginx.PathParamInt(rc.GinCtx, "roleId") result := m.MenuApp.SelectMenuLable(entity.SysMenu{}) @@ -71,7 +70,7 @@ func (m *MenuApi) GetMenuTreeRoleSelect(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "抱歉未找到相关信息"}" // @Router /system/menu/menuPaths [get] // @Security X-TOKEN -func (m *MenuApi) GetMenuPaths(rc *ctx.ReqCtx) { +func (m *MenuApi) GetMenuPaths(rc *ginx.ReqCtx) { roleKey := rc.GinCtx.Query("roleKey") biz.IsTrue(roleKey != "", "请传入角色Key") rc.ResData = m.RoleMenuApp.GetMenuPaths(entity.SysRoleMenu{RoleName: roleKey}) @@ -87,7 +86,7 @@ func (m *MenuApi) GetMenuPaths(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "抱歉未找到相关信息"}" // @Router /system/menu/menuList [get] // @Security Bearer -func (m *MenuApi) GetMenuList(rc *ctx.ReqCtx) { +func (m *MenuApi) GetMenuList(rc *ginx.ReqCtx) { menuName := rc.GinCtx.Query("menuName") status := rc.GinCtx.Query("status") @@ -107,7 +106,7 @@ func (m *MenuApi) GetMenuList(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "抱歉未找到相关信息"}" // @Router /system/menu/{menuId} [get] // @Security Bearer -func (m *MenuApi) GetMenu(rc *ctx.ReqCtx) { +func (m *MenuApi) GetMenu(rc *ginx.ReqCtx) { menuId := ginx.PathParamInt(rc.GinCtx, "menuId") rc.ResData = m.MenuApp.FindOne(int64(menuId)) @@ -121,7 +120,7 @@ func (m *MenuApi) GetMenu(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /system/menu [post] // @Security X-TOKEN -func (m *MenuApi) InsertMenu(rc *ctx.ReqCtx) { +func (m *MenuApi) InsertMenu(rc *ginx.ReqCtx) { var menu entity.SysMenu ginx.BindJsonAndValid(rc.GinCtx, &menu) menu.CreateBy = rc.LoginAccount.UserName @@ -142,7 +141,7 @@ func (m *MenuApi) InsertMenu(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": -1, "message": "修改失败"}" // @Router /system/menu [put] // @Security X-TOKEN -func (m *MenuApi) UpdateMenu(rc *ctx.ReqCtx) { +func (m *MenuApi) UpdateMenu(rc *ginx.ReqCtx) { var menu entity.SysMenu ginx.BindJsonAndValid(rc.GinCtx, &menu) menu.UpdateBy = rc.LoginAccount.UserName @@ -162,7 +161,7 @@ func (m *MenuApi) UpdateMenu(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /system/menu/{menuId} [delete] -func (m *MenuApi) DeleteMenu(rc *ctx.ReqCtx) { +func (m *MenuApi) DeleteMenu(rc *ginx.ReqCtx) { menuId := ginx.PathParamInt(rc.GinCtx, "menuId") m.MenuApp.Delete([]int64{int64(menuId)}) } diff --git a/apps/system/api/notice.go b/apps/system/api/notice.go index b5b7707..9945494 100644 --- a/apps/system/api/notice.go +++ b/apps/system/api/notice.go @@ -3,7 +3,6 @@ package api import ( "pandax/apps/system/entity" "pandax/apps/system/services" - "pandax/base/ctx" "pandax/base/ginx" "pandax/base/utils" "strings" @@ -24,7 +23,7 @@ type NoticeApi struct { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/post [get] // @Security -func (p *NoticeApi) GetNoticeList(rc *ctx.ReqCtx) { +func (p *NoticeApi) GetNoticeList(rc *ginx.ReqCtx) { pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) noticeType := rc.GinCtx.Query("noticeType") @@ -56,7 +55,7 @@ func (p *NoticeApi) GetNoticeList(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/notice [post] // @Security X-TOKEN -func (p *NoticeApi) InsertNotice(rc *ctx.ReqCtx) { +func (p *NoticeApi) InsertNotice(rc *ginx.ReqCtx) { var notice entity.SysNotice ginx.BindJsonAndValid(rc.GinCtx, ¬ice) notice.UserName = rc.LoginAccount.UserName @@ -73,7 +72,7 @@ func (p *NoticeApi) InsertNotice(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/notice [put] // @Security X-TOKEN -func (p *NoticeApi) UpdateNotice(rc *ctx.ReqCtx) { +func (p *NoticeApi) UpdateNotice(rc *ginx.ReqCtx) { var notice entity.SysNotice ginx.BindJsonAndValid(rc.GinCtx, ¬ice) @@ -87,7 +86,7 @@ func (p *NoticeApi) UpdateNotice(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /system/notice/{noticeId} [delete] -func (p *NoticeApi) DeleteNotice(rc *ctx.ReqCtx) { +func (p *NoticeApi) DeleteNotice(rc *ginx.ReqCtx) { noticeId := rc.GinCtx.Param("noticeId") noticeIds := utils.IdsStrToIdsIntGroup(noticeId) p.NoticeApp.Delete(noticeIds) diff --git a/apps/system/api/post.go b/apps/system/api/post.go index 710773b..8242d01 100644 --- a/apps/system/api/post.go +++ b/apps/system/api/post.go @@ -6,7 +6,6 @@ import ( "pandax/apps/system/entity" "pandax/apps/system/services" "pandax/base/biz" - "pandax/base/ctx" "pandax/base/ginx" "pandax/base/utils" "pandax/pkg/global" @@ -29,7 +28,7 @@ type PostApi struct { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/post [get] // @Security -func (p *PostApi) GetPostList(rc *ctx.ReqCtx) { +func (p *PostApi) GetPostList(rc *ginx.ReqCtx) { pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) @@ -59,7 +58,7 @@ func (p *PostApi) GetPostList(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/post/{postId} [get] // @Security -func (p *PostApi) GetPost(rc *ctx.ReqCtx) { +func (p *PostApi) GetPost(rc *ginx.ReqCtx) { postId := ginx.PathParamInt(rc.GinCtx, "postId") p.PostApp.FindOne(int64(postId)) } @@ -74,7 +73,7 @@ func (p *PostApi) GetPost(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/post [post] // @Security X-TOKEN -func (p *PostApi) InsertPost(rc *ctx.ReqCtx) { +func (p *PostApi) InsertPost(rc *ginx.ReqCtx) { var post entity.SysPost ginx.BindJsonAndValid(rc.GinCtx, &post) post.TenantId = rc.LoginAccount.TenantId @@ -92,7 +91,7 @@ func (p *PostApi) InsertPost(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/post [put] // @Security X-TOKEN -func (p *PostApi) UpdatePost(rc *ctx.ReqCtx) { +func (p *PostApi) UpdatePost(rc *ginx.ReqCtx) { var post entity.SysPost ginx.BindJsonAndValid(rc.GinCtx, &post) @@ -107,7 +106,7 @@ func (p *PostApi) UpdatePost(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /system/post/{postId} [delete] -func (p *PostApi) DeletePost(rc *ctx.ReqCtx) { +func (p *PostApi) DeletePost(rc *ginx.ReqCtx) { postId := rc.GinCtx.Param("postId") postIds := utils.IdsStrToIdsIntGroup(postId) diff --git a/apps/system/api/role.go b/apps/system/api/role.go index 98e4a50..e64ebe3 100644 --- a/apps/system/api/role.go +++ b/apps/system/api/role.go @@ -7,7 +7,6 @@ import ( services "pandax/apps/system/services" "pandax/base/biz" "pandax/base/casbin" - "pandax/base/ctx" "pandax/base/ginx" "pandax/base/utils" "pandax/pkg/global" @@ -32,7 +31,7 @@ type RoleApi struct { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/role/rolelist [get] // @Security -func (r *RoleApi) GetRoleList(rc *ctx.ReqCtx) { +func (r *RoleApi) GetRoleList(rc *ginx.ReqCtx) { pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) status := rc.GinCtx.Query("status") @@ -62,7 +61,7 @@ func (r *RoleApi) GetRoleList(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "抱歉未找到相关信息"}" // @Router /system/role [get] // @Security X-TOKEN -func (r *RoleApi) GetRole(rc *ctx.ReqCtx) { +func (r *RoleApi) GetRole(rc *ginx.ReqCtx) { roleId := ginx.PathParamInt(rc.GinCtx, "roleId") role := r.RoleApp.FindOne(int64(roleId)) role.MenuIds = r.RoleApp.GetRoleMeunId(entity.SysRole{RoleId: int64(roleId)}) @@ -79,7 +78,7 @@ func (r *RoleApi) GetRole(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/role [post] -func (r *RoleApi) InsertRole(rc *ctx.ReqCtx) { +func (r *RoleApi) InsertRole(rc *ginx.ReqCtx) { var role entity.SysRole ginx.BindJsonAndValid(rc.GinCtx, &role) role.CreateBy = rc.LoginAccount.UserName @@ -101,7 +100,7 @@ func (r *RoleApi) InsertRole(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "修改成功"}" // @Success 200 {string} string "{"code": 400, "message": "修改失败"}" // @Router /system/role [put] -func (r *RoleApi) UpdateRole(rc *ctx.ReqCtx) { +func (r *RoleApi) UpdateRole(rc *ginx.ReqCtx) { var role entity.SysRole ginx.BindJsonAndValid(rc.GinCtx, &role) role.UpdateBy = rc.LoginAccount.UserName @@ -125,7 +124,7 @@ func (r *RoleApi) UpdateRole(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "修改成功"}" // @Success 200 {string} string "{"code": 400, "message": "修改失败"}" // @Router /system/role/changeStatus [put] -func (r *RoleApi) UpdateRoleStatus(rc *ctx.ReqCtx) { +func (r *RoleApi) UpdateRoleStatus(rc *ginx.ReqCtx) { var role entity.SysRole ginx.BindJsonAndValid(rc.GinCtx, &role) role.UpdateBy = rc.LoginAccount.UserName @@ -142,7 +141,7 @@ func (r *RoleApi) UpdateRoleStatus(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "修改成功"}" // @Success 200 {string} string "{"code": 400, "message": "修改失败"}" // @Router /system/role/dataScope [put] -func (r *RoleApi) UpdateRoleDataScope(rc *ctx.ReqCtx) { +func (r *RoleApi) UpdateRoleDataScope(rc *ginx.ReqCtx) { var role entity.SysRole ginx.BindJsonAndValid(rc.GinCtx, &role) role.UpdateBy = rc.LoginAccount.UserName @@ -163,7 +162,7 @@ func (r *RoleApi) UpdateRoleDataScope(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /system/role/{roleId} [delete] -func (r *RoleApi) DeleteRole(rc *ctx.ReqCtx) { +func (r *RoleApi) DeleteRole(rc *ginx.ReqCtx) { roleId := rc.GinCtx.Param("roleId") roleIds := utils.IdsStrToIdsIntGroup(roleId) @@ -198,7 +197,7 @@ func (r *RoleApi) DeleteRole(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /system/dict/type/export [get] -func (p *RoleApi) ExportRole(rc *ctx.ReqCtx) { +func (p *RoleApi) ExportRole(rc *ginx.ReqCtx) { filename := rc.GinCtx.Query("filename") status := rc.GinCtx.Query("status") roleName := rc.GinCtx.Query("roleName") diff --git a/apps/system/api/system.go b/apps/system/api/system.go index 8d381e7..7c04897 100644 --- a/apps/system/api/system.go +++ b/apps/system/api/system.go @@ -7,7 +7,7 @@ import ( "github.com/kakuilan/kgo" "net/http" "pandax/base/biz" - "pandax/base/ctx" + "pandax/base/ginx" "pandax/base/ws" "runtime" ) @@ -71,8 +71,8 @@ func (s *System) ConnectWs(g *gin.Context) { panic(any(biz.NewBizErr("升级websocket失败"))) } // 权限校验 - rc := ctx.NewReqCtxWithGin(g) - if err = ctx.PermissionHandler(rc); err != nil { + rc := ginx.NewReqCtx(g) + if err = ginx.PermissionHandler(rc); err != nil { panic(any(biz.NewBizErr("没有权限"))) } diff --git a/apps/system/api/tenant.go b/apps/system/api/tenant.go index 4df1276..2f688f1 100644 --- a/apps/system/api/tenant.go +++ b/apps/system/api/tenant.go @@ -8,7 +8,6 @@ package api import ( "pandax/apps/system/entity" "pandax/apps/system/services" - "pandax/base/ctx" "pandax/base/ginx" "pandax/base/utils" ) @@ -24,7 +23,7 @@ type SysTenantsApi struct { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/tenant/list [get] // @Security -func (p *SysTenantsApi) GetSysTenantsList(rc *ctx.ReqCtx) { +func (p *SysTenantsApi) GetSysTenantsList(rc *ginx.ReqCtx) { data := entity.SysTenants{} pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) @@ -44,7 +43,7 @@ func (p *SysTenantsApi) GetSysTenantsList(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/tenant/lists [get] // @Security -func (p *SysTenantsApi) GetSysTenantsAll(rc *ctx.ReqCtx) { +func (p *SysTenantsApi) GetSysTenantsAll(rc *ginx.ReqCtx) { list := make([]entity.SysTenants, 0) if rc.LoginAccount.RoleKey == "admin" { data := entity.SysTenants{} @@ -62,7 +61,7 @@ func (p *SysTenantsApi) GetSysTenantsAll(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/tenant/{tenantId} [get] // @Security -func (p *SysTenantsApi) GetSysTenants(rc *ctx.ReqCtx) { +func (p *SysTenantsApi) GetSysTenants(rc *ginx.ReqCtx) { tenantId := ginx.PathParamInt(rc.GinCtx, "tenantId") p.SysTenantsApp.FindOne(int64(tenantId)) } @@ -77,7 +76,7 @@ func (p *SysTenantsApi) GetSysTenants(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/tenant [post] // @Security X-TOKEN -func (p *SysTenantsApi) InsertSysTenants(rc *ctx.ReqCtx) { +func (p *SysTenantsApi) InsertSysTenants(rc *ginx.ReqCtx) { var data entity.SysTenants ginx.BindJsonAndValid(rc.GinCtx, &data) @@ -94,7 +93,7 @@ func (p *SysTenantsApi) InsertSysTenants(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/tenant [put] // @Security X-TOKEN -func (p *SysTenantsApi) UpdateSysTenants(rc *ctx.ReqCtx) { +func (p *SysTenantsApi) UpdateSysTenants(rc *ginx.ReqCtx) { var data entity.SysTenants ginx.BindJsonAndValid(rc.GinCtx, &data) @@ -108,7 +107,7 @@ func (p *SysTenantsApi) UpdateSysTenants(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /system/tenant/{tenantId} [delete] -func (p *SysTenantsApi) DeleteSysTenants(rc *ctx.ReqCtx) { +func (p *SysTenantsApi) DeleteSysTenants(rc *ginx.ReqCtx) { tenantId := rc.GinCtx.Param("tenantId") tenantIds := utils.IdsStrToIdsIntGroup(tenantId) p.SysTenantsApp.Delete(tenantIds) diff --git a/apps/system/api/user.go b/apps/system/api/user.go index 74a16a2..cef899d 100644 --- a/apps/system/api/user.go +++ b/apps/system/api/user.go @@ -9,6 +9,7 @@ import ( "pandax/apps/system/api/form" "pandax/apps/system/api/vo" "pandax/apps/system/entity" + "pandax/base/token" logEntity "pandax/apps/log/entity" logServices "pandax/apps/log/services" @@ -16,7 +17,6 @@ import ( "pandax/apps/system/services" "pandax/base/biz" "pandax/base/captcha" - "pandax/base/ctx" "pandax/base/ginx" "pandax/base/utils" "pandax/pkg/global" @@ -49,9 +49,9 @@ func (u *UserApi) GenerateCaptcha(c *gin.Context) { // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"登陆成功"}" // @Router /system/user/refreshToken [get] -func (u *UserApi) RefreshToken(rc *ctx.ReqCtx) { +func (u *UserApi) RefreshToken(rc *ginx.ReqCtx) { tokenStr := rc.GinCtx.Request.Header.Get("X-TOKEN") - j := ctx.NewJWT("", []byte(global.Conf.Jwt.Key), jwt.SigningMethodHS256) + j := token.NewJWT("", []byte(global.Conf.Jwt.Key), jwt.SigningMethodHS256) token, err := j.RefreshToken(tokenStr) biz.ErrIsNil(err, "刷新token失败") rc.ResData = map[string]any{"token": token, "expire": time.Now().Unix() + global.Conf.Jwt.ExpireTime} @@ -63,15 +63,15 @@ func (u *UserApi) RefreshToken(rc *ctx.ReqCtx) { // @Param data body form.Login true "用户名, 密码, 验证码" // @Success 200 {string} string "{"success":true,"data":{},"msg":"登陆成功"}" // @Router /system/user/login [post] -func (u *UserApi) Login(rc *ctx.ReqCtx) { +func (u *UserApi) Login(rc *ginx.ReqCtx) { var l form.Login ginx.BindJsonAndValid(rc.GinCtx, &l) biz.IsTrue(captcha.Verify(l.CaptchaId, l.Captcha), "验证码认证失败") login := u.UserApp.Login(entity.Login{Username: l.Username, Password: l.Password}) role := u.RoleApp.FindOne(login.RoleId) - j := ctx.NewJWT("", []byte(global.Conf.Jwt.Key), jwt.SigningMethodHS256) - token, err := j.CreateToken(ctx.Claims{ + j := token.NewJWT("", []byte(global.Conf.Jwt.Key), jwt.SigningMethodHS256) + token, err := j.CreateToken(token.Claims{ UserId: login.UserId, TenantId: login.TenantId, UserName: login.Username, @@ -115,7 +115,7 @@ func (u *UserApi) Login(rc *ctx.ReqCtx) { // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"成功"}" // @Router /system/user/auth [get] -func (u *UserApi) Auth(rc *ctx.ReqCtx) { +func (u *UserApi) Auth(rc *ginx.ReqCtx) { userName := rc.GinCtx.Query("username") biz.NotEmpty(userName, "用户名必传") var user entity.SysUser @@ -139,7 +139,7 @@ func (u *UserApi) Auth(rc *ctx.ReqCtx) { // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"登陆成功"}" // @Router /system/user/logout [post] -func (u *UserApi) LogOut(rc *ctx.ReqCtx) { +func (u *UserApi) LogOut(rc *ginx.ReqCtx) { var loginLog logEntity.LogLogin ua := user_agent.New(rc.GinCtx.Request.UserAgent()) loginLog.Ipaddr = rc.GinCtx.ClientIP() @@ -167,7 +167,7 @@ func (u *UserApi) LogOut(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}" // @Router /system/user/sysUserList [get] // @Security X-TOKEN -func (u *UserApi) GetSysUserList(rc *ctx.ReqCtx) { +func (u *UserApi) GetSysUserList(rc *ginx.ReqCtx) { pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) status := rc.GinCtx.Query("status") @@ -199,7 +199,7 @@ func (u *UserApi) GetSysUserList(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/user/profile [get] // @Security -func (u *UserApi) GetSysUserProfile(rc *ctx.ReqCtx) { +func (u *UserApi) GetSysUserProfile(rc *ginx.ReqCtx) { sysUser := entity.SysUser{} sysUser.UserId = rc.LoginAccount.UserId @@ -235,7 +235,7 @@ func (u *UserApi) GetSysUserProfile(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /system/user/profileAvatar [post] -func (u *UserApi) InsetSysUserAvatar(rc *ctx.ReqCtx) { +func (u *UserApi) InsetSysUserAvatar(rc *ginx.ReqCtx) { form, err := rc.GinCtx.MultipartForm() biz.ErrIsNil(err, "头像上传失败") @@ -262,7 +262,7 @@ func (u *UserApi) InsetSysUserAvatar(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /system/user/updatePwd [post] -func (u *UserApi) SysUserUpdatePwd(rc *ctx.ReqCtx) { +func (u *UserApi) SysUserUpdatePwd(rc *ginx.ReqCtx) { var pws entity.SysUserPwd ginx.BindJsonAndValid(rc.GinCtx, &pws) @@ -278,7 +278,7 @@ func (u *UserApi) SysUserUpdatePwd(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/user/sysUser/{userId} [get] // @Security -func (u *UserApi) GetSysUser(rc *ctx.ReqCtx) { +func (u *UserApi) GetSysUser(rc *ginx.ReqCtx) { userId := ginx.PathParamInt(rc.GinCtx, "userId") user := entity.SysUser{} @@ -312,7 +312,7 @@ func (u *UserApi) GetSysUser(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/user/getInit [get] // @Security -func (u *UserApi) GetSysUserInit(rc *ctx.ReqCtx) { +func (u *UserApi) GetSysUserInit(rc *ginx.ReqCtx) { var role entity.SysRole if !IsTenantAdmin(rc.LoginAccount.TenantId) { @@ -336,7 +336,7 @@ func (u *UserApi) GetSysUserInit(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /system/user/getInit [get] // @Security -func (u *UserApi) GetUserRolePost(rc *ctx.ReqCtx) { +func (u *UserApi) GetUserRolePost(rc *ginx.ReqCtx) { var user entity.SysUser user.UserId = rc.LoginAccount.UserId @@ -367,7 +367,7 @@ func (u *UserApi) GetUserRolePost(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/user/sysUser [post] -func (u *UserApi) InsertSysUser(rc *ctx.ReqCtx) { +func (u *UserApi) InsertSysUser(rc *ginx.ReqCtx) { var sysUser entity.SysUser ginx.BindJsonAndValid(rc.GinCtx, &sysUser) sysUser.CreateBy = rc.LoginAccount.UserName @@ -383,7 +383,7 @@ func (u *UserApi) InsertSysUser(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/user/sysUser [put] -func (u *UserApi) UpdateSysUser(rc *ctx.ReqCtx) { +func (u *UserApi) UpdateSysUser(rc *ginx.ReqCtx) { var sysUser entity.SysUser ginx.BindJsonAndValid(rc.GinCtx, &sysUser) sysUser.CreateBy = rc.LoginAccount.UserName @@ -399,7 +399,7 @@ func (u *UserApi) UpdateSysUser(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /system/user/sysUser [put] -func (u *UserApi) UpdateSysUserStu(rc *ctx.ReqCtx) { +func (u *UserApi) UpdateSysUserStu(rc *ginx.ReqCtx) { var sysUser entity.SysUser ginx.BindJsonAndValid(rc.GinCtx, &sysUser) sysUser.CreateBy = rc.LoginAccount.UserName @@ -413,7 +413,7 @@ func (u *UserApi) UpdateSysUserStu(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /system/user/sysuser/{userId} [delete] -func (u *UserApi) DeleteSysUser(rc *ctx.ReqCtx) { +func (u *UserApi) DeleteSysUser(rc *ginx.ReqCtx) { userIds := rc.GinCtx.Param("userId") us := utils.IdsStrToIdsIntGroup(userIds) u.UserApp.Delete(us) @@ -428,7 +428,7 @@ func (u *UserApi) DeleteSysUser(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /system/dict/type/export [get] -func (u *UserApi) ExportUser(rc *ctx.ReqCtx) { +func (u *UserApi) ExportUser(rc *ginx.ReqCtx) { filename := rc.GinCtx.Query("filename") status := rc.GinCtx.Query("status") userName := rc.GinCtx.Query("username") diff --git a/apps/system/router/api.go b/apps/system/router/api.go index 7ec1e64..eadcdca 100644 --- a/apps/system/router/api.go +++ b/apps/system/router/api.go @@ -4,7 +4,7 @@ import ( "github.com/gin-gonic/gin" "pandax/apps/system/api" "pandax/apps/system/services" - "pandax/base/ctx" + "pandax/base/ginx" ) func InitApiRouter(router *gin.RouterGroup) { @@ -13,38 +13,31 @@ func InitApiRouter(router *gin.RouterGroup) { } api := router.Group("api") - apiListLog := ctx.NewLogInfo("获取api分页列表") api.GET("list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(apiListLog).Handle(s.GetApiList) + ginx.NewReqCtx(c).WithLog("获取api分页列表").Handle(s.GetApiList) }) - apiListAllLog := ctx.NewLogInfo("获取所有api") api.GET("all", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(apiListAllLog).Handle(s.GetAllApis) + ginx.NewReqCtx(c).WithLog("获取所有api").Handle(s.GetAllApis) }) - apiListByRoleLog := ctx.NewLogInfo("获取角色拥有的api权限") api.GET("getPolicyPathByRoleId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(apiListByRoleLog).Handle(s.GetPolicyPathByRoleId) + ginx.NewReqCtx(c).WithLog("获取角色拥有的api权限").Handle(s.GetPolicyPathByRoleId) }) - apiLog := ctx.NewLogInfo("获取api信息") api.GET(":id", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(apiLog).Handle(s.GetApiById) + ginx.NewReqCtx(c).WithLog("获取api信息").Handle(s.GetApiById) }) - insertApiLog := ctx.NewLogInfo("添加api信息") api.POST("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(insertApiLog).Handle(s.CreateApi) + ginx.NewReqCtx(c).WithLog("添加api信息").Handle(s.CreateApi) }) - updateApiLog := ctx.NewLogInfo("修改api信息") api.PUT("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateApiLog).Handle(s.UpdateApi) + ginx.NewReqCtx(c).WithLog("修改api信息").Handle(s.UpdateApi) }) - deleteApiLog := ctx.NewLogInfo("删除api信息") api.DELETE(":id", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteApiLog).Handle(s.DeleteApi) + ginx.NewReqCtx(c).WithLog("删除api信息").Handle(s.DeleteApi) }) } diff --git a/apps/system/router/config.go b/apps/system/router/config.go index 9737073..17746c6 100644 --- a/apps/system/router/config.go +++ b/apps/system/router/config.go @@ -4,7 +4,7 @@ import ( "github.com/gin-gonic/gin" "pandax/apps/system/api" "pandax/apps/system/services" - "pandax/base/ctx" + "pandax/base/ginx" ) func InitConfigRouter(router *gin.RouterGroup) { @@ -13,33 +13,27 @@ func InitConfigRouter(router *gin.RouterGroup) { } config := router.Group("config") - configListLog := ctx.NewLogInfo("获取配置分页列表") config.GET("list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(configListLog).Handle(s.GetConfigList) + ginx.NewReqCtx(c).WithLog("获取配置分页列表").Handle(s.GetConfigList) }) - configListByKeyLog := ctx.NewLogInfo("获取配置列表通过ConfigKey") config.GET("configKey", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(configListByKeyLog).Handle(s.GetConfigListByKey) + ginx.NewReqCtx(c).WithLog("获取配置列表通过ConfigKey").Handle(s.GetConfigListByKey) }) - configLog := ctx.NewLogInfo("获取配置信息") config.GET(":configId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(configLog).Handle(s.GetConfig) + ginx.NewReqCtx(c).WithLog("获取配置信息").Handle(s.GetConfig) }) - insertConfigLog := ctx.NewLogInfo("添加配置信息") config.POST("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(insertConfigLog).Handle(s.InsertConfig) + ginx.NewReqCtx(c).WithLog("添加配置信息").Handle(s.InsertConfig) }) - updateConfigLog := ctx.NewLogInfo("修改配置信息") config.PUT("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateConfigLog).Handle(s.UpdateConfig) + ginx.NewReqCtx(c).WithLog("修改配置信息").Handle(s.UpdateConfig) }) - deleteConfigLog := ctx.NewLogInfo("删除配置信息") config.DELETE(":configId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteConfigLog).Handle(s.DeleteConfig) + ginx.NewReqCtx(c).WithLog("删除配置信息").Handle(s.DeleteConfig) }) } diff --git a/apps/system/router/dept.go b/apps/system/router/dept.go index 8c6c86c..4cc3a6f 100644 --- a/apps/system/router/dept.go +++ b/apps/system/router/dept.go @@ -4,7 +4,7 @@ import ( "github.com/gin-gonic/gin" "pandax/apps/system/api" "pandax/apps/system/services" - "pandax/base/ctx" + "pandax/base/ginx" ) func InitDeptRouter(router *gin.RouterGroup) { @@ -15,38 +15,31 @@ func InitDeptRouter(router *gin.RouterGroup) { } dept := router.Group("dept") - roleDeptTreSelectLog := ctx.NewLogInfo("获取角色部门树") dept.GET("roleDeptTreeSelect/:roleId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(roleDeptTreSelectLog).Handle(r.GetDeptTreeRoleSelect) + ginx.NewReqCtx(c).WithLog("获取角色部门树").Handle(r.GetDeptTreeRoleSelect) }) - deptTreeLog := ctx.NewLogInfo("获取所有部门树") dept.GET("deptTree", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deptTreeLog).Handle(r.GetDeptTree) + ginx.NewReqCtx(c).WithLog("获取所有部门树").Handle(r.GetDeptTree) }) - deptListLog := ctx.NewLogInfo("获取部门列表") dept.GET("list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deptListLog).Handle(r.GetDeptList) + ginx.NewReqCtx(c).WithLog("获取部门列表").Handle(r.GetDeptList) }) - deptLog := ctx.NewLogInfo("获取部门信息") dept.GET(":deptId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deptLog).Handle(r.GetDept) + ginx.NewReqCtx(c).WithLog("获取部门信息").Handle(r.GetDept) }) - inertDeptLog := ctx.NewLogInfo("添加部门信息") dept.POST("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(inertDeptLog).Handle(r.InsertDept) + ginx.NewReqCtx(c).WithLog("添加部门信息").Handle(r.InsertDept) }) - updateDeptLog := ctx.NewLogInfo("修改部门信息") dept.PUT("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateDeptLog).Handle(r.UpdateDept) + ginx.NewReqCtx(c).WithLog("修改部门信息").Handle(r.UpdateDept) }) - deleteDeptLog := ctx.NewLogInfo("删除部门信息") dept.DELETE(":deptId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteDeptLog).Handle(r.DeleteDept) + ginx.NewReqCtx(c).WithLog("删除部门信息").Handle(r.DeleteDept) }) } diff --git a/apps/system/router/dict.go b/apps/system/router/dict.go index abaccf9..5e401e9 100644 --- a/apps/system/router/dict.go +++ b/apps/system/router/dict.go @@ -4,7 +4,7 @@ import ( "github.com/gin-gonic/gin" "pandax/apps/system/api" "pandax/apps/system/services" - "pandax/base/ctx" + "pandax/base/ginx" ) func InitDictRouter(router *gin.RouterGroup) { @@ -14,64 +14,52 @@ func InitDictRouter(router *gin.RouterGroup) { } dict := router.Group("dict") - typeList := ctx.NewLogInfo("获取字典类型分页列表") dict.GET("type/list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(typeList).Handle(s.GetDictTypeList) + ginx.NewReqCtx(c).WithLog("获取字典类型分页列表").Handle(s.GetDictTypeList) }) - typeLog := ctx.NewLogInfo("获取字典类型信息") dict.GET("type/:dictId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(typeLog).Handle(s.GetDictType) + ginx.NewReqCtx(c).WithLog("获取字典类型信息").Handle(s.GetDictType) }) - insertTypeLog := ctx.NewLogInfo("添加字典类型信息") dict.POST("type", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(insertTypeLog).Handle(s.InsertDictType) + ginx.NewReqCtx(c).WithLog("添加字典类型信息").Handle(s.InsertDictType) }) - updateTypeLog := ctx.NewLogInfo("修改字典类型信息") dict.PUT("type", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateTypeLog).Handle(s.UpdateDictType) + ginx.NewReqCtx(c).WithLog("修改字典类型信息").Handle(s.UpdateDictType) }) - deleteTypeLog := ctx.NewLogInfo("删除字典类型信息") dict.DELETE("type/:dictId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteTypeLog).Handle(s.DeleteDictType) + ginx.NewReqCtx(c).WithLog("删除字典类型信息").Handle(s.DeleteDictType) }) - exportTypeLog := ctx.NewLogInfo("导出字典类型信息") dict.GET("type/export", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(exportTypeLog).Handle(s.ExportDictType) + ginx.NewReqCtx(c).WithLog("导出字典类型信息").Handle(s.ExportDictType) }) - dataListLog := ctx.NewLogInfo("获取字典数据分页列表") dict.GET("data/list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(dataListLog).Handle(s.GetDictDataList) + ginx.NewReqCtx(c).WithLog("获取字典数据分页列表").Handle(s.GetDictDataList) }) - dataListByDictTypeLog := ctx.NewLogInfo("获取字典数据列表通过字典类型") dict.GET("data/type", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(dataListByDictTypeLog).Handle(s.GetDictDataListByDictType) + ginx.NewReqCtx(c).WithLog("获取字典数据列表通过字典类型").Handle(s.GetDictDataListByDictType) }) - dataLog := ctx.NewLogInfo("获取字典数据信息") dict.GET("data/:dictCode", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(dataLog).Handle(s.GetDictData) + ginx.NewReqCtx(c).WithLog("获取字典数据信息").Handle(s.GetDictData) }) - insertDataLog := ctx.NewLogInfo("添加字典数据信息") dict.POST("data", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(insertDataLog).Handle(s.InsertDictData) + ginx.NewReqCtx(c).WithLog("添加字典数据信息").Handle(s.InsertDictData) }) - updateDataLog := ctx.NewLogInfo("修改字典数据信息") dict.PUT("data", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateDataLog).Handle(s.UpdateDictData) + ginx.NewReqCtx(c).WithLog("修改字典数据信息").Handle(s.UpdateDictData) }) - deleteDataLog := ctx.NewLogInfo("删除字典数据信息") dict.DELETE("data/:dictCode", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteDataLog).Handle(s.DeleteDictData) + ginx.NewReqCtx(c).WithLog("删除字典数据信息").Handle(s.DeleteDictData) }) } diff --git a/apps/system/router/menu.go b/apps/system/router/menu.go index 72fff4f..bd22971 100644 --- a/apps/system/router/menu.go +++ b/apps/system/router/menu.go @@ -4,7 +4,7 @@ import ( "github.com/gin-gonic/gin" "pandax/apps/system/api" "pandax/apps/system/services" - "pandax/base/ctx" + "pandax/base/ginx" ) func InitMenuRouter(router *gin.RouterGroup) { @@ -16,48 +16,39 @@ func InitMenuRouter(router *gin.RouterGroup) { } menu := router.Group("menu") - getSetRole := ctx.NewLogInfo("获取菜单树") menu.GET("menuTreeSelect", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(getSetRole).WithNeedToken(false).WithNeedCasbin(false).Handle(s.GetMenuTreeSelect) + ginx.NewReqCtx(c).WithLog("获取菜单树").WithNeedToken(false).WithNeedCasbin(false).Handle(s.GetMenuTreeSelect) }) - menuRole := ctx.NewLogInfo("获取角色菜单") menu.GET("menuRole", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(menuRole).Handle(s.GetMenuRole) + ginx.NewReqCtx(c).WithLog("获取角色菜单").Handle(s.GetMenuRole) }) - roleMenuTreSelect := ctx.NewLogInfo("获取角色菜单树") menu.GET("roleMenuTreeSelect/:roleId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(roleMenuTreSelect).Handle(s.GetMenuTreeRoleSelect) + ginx.NewReqCtx(c).WithLog("获取角色菜单树").Handle(s.GetMenuTreeRoleSelect) }) - menuPaths := ctx.NewLogInfo("获取角色菜单路径列表") menu.GET("menuPaths", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(menuPaths).Handle(s.GetMenuPaths) + ginx.NewReqCtx(c).WithLog("获取角色菜单路径列表").Handle(s.GetMenuPaths) }) - menuList := ctx.NewLogInfo("获取菜单列表") menu.GET("list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(menuList).Handle(s.GetMenuList) + ginx.NewReqCtx(c).WithLog("获取菜单列表").Handle(s.GetMenuList) }) - menuLog := ctx.NewLogInfo("获取菜单信息") menu.GET(":menuId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(menuLog).Handle(s.GetMenu) + ginx.NewReqCtx(c).WithLog("获取菜单信息").Handle(s.GetMenu) }) - insertMenuLog := ctx.NewLogInfo("添加菜单信息") menu.POST("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(insertMenuLog).Handle(s.InsertMenu) + ginx.NewReqCtx(c).WithLog("添加菜单信息").Handle(s.InsertMenu) }) - updateMenuLog := ctx.NewLogInfo("修改菜单信息") menu.PUT("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateMenuLog).Handle(s.UpdateMenu) + ginx.NewReqCtx(c).WithLog("修改菜单信息").Handle(s.UpdateMenu) }) - deleteMenuLog := ctx.NewLogInfo("删除菜单信息") menu.DELETE(":menuId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteMenuLog).Handle(s.DeleteMenu) + ginx.NewReqCtx(c).WithLog("删除菜单信息").Handle(s.DeleteMenu) }) } diff --git a/apps/system/router/notice.go b/apps/system/router/notice.go index f29df46..1ca5040 100644 --- a/apps/system/router/notice.go +++ b/apps/system/router/notice.go @@ -4,7 +4,7 @@ import ( "github.com/gin-gonic/gin" "pandax/apps/system/api" "pandax/apps/system/services" - "pandax/base/ctx" + "pandax/base/ginx" ) func InitNoticeRouter(router *gin.RouterGroup) { @@ -14,23 +14,19 @@ func InitNoticeRouter(router *gin.RouterGroup) { } notice := router.Group("notice") - noticetList := ctx.NewLogInfo("获取通知分页列表") notice.GET("list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(noticetList).Handle(s.GetNoticeList) + ginx.NewReqCtx(c).WithLog("获取通知分页列表").Handle(s.GetNoticeList) }) - insertNoticeLog := ctx.NewLogInfo("添加通知信息") notice.POST("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(insertNoticeLog).Handle(s.InsertNotice) + ginx.NewReqCtx(c).WithLog("添加通知信息").Handle(s.InsertNotice) }) - updateNoticeLog := ctx.NewLogInfo("修改通知信息") notice.PUT("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateNoticeLog).Handle(s.UpdateNotice) + ginx.NewReqCtx(c).WithLog("修改通知信息").Handle(s.UpdateNotice) }) - deleteNoticeLog := ctx.NewLogInfo("删除通知信息") notice.DELETE(":noticeId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteNoticeLog).Handle(s.DeleteNotice) + ginx.NewReqCtx(c).WithLog("删除通知信息").Handle(s.DeleteNotice) }) } diff --git a/apps/system/router/post.go b/apps/system/router/post.go index 09fe42c..5215a36 100644 --- a/apps/system/router/post.go +++ b/apps/system/router/post.go @@ -4,7 +4,7 @@ import ( "github.com/gin-gonic/gin" "pandax/apps/system/api" "pandax/apps/system/services" - "pandax/base/ctx" + "pandax/base/ginx" ) func InitPostRouter(router *gin.RouterGroup) { @@ -15,28 +15,23 @@ func InitPostRouter(router *gin.RouterGroup) { } post := router.Group("post") - postList := ctx.NewLogInfo("获取岗位分页列表") post.GET("list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(postList).Handle(s.GetPostList) + ginx.NewReqCtx(c).WithLog("获取岗位分页列表").Handle(s.GetPostList) }) - postLog := ctx.NewLogInfo("获取岗位信息") post.GET(":postId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(postLog).Handle(s.GetPost) + ginx.NewReqCtx(c).WithLog("获取岗位信息").Handle(s.GetPost) }) - insertPostLog := ctx.NewLogInfo("添加岗位信息") post.POST("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(insertPostLog).Handle(s.InsertPost) + ginx.NewReqCtx(c).WithLog("添加岗位信息").Handle(s.InsertPost) }) - updatePostLog := ctx.NewLogInfo("修改岗位信息") post.PUT("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updatePostLog).Handle(s.UpdatePost) + ginx.NewReqCtx(c).WithLog("修改岗位信息").Handle(s.UpdatePost) }) - deletePostLog := ctx.NewLogInfo("删除岗位信息") post.DELETE(":postId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deletePostLog).Handle(s.DeletePost) + ginx.NewReqCtx(c).WithLog("删除岗位信息").Handle(s.DeletePost) }) } diff --git a/apps/system/router/role.go b/apps/system/router/role.go index de031be..a9dcb85 100644 --- a/apps/system/router/role.go +++ b/apps/system/router/role.go @@ -4,7 +4,7 @@ import ( "github.com/gin-gonic/gin" "pandax/apps/system/api" "pandax/apps/system/services" - "pandax/base/ctx" + "pandax/base/ginx" ) func InitRoleRouter(router *gin.RouterGroup) { @@ -16,42 +16,35 @@ func InitRoleRouter(router *gin.RouterGroup) { } role := router.Group("role") - roleListLog := ctx.NewLogInfo("获取角色分页列表") role.GET("list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(roleListLog).Handle(s.GetRoleList) + ginx.NewReqCtx(c).WithLog("获取角色分页列表").Handle(s.GetRoleList) }) - roleLog := ctx.NewLogInfo("获取角色信息") role.GET(":roleId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(roleLog).Handle(s.GetRole) + ginx.NewReqCtx(c).WithLog("获取角色信息").Handle(s.GetRole) }) - insertRoleLog := ctx.NewLogInfo("添加角色信息") role.POST("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(insertRoleLog).Handle(s.InsertRole) + ginx.NewReqCtx(c).WithLog("添加角色信息").Handle(s.InsertRole) }) - updateRoleLog := ctx.NewLogInfo("修改角色信息") role.PUT("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateRoleLog).Handle(s.UpdateRole) + ginx.NewReqCtx(c).WithLog("修改角色信息").Handle(s.UpdateRole) }) - updateStaRoleLog := ctx.NewLogInfo("修改角色状态") + role.PUT("changeStatus", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateStaRoleLog).Handle(s.UpdateRoleStatus) + ginx.NewReqCtx(c).WithLog("修改角色状态").Handle(s.UpdateRoleStatus) }) - updateDaSRoleLog := ctx.NewLogInfo("修改角色部门权限") role.PUT("dataScope", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateDaSRoleLog).Handle(s.UpdateRoleDataScope) + ginx.NewReqCtx(c).WithLog("修改角色部门权限").Handle(s.UpdateRoleDataScope) }) - deleteRoleLog := ctx.NewLogInfo("删除角色信息") role.DELETE(":roleId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteRoleLog).Handle(s.DeleteRole) + ginx.NewReqCtx(c).WithLog("删除角色信息").Handle(s.DeleteRole) }) - exportRoleLog := ctx.NewLogInfo("导出角色信息") role.GET("export", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(exportRoleLog).Handle(s.ExportRole) + ginx.NewReqCtx(c).WithLog("导出角色信息").Handle(s.ExportRole) }) } diff --git a/apps/system/router/tenant.go b/apps/system/router/tenant.go index dcf572b..9235f15 100644 --- a/apps/system/router/tenant.go +++ b/apps/system/router/tenant.go @@ -10,7 +10,7 @@ import ( "github.com/gin-gonic/gin" "pandax/apps/system/api" "pandax/apps/system/services" - "pandax/base/ctx" + "pandax/base/ginx" ) func InitSysTenantRouter(router *gin.RouterGroup) { @@ -19,31 +19,27 @@ func InitSysTenantRouter(router *gin.RouterGroup) { } routerGroup := router.Group("tenant") - SysTenantListLog := ctx.NewLogInfo("获取SysTenant分页列表") routerGroup.GET("list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(SysTenantListLog).Handle(s.GetSysTenantsList) + ginx.NewReqCtx(c).WithLog("获取SysTenant分页列表").Handle(s.GetSysTenantsList) }) - SysTenantAllLog := ctx.NewLogInfo("获取SysTenant列表") + routerGroup.GET("lists", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(SysTenantAllLog).Handle(s.GetSysTenantsAll) + ginx.NewReqCtx(c).WithLog("获取SysTenant列表").Handle(s.GetSysTenantsAll) }) - SysTenantLog := ctx.NewLogInfo("获取SysTenant信息") + routerGroup.GET(":tenantId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(SysTenantLog).Handle(s.GetSysTenants) + ginx.NewReqCtx(c).WithLog("获取SysTenant信息").Handle(s.GetSysTenants) }) - insertSysTenantLog := ctx.NewLogInfo("添加SysTenant信息") routerGroup.POST("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(insertSysTenantLog).Handle(s.InsertSysTenants) + ginx.NewReqCtx(c).WithLog("添加SysTenant信息").Handle(s.InsertSysTenants) }) - updateSysTenantLog := ctx.NewLogInfo("修改SysTenant信息") routerGroup.PUT("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateSysTenantLog).Handle(s.UpdateSysTenants) + ginx.NewReqCtx(c).WithLog("修改SysTenant信息").Handle(s.UpdateSysTenants) }) - deleteSysTenantLog := ctx.NewLogInfo("删除SysTenant信息") routerGroup.DELETE(":tenantId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteSysTenantLog).Handle(s.DeleteSysTenants) + ginx.NewReqCtx(c).WithLog("删除SysTenant信息").Handle(s.DeleteSysTenants) }) } diff --git a/apps/system/router/user.go b/apps/system/router/user.go index 0eced61..f55adae 100644 --- a/apps/system/router/user.go +++ b/apps/system/router/user.go @@ -6,7 +6,7 @@ import ( "pandax/apps/system/services" logServices "pandax/apps/log/services" - "pandax/base/ctx" + "pandax/base/ginx" ) func InitUserRouter(router *gin.RouterGroup) { @@ -23,71 +23,57 @@ func InitUserRouter(router *gin.RouterGroup) { // 获取验证码 user.GET("getCaptcha", s.GenerateCaptcha) - loginLog := ctx.NewLogInfo("登录") user.POST("login", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(loginLog).WithNeedToken(false).WithNeedCasbin(false).Handle(s.Login) + ginx.NewReqCtx(c).WithLog("登录").WithNeedToken(false).WithNeedCasbin(false).Handle(s.Login) }) - authLog := ctx.NewLogInfo("认证信息") user.GET("auth", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(authLog).WithNeedCasbin(false).Handle(s.Auth) + ginx.NewReqCtx(c).WithLog("认证信息").WithNeedCasbin(false).Handle(s.Auth) }) - logoutLog := ctx.NewLogInfo("退出登录") user.POST("logout", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(logoutLog).WithNeedToken(false).WithNeedCasbin(false).Handle(s.LogOut) + ginx.NewReqCtx(c).WithLog("退出登录").WithNeedToken(false).WithNeedCasbin(false).Handle(s.LogOut) }) - sysUserListLog := ctx.NewLogInfo("得到用户分页列表") user.GET("list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(sysUserListLog).Handle(s.GetSysUserList) + ginx.NewReqCtx(c).WithLog("得到用户分页列表").Handle(s.GetSysUserList) }) - avatarLog := ctx.NewLogInfo("修改用户头像") user.POST("avatar", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(avatarLog).Handle(s.InsetSysUserAvatar) + ginx.NewReqCtx(c).WithLog("修改用户头像").Handle(s.InsetSysUserAvatar) }) - pwdLog := ctx.NewLogInfo("修改用户密码") user.PUT("pwd", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(pwdLog).Handle(s.SysUserUpdatePwd) + ginx.NewReqCtx(c).WithLog("修改用户密码").Handle(s.SysUserUpdatePwd) }) - userLog := ctx.NewLogInfo("获取用户信息") user.GET("getById/:userId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(userLog).Handle(s.GetSysUser) + ginx.NewReqCtx(c).WithLog("获取用户信息").Handle(s.GetSysUser) }) - getSysUserInitLog := ctx.NewLogInfo("获取初始化角色岗位信息(添加用户初始化)") user.GET("getInit", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(getSysUserInitLog).Handle(s.GetSysUserInit) + ginx.NewReqCtx(c).WithLog("获取初始化角色岗位信息(添加用户初始化)").Handle(s.GetSysUserInit) }) - getSysUserRoPoLog := ctx.NewLogInfo("获取用户角色岗位信息(添加用户初始化)") user.GET("getRoPo", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(getSysUserRoPoLog).Handle(s.GetUserRolePost) + ginx.NewReqCtx(c).WithLog("获取用户角色岗位信息(添加用户初始化)").Handle(s.GetUserRolePost) }) - insertUserLog := ctx.NewLogInfo("添加用户信息") user.POST("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(insertUserLog).Handle(s.InsertSysUser) + ginx.NewReqCtx(c).WithLog("添加用户信息").Handle(s.InsertSysUser) }) - updateUserLog := ctx.NewLogInfo("修改用户信息") user.PUT("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateUserLog).Handle(s.UpdateSysUser) + ginx.NewReqCtx(c).WithLog("修改用户信息").Handle(s.UpdateSysUser) }) - updateUserStuLog := ctx.NewLogInfo("修改用户状态") user.PUT("changeStatus", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(updateUserStuLog).Handle(s.UpdateSysUserStu) + ginx.NewReqCtx(c).WithLog("修改用户状态").Handle(s.UpdateSysUserStu) }) - deleteUserLog := ctx.NewLogInfo("删除用户信息") user.DELETE(":userId", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(deleteUserLog).Handle(s.DeleteSysUser) + ginx.NewReqCtx(c).WithLog("删除用户信息").Handle(s.DeleteSysUser) }) - exportUserLog := ctx.NewLogInfo("导出用户信息") user.GET("export", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(exportUserLog).Handle(s.ExportUser) + ginx.NewReqCtx(c).WithLog("导出用户信息").Handle(s.ExportUser) }) } diff --git a/base/config/config.go b/base/config/config.go index d95c8bd..82e36fc 100644 --- a/base/config/config.go +++ b/base/config/config.go @@ -8,6 +8,8 @@ import ( "path/filepath" ) +var GConfig *Config + func InitConfig(configFilePath string) *Config { // 获取启动参数中,配置文件的绝对路径 path, _ := filepath.Abs(configFilePath) @@ -19,6 +21,7 @@ func InitConfig(configFilePath string) *Config { } // 校验配置文件内容信息 yc.Valid() + GConfig = yc return yc } diff --git a/base/ginx/ginx.go b/base/ginx/ginx.go index e209938..cfcf021 100644 --- a/base/ginx/ginx.go +++ b/base/ginx/ginx.go @@ -24,6 +24,7 @@ func BindQuery(g *gin.Context, data any) { panic(any(biz.NewBizErr(err.Error()))) } } + func ParamsToAny(g *gin.Context, in any) { vars := make(map[string]any) for _, v := range g.Params { diff --git a/base/ctx/log_handler.go b/base/ginx/log_handler.go similarity index 99% rename from base/ctx/log_handler.go rename to base/ginx/log_handler.go index 7bdbbac..aa5f8a6 100644 --- a/base/ctx/log_handler.go +++ b/base/ginx/log_handler.go @@ -1,4 +1,4 @@ -package ctx +package ginx import ( "encoding/json" diff --git a/base/ctx/permission_handler.go b/base/ginx/permission_handler.go similarity index 92% rename from base/ctx/permission_handler.go rename to base/ginx/permission_handler.go index 40c4ee1..297c6fd 100644 --- a/base/ctx/permission_handler.go +++ b/base/ginx/permission_handler.go @@ -1,9 +1,10 @@ -package ctx +package ginx import ( "github.com/dgrijalva/jwt-go" "pandax/base/biz" "pandax/base/casbin" + "pandax/base/token" "pandax/pkg/global" "strconv" ) @@ -37,7 +38,7 @@ func PermissionHandler(rc *ReqCtx) error { if tokenStr == "" { return biz.PermissionErr } - j := NewJWT("", []byte(global.Conf.Jwt.Key), jwt.SigningMethodHS256) + j := token.NewJWT("", []byte(global.Conf.Jwt.Key), jwt.SigningMethodHS256) loginAccount, err := j.ParseToken(tokenStr) if err != nil || loginAccount == nil { return biz.PermissionErr diff --git a/base/ginx/req_ctx.go b/base/ginx/req_ctx.go new file mode 100644 index 0000000..89e9452 --- /dev/null +++ b/base/ginx/req_ctx.go @@ -0,0 +1,124 @@ +package ginx + +import ( + "pandax/base/biz" + "pandax/base/token" + "time" + + "github.com/gin-gonic/gin" +) + +// 处理函数 +type HandlerFunc func(*ReqCtx) + +type ReqCtx struct { + GinCtx *gin.Context // gin context + + // NeedToken bool // 是否需要token + RequiredPermission *Permission // 需要的权限信息,默认为nil,需要校验token + LoginAccount *token.Claims // 登录账号信息,只有校验token后才会有值 + + LogInfo *LogInfo // 日志相关信息 + ReqParam any // 请求参数,主要用于记录日志 + ResData any // 响应结果 + Err any // 请求错误 + + timed int64 // 执行时间 + noRes bool // 无需返回结果,即文件下载等 +} + +func (rc *ReqCtx) Handle(handler HandlerFunc) { + ginCtx := rc.GinCtx + defer func() { + var err any + err = recover() + if err != nil { + rc.Err = err + ErrorRes(ginCtx, err) + } + // 应用所有请求后置处理器 + ApplyHandlerInterceptor(afterHandlers, rc) + }() + biz.IsTrue(ginCtx != nil, "ginContext == nil") + + // 默认为不记录请求参数,可在handler回调函数中覆盖赋值 + rc.ReqParam = 0 + // 默认响应结果为nil,可在handler中赋值 + rc.ResData = nil + + // 调用请求前所有处理器 + err := ApplyHandlerInterceptor(beforeHandlers, rc) + if err != nil { + panic(err) + } + + begin := time.Now() + handler(rc) + rc.timed = time.Now().Sub(begin).Milliseconds() + if !rc.noRes { + SuccessRes(ginCtx, rc.ResData) + } +} + +func (rc *ReqCtx) Download(filename string) { + rc.noRes = true + Download(rc.GinCtx, filename) +} + +// 新建请求上下文,默认需要校验token +func NewReqCtx(g *gin.Context) *ReqCtx { + return &ReqCtx{GinCtx: g, LogInfo: NewLogInfo("默认日志信息"), RequiredPermission: &Permission{NeedToken: true, NeedCasbin: true}} +} + +// 调用该方法设置请求描述,则默认记录日志,并不记录响应结果 +func (r *ReqCtx) WithLog(model string) *ReqCtx { + r.LogInfo.Description = model + return r +} + +// 设置请求上下文需要的权限信息 +func (r *ReqCtx) WithRequiredPermission(permission *Permission) *ReqCtx { + r.RequiredPermission = permission + return r +} + +// 是否需要token +func (r *ReqCtx) WithNeedToken(needToken bool) *ReqCtx { + r.RequiredPermission.NeedToken = needToken + return r +} + +// 是否需要Casbin +func (r *ReqCtx) WithNeedCasbin(needCasbin bool) *ReqCtx { + r.RequiredPermission.NeedCasbin = needCasbin + return r +} + +// 处理器拦截器函数 +type HandlerInterceptorFunc func(*ReqCtx) error +type HandlerInterceptors []HandlerInterceptorFunc + +var ( + beforeHandlers HandlerInterceptors + afterHandlers HandlerInterceptors +) + +// 使用前置处理器函数 +func UseBeforeHandlerInterceptor(b HandlerInterceptorFunc) { + beforeHandlers = append(beforeHandlers, b) +} + +// 使用后置处理器函数 +func UseAfterHandlerInterceptor(b HandlerInterceptorFunc) { + afterHandlers = append(afterHandlers, b) +} + +// 应用指定处理器拦截器,如果有一个错误则直接返回错误 +func ApplyHandlerInterceptor(his HandlerInterceptors, rc *ReqCtx) any { + for _, handler := range his { + if err := handler(rc); err != nil { + return err + } + } + return nil +} diff --git a/base/logger/logger.go b/base/logger/logger.go index 12c9136..268d343 100644 --- a/base/logger/logger.go +++ b/base/logger/logger.go @@ -10,8 +10,10 @@ import ( "github.com/sirupsen/logrus" ) +var Log *logrus.Logger + func InitLog(logConf *config.Log) *logrus.Logger { - var Log = logrus.New() + Log = logrus.New() Log.SetFormatter(new(LogFormatter)) Log.SetReportCaller(true) diff --git a/base/restfulx/log_handler.go b/base/restfulx/log_handler.go new file mode 100644 index 0000000..84d7132 --- /dev/null +++ b/base/restfulx/log_handler.go @@ -0,0 +1,84 @@ +package restfulx + +import ( + "encoding/json" + "fmt" + "pandax/base/biz" + "pandax/base/utils" + "pandax/pkg/global" + "reflect" + "runtime/debug" + + "github.com/sirupsen/logrus" +) + +type LogInfo struct { + LogResp bool // 是否记录返回结果 + Description string // 请求描述 +} + +func NewLogInfo(description string) *LogInfo { + return &LogInfo{Description: description, LogResp: false} +} + +func (i *LogInfo) WithLogResp(logResp bool) *LogInfo { + i.LogResp = logResp + return i +} + +func LogHandler(rc *ReqCtx) error { + li := rc.LogInfo + if li == nil { + return nil + } + + lfs := logrus.Fields{} + if la := rc.LoginAccount; la != nil { + lfs["uid"] = la.UserId + lfs["uname"] = la.UserName + } + + req := rc.GinCtx.Request + lfs[req.Method] = req.URL.Path + + if err := rc.Err; err != nil { + global.Log.WithFields(lfs).Error(getErrMsg(rc, err)) + return nil + } + global.Log.WithFields(lfs).Info(getLogMsg(rc)) + return nil +} + +func getLogMsg(rc *ReqCtx) string { + msg := rc.LogInfo.Description + fmt.Sprintf(" ->%dms", rc.timed) + if !utils.IsBlank(reflect.ValueOf(rc.ReqParam)) { + rb, _ := json.Marshal(rc.ReqParam) + msg = msg + fmt.Sprintf("\n--> %s", string(rb)) + } + + // 返回结果不为空,则记录返回结果 + if rc.LogInfo.LogResp && !utils.IsBlank(reflect.ValueOf(rc.ResData)) { + respB, _ := json.Marshal(rc.ResData) + msg = msg + fmt.Sprintf("\n<-- %s", string(respB)) + } + return msg +} + +func getErrMsg(rc *ReqCtx, err any) string { + msg := rc.LogInfo.Description + if !utils.IsBlank(reflect.ValueOf(rc.ReqParam)) { + rb, _ := json.Marshal(rc.ReqParam) + msg = msg + fmt.Sprintf("\n--> %s", string(rb)) + } + + var errMsg string + switch t := err.(type) { + case *biz.BizError: + errMsg = fmt.Sprintf("\n<-e errCode: %d, errMsg: %s", t.Code(), t.Error()) + case error: + errMsg = fmt.Sprintf("\n<-e errMsg: %s\n%s", t.Error(), string(debug.Stack())) + case string: + errMsg = fmt.Sprintf("\n<-e errMsg: %s\n%s", t, string(debug.Stack())) + } + return (msg + errMsg) +} diff --git a/base/restfulx/permission_handler.go b/base/restfulx/permission_handler.go new file mode 100644 index 0000000..e06054b --- /dev/null +++ b/base/restfulx/permission_handler.go @@ -0,0 +1,60 @@ +package restfulx + +import ( + "github.com/dgrijalva/jwt-go" + "pandax/base/biz" + "pandax/base/casbin" + "pandax/base/token" + "pandax/pkg/global" + "strconv" +) + +type Permission struct { + NeedToken bool // 是否需要token + NeedCasbin bool // 是否进行权限 api路径权限验证 +} + +func (p *Permission) WithNeedToken(needToken bool) *Permission { + p.NeedToken = needToken + return p +} + +func (p *Permission) WithNeedCasBin(needCasBin bool) *Permission { + p.NeedCasbin = needCasBin + return p +} + +func PermissionHandler(rc *ReqCtx) error { + permission := rc.RequiredPermission + // 如果需要的权限信息不为空,并且不需要token,则不返回错误,继续后续逻辑 + if permission != nil && !permission.NeedToken { + return nil + } + tokenStr := rc.GinCtx.Request.Header.Get("X-TOKEN") + // header不存在则从查询参数token中获取 + if tokenStr == "" { + tokenStr = rc.GinCtx.Query("token") + } + if tokenStr == "" { + return biz.PermissionErr + } + j := token.NewJWT("", []byte(global.Conf.Jwt.Key), jwt.SigningMethodHS256) + loginAccount, err := j.ParseToken(tokenStr) + if err != nil || loginAccount == nil { + return biz.PermissionErr + } + rc.LoginAccount = loginAccount + + if !permission.NeedCasbin { + return nil + } + e := casbin.Casbin() + // 判断策略中是否存在 + tenantId := strconv.Itoa(int(rc.LoginAccount.TenantId)) + success, err := e.Enforce(tenantId, loginAccount.RoleKey, rc.GinCtx.Request.URL.Path, rc.GinCtx.Request.Method) + if !success { + return biz.CasbinErr + } + + return nil +} diff --git a/base/ctx/req_ctx.go b/base/restfulx/req_ctx.go similarity index 89% rename from base/ctx/req_ctx.go rename to base/restfulx/req_ctx.go index aecea1c..30a6bb2 100644 --- a/base/ctx/req_ctx.go +++ b/base/restfulx/req_ctx.go @@ -1,8 +1,9 @@ -package ctx +package restfulx import ( "pandax/base/biz" "pandax/base/ginx" + "pandax/base/token" "time" "github.com/gin-gonic/gin" @@ -15,8 +16,8 @@ type ReqCtx struct { GinCtx *gin.Context // gin context // NeedToken bool // 是否需要token - RequiredPermission *Permission // 需要的权限信息,默认为nil,需要校验token - LoginAccount *Claims // 登录账号信息,只有校验token后才会有值 + RequiredPermission *Permission // 需要的权限信息,默认为nil,需要校验token + LoginAccount *token.Claims // 登录账号信息,只有校验token后才会有值 LogInfo *LogInfo // 日志相关信息 ReqParam any // 请求参数,主要用于记录日志 @@ -65,12 +66,7 @@ func (rc *ReqCtx) Download(filename string) { ginx.Download(rc.GinCtx, filename) } -// 新建请求上下文,默认需要校验token -func NewReqCtx() *ReqCtx { - return &ReqCtx{} -} - -func NewReqCtxWithGin(g *gin.Context) *ReqCtx { +func NewReqCtx(g *gin.Context) *ReqCtx { return &ReqCtx{GinCtx: g, RequiredPermission: &Permission{NeedToken: true, NeedCasbin: true}} } diff --git a/base/restfulx/restfulx.go b/base/restfulx/restfulx.go new file mode 100644 index 0000000..56a270b --- /dev/null +++ b/base/restfulx/restfulx.go @@ -0,0 +1,95 @@ +package restfulx + +import ( + "encoding/json" + "net/http" + "pandax/base/biz" + "pandax/base/model" + "pandax/pkg/global" + "strconv" + + "github.com/gin-gonic/gin" +) + +// 绑定并校验请求结构体参数 结构体添加 例如: binding:"required" 或binding:"required,gt=10" +func BindJsonAndValid(g *gin.Context, data any) { + if err := g.ShouldBindJSON(data); err != nil { + panic(any(biz.NewBizErr("传参格式错误:" + err.Error()))) + } +} + +// 绑定查询字符串到 +func BindQuery(g *gin.Context, data any) { + if err := g.ShouldBindQuery(data); err != nil { + panic(any(biz.NewBizErr(err.Error()))) + } +} +func ParamsToAny(g *gin.Context, in any) { + vars := make(map[string]any) + for _, v := range g.Params { + vars[v.Key] = v.Value + } + marshal, _ := json.Marshal(vars) + err := json.Unmarshal(marshal, in) + biz.ErrIsNil(err, "error get path value encoding unmarshal") + return +} + +// 获取分页参数 +func GetPageParam(g *gin.Context) *model.PageParam { + return &model.PageParam{PageNum: QueryInt(g, "pageNum", 1), PageSize: QueryInt(g, "pageSize", 10)} +} + +// 获取查询参数中指定参数值,并转为int +func QueryInt(g *gin.Context, qm string, defaultInt int) int { + qv := g.Query(qm) + if qv == "" { + return defaultInt + } + qvi, err := strconv.Atoi(qv) + biz.ErrIsNil(err, "query param not int") + return qvi +} + +// 获取路径参数 +func PathParamInt(g *gin.Context, pm string) int { + value, _ := strconv.Atoi(g.Param(pm)) + return value +} + +// 文件下载 +func Download(g *gin.Context, filename string) { + g.Writer.Header().Add("success", "true") + g.Writer.Header().Set("Content-Length", "-1") + g.Writer.Header().Set("Content-Disposition", "attachment; filename="+filename) + g.File(filename) +} + +// 返回统一成功结果 +func SuccessRes(g *gin.Context, data any) { + g.JSON(http.StatusOK, model.Success(data)) +} + +// 返回失败结果集 +func ErrorRes(g *gin.Context, err any) { + if err != nil { + + } + switch t := err.(type) { + case *biz.BizError: + g.JSON(http.StatusOK, model.Error(t)) + break + case error: + g.JSON(http.StatusOK, model.ServerError()) + global.Log.Error(t) + // panic(err) + break + case string: + g.JSON(http.StatusOK, model.ServerError()) + global.Log.Error(t) + // panic(err) + break + default: + global.Log.Error(t) + } +} diff --git a/base/ctx/token.go b/base/token/token.go similarity index 99% rename from base/ctx/token.go rename to base/token/token.go index fdd4991..6e2d023 100644 --- a/base/ctx/token.go +++ b/base/token/token.go @@ -1,4 +1,4 @@ -package ctx +package token import ( "errors" diff --git a/main.go b/main.go index 3522759..4d310c4 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ import ( "os" "pandax/apps/job/jobs" "pandax/base/config" - "pandax/base/ctx" + "pandax/base/ginx" "pandax/base/logger" "pandax/base/starter" "pandax/pkg/global" @@ -31,11 +31,11 @@ var rootCmd = &cobra.Command{ } }, Run: func(cmd *cobra.Command, args []string) { - ctx.UseAfterHandlerInterceptor(middleware.OperationHandler) + ginx.UseAfterHandlerInterceptor(middleware.OperationHandler) // gin前置 函数 - ctx.UseBeforeHandlerInterceptor(ctx.PermissionHandler) + ginx.UseBeforeHandlerInterceptor(ginx.PermissionHandler) // gin后置 函数 - ctx.UseAfterHandlerInterceptor(ctx.LogHandler) + ginx.UseAfterHandlerInterceptor(ginx.LogHandler) go func() { // 启动系统调度任务 jobs.InitJob() diff --git a/pkg/middleware/oper.go b/pkg/middleware/oper.go index 484df90..fc09ea2 100644 --- a/pkg/middleware/oper.go +++ b/pkg/middleware/oper.go @@ -4,11 +4,11 @@ import ( "net/http" "pandax/apps/log/entity" "pandax/apps/log/services" - "pandax/base/ctx" + "pandax/base/ginx" "pandax/base/utils" ) -func OperationHandler(rc *ctx.ReqCtx) error { +func OperationHandler(rc *ginx.ReqCtx) error { c := rc.GinCtx // 请求操作不做记录 if c.Request.Method == http.MethodGet || rc.LoginAccount == nil { diff --git a/resource/template/go/api.template b/resource/template/go/api.template index 09d0a70..f75d682 100644 --- a/resource/template/go/api.template +++ b/resource/template/go/api.template @@ -7,7 +7,7 @@ package api import ( "pandax/apps/{{.PackageName}}/entity" "pandax/apps/{{.PackageName}}/services" - "pandax/base/ctx" + "pandax/base/ginx" "pandax/base/ginx" "pandax/base/utils" ) @@ -23,7 +23,7 @@ type {{.ClassName}}Api struct { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /{{.PackageName}}/{{.BusinessName}}/list [get] // @Security -func (p *{{.ClassName}}Api) Get{{.ClassName}}List(rc *ctx.ReqCtx) { +func (p *{{.ClassName}}Api) Get{{.ClassName}}List(rc *ginx.ReqCtx) { data := entity.{{.ClassName}}{} pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1) pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10) @@ -54,7 +54,7 @@ func (p *{{.ClassName}}Api) Get{{.ClassName}}List(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "data": [...]}" // @Router /{{.PackageName}}/{{.BusinessName}}/{{"{"}}{{.PkJsonField}}{{"}"}} [get] // @Security -func (p *{{.ClassName}}Api) Get{{.ClassName}}(rc *ctx.ReqCtx) { +func (p *{{.ClassName}}Api) Get{{.ClassName}}(rc *ginx.ReqCtx) { {{.PkJsonField}} := ginx.PathParamInt(rc.GinCtx, "{{.PkJsonField}}") p.{{.ClassName}}App.FindOne(int64({{.PkJsonField}})) } @@ -69,7 +69,7 @@ func (p *{{.ClassName}}Api) Get{{.ClassName}}(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /{{.PackageName}}/{{.BusinessName}} [post] // @Security X-TOKEN -func (p *{{.ClassName}}Api) Insert{{.ClassName}}(rc *ctx.ReqCtx) { +func (p *{{.ClassName}}Api) Insert{{.ClassName}}(rc *ginx.ReqCtx) { var data entity.{{.ClassName}} ginx.BindJsonAndValid(rc.GinCtx, &data) @@ -86,7 +86,7 @@ func (p *{{.ClassName}}Api) Insert{{.ClassName}}(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "添加失败"}" // @Router /{{.PackageName}}/{{.BusinessName}} [put] // @Security X-TOKEN -func (p *{{.ClassName}}Api) Update{{.ClassName}}(rc *ctx.ReqCtx) { +func (p *{{.ClassName}}Api) Update{{.ClassName}}(rc *ginx.ReqCtx) { var data entity.{{.ClassName}} ginx.BindJsonAndValid(rc.GinCtx, &data) @@ -100,7 +100,7 @@ func (p *{{.ClassName}}Api) Update{{.ClassName}}(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 200, "message": "删除成功"}" // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /{{.PackageName}}/{{.BusinessName}}/{{"{"}}{{.PkJsonField}}{{"}"}} [delete] -func (p *{{.ClassName}}Api) Delete{{.ClassName}}(rc *ctx.ReqCtx) { +func (p *{{.ClassName}}Api) Delete{{.ClassName}}(rc *ginx.ReqCtx) { {{.PkJsonField}} := rc.GinCtx.Param("{{.PkJsonField}}") {{.PkJsonField}}s := utils.IdsStrToIdsIntGroup({{.PkJsonField}}) diff --git a/resource/template/go/router.template b/resource/template/go/router.template index 3a9248a..d492f23 100644 --- a/resource/template/go/router.template +++ b/resource/template/go/router.template @@ -9,7 +9,7 @@ import ( "github.com/gin-gonic/gin" "pandax/apps/{{.PackageName}}/api" "pandax/apps/{{.PackageName}}/services" - "pandax/base/ctx" + "pandax/base/ginx" ) func Init{{.ClassName}}Router(router *gin.RouterGroup) { @@ -18,29 +18,29 @@ func Init{{.ClassName}}Router(router *gin.RouterGroup) { } routerGroup := router.Group("{{.BusinessName}}") - {{.ClassName}}ListLog := ctx.NewLogInfo("获取{{.FunctionName}}分页列表") + {{.ClassName}}ListLog := ginx.NewLogInfo("获取{{.FunctionName}}分页列表") routerGroup.GET("list", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog({{.ClassName}}ListLog).Handle(s.Get{{.ClassName}}List) + ginx.NewReqCtx(c).WithLog({{.ClassName}}ListLog).Handle(s.Get{{.ClassName}}List) }) - {{.ClassName}}Log := ctx.NewLogInfo("获取{{.FunctionName}}信息") + {{.ClassName}}Log := ginx.NewLogInfo("获取{{.FunctionName}}信息") routerGroup.GET(":{{.PkJsonField}}", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog({{.ClassName}}Log).Handle(s.Get{{.ClassName}}) + ginx.NewReqCtx(c).WithLog({{.ClassName}}Log).Handle(s.Get{{.ClassName}}) }) - insert{{.ClassName}}Log := ctx.NewLogInfo("添加{{.FunctionName}}信息") + insert{{.ClassName}}Log := ginx.NewLogInfo("添加{{.FunctionName}}信息") routerGroup.POST("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(insert{{.ClassName}}Log).Handle(s.Insert{{.ClassName}}) + ginx.NewReqCtx(c).WithLog(insert{{.ClassName}}Log).Handle(s.Insert{{.ClassName}}) }) - update{{.ClassName}}Log := ctx.NewLogInfo("修改{{.FunctionName}}信息") + update{{.ClassName}}Log := ginx.NewLogInfo("修改{{.FunctionName}}信息") routerGroup.PUT("", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(update{{.ClassName}}Log).Handle(s.Update{{.ClassName}}) + ginx.NewReqCtx(c).WithLog(update{{.ClassName}}Log).Handle(s.Update{{.ClassName}}) }) - delete{{.ClassName}}Log := ctx.NewLogInfo("删除{{.FunctionName}}信息") + delete{{.ClassName}}Log := ginx.NewLogInfo("删除{{.FunctionName}}信息") routerGroup.DELETE(":{{.PkJsonField}}", func(c *gin.Context) { - ctx.NewReqCtxWithGin(c).WithLog(delete{{.ClassName}}Log).Handle(s.Delete{{.ClassName}}) + ginx.NewReqCtx(c).WithLog(delete{{.ClassName}}Log).Handle(s.Delete{{.ClassName}}) }) }