|
| 1 | +package system |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/flipped-aurora/gin-vue-admin/server/global" |
| 5 | + "github.com/flipped-aurora/gin-vue-admin/server/model/common/response" |
| 6 | + "github.com/flipped-aurora/gin-vue-admin/server/model/system" |
| 7 | + systemReq "github.com/flipped-aurora/gin-vue-admin/server/model/system/request" |
| 8 | + "github.com/gin-gonic/gin" |
| 9 | + "go.uber.org/zap" |
| 10 | +) |
| 11 | + |
| 12 | +type SysErrorApi struct{} |
| 13 | + |
| 14 | +// CreateSysError 创建错误日志 |
| 15 | +// @Tags SysError |
| 16 | +// @Summary 创建错误日志 |
| 17 | +// @Security ApiKeyAuth |
| 18 | +// @Accept application/json |
| 19 | +// @Produce application/json |
| 20 | +// @Param data body system.SysError true "创建错误日志" |
| 21 | +// @Success 200 {object} response.Response{msg=string} "创建成功" |
| 22 | +// @Router /sysErrpr/createSysError [post] |
| 23 | +func (sysErrprApi *SysErrorApi) CreateSysError(c *gin.Context) { |
| 24 | + // 创建业务用Context |
| 25 | + ctx := c.Request.Context() |
| 26 | + |
| 27 | + var sysErrpr system.SysError |
| 28 | + err := c.ShouldBindJSON(&sysErrpr) |
| 29 | + if err != nil { |
| 30 | + response.FailWithMessage(err.Error(), c) |
| 31 | + return |
| 32 | + } |
| 33 | + err = sysErrprService.CreateSysError(ctx, &sysErrpr) |
| 34 | + if err != nil { |
| 35 | + global.GVA_LOG.Error("创建失败!", zap.Error(err)) |
| 36 | + response.FailWithMessage("创建失败:"+err.Error(), c) |
| 37 | + return |
| 38 | + } |
| 39 | + response.OkWithMessage("创建成功", c) |
| 40 | +} |
| 41 | + |
| 42 | +// DeleteSysError 删除错误日志 |
| 43 | +// @Tags SysError |
| 44 | +// @Summary 删除错误日志 |
| 45 | +// @Security ApiKeyAuth |
| 46 | +// @Accept application/json |
| 47 | +// @Produce application/json |
| 48 | +// @Param data body system.SysError true "删除错误日志" |
| 49 | +// @Success 200 {object} response.Response{msg=string} "删除成功" |
| 50 | +// @Router /sysErrpr/deleteSysError [delete] |
| 51 | +func (sysErrprApi *SysErrorApi) DeleteSysError(c *gin.Context) { |
| 52 | + // 创建业务用Context |
| 53 | + ctx := c.Request.Context() |
| 54 | + |
| 55 | + ID := c.Query("ID") |
| 56 | + err := sysErrprService.DeleteSysError(ctx, ID) |
| 57 | + if err != nil { |
| 58 | + global.GVA_LOG.Error("删除失败!", zap.Error(err)) |
| 59 | + response.FailWithMessage("删除失败:"+err.Error(), c) |
| 60 | + return |
| 61 | + } |
| 62 | + response.OkWithMessage("删除成功", c) |
| 63 | +} |
| 64 | + |
| 65 | +// DeleteSysErrorByIds 批量删除错误日志 |
| 66 | +// @Tags SysError |
| 67 | +// @Summary 批量删除错误日志 |
| 68 | +// @Security ApiKeyAuth |
| 69 | +// @Accept application/json |
| 70 | +// @Produce application/json |
| 71 | +// @Success 200 {object} response.Response{msg=string} "批量删除成功" |
| 72 | +// @Router /sysErrpr/deleteSysErrorByIds [delete] |
| 73 | +func (sysErrprApi *SysErrorApi) DeleteSysErrorByIds(c *gin.Context) { |
| 74 | + // 创建业务用Context |
| 75 | + ctx := c.Request.Context() |
| 76 | + |
| 77 | + IDs := c.QueryArray("IDs[]") |
| 78 | + err := sysErrprService.DeleteSysErrorByIds(ctx, IDs) |
| 79 | + if err != nil { |
| 80 | + global.GVA_LOG.Error("批量删除失败!", zap.Error(err)) |
| 81 | + response.FailWithMessage("批量删除失败:"+err.Error(), c) |
| 82 | + return |
| 83 | + } |
| 84 | + response.OkWithMessage("批量删除成功", c) |
| 85 | +} |
| 86 | + |
| 87 | +// UpdateSysError 更新错误日志 |
| 88 | +// @Tags SysError |
| 89 | +// @Summary 更新错误日志 |
| 90 | +// @Security ApiKeyAuth |
| 91 | +// @Accept application/json |
| 92 | +// @Produce application/json |
| 93 | +// @Param data body system.SysError true "更新错误日志" |
| 94 | +// @Success 200 {object} response.Response{msg=string} "更新成功" |
| 95 | +// @Router /sysErrpr/updateSysError [put] |
| 96 | +func (sysErrprApi *SysErrorApi) UpdateSysError(c *gin.Context) { |
| 97 | + // 从ctx获取标准context进行业务行为 |
| 98 | + ctx := c.Request.Context() |
| 99 | + |
| 100 | + var sysErrpr system.SysError |
| 101 | + err := c.ShouldBindJSON(&sysErrpr) |
| 102 | + if err != nil { |
| 103 | + response.FailWithMessage(err.Error(), c) |
| 104 | + return |
| 105 | + } |
| 106 | + err = sysErrprService.UpdateSysError(ctx, sysErrpr) |
| 107 | + if err != nil { |
| 108 | + global.GVA_LOG.Error("更新失败!", zap.Error(err)) |
| 109 | + response.FailWithMessage("更新失败:"+err.Error(), c) |
| 110 | + return |
| 111 | + } |
| 112 | + response.OkWithMessage("更新成功", c) |
| 113 | +} |
| 114 | + |
| 115 | +// FindSysError 用id查询错误日志 |
| 116 | +// @Tags SysError |
| 117 | +// @Summary 用id查询错误日志 |
| 118 | +// @Security ApiKeyAuth |
| 119 | +// @Accept application/json |
| 120 | +// @Produce application/json |
| 121 | +// @Param ID query uint true "用id查询错误日志" |
| 122 | +// @Success 200 {object} response.Response{data=system.SysError,msg=string} "查询成功" |
| 123 | +// @Router /sysErrpr/findSysError [get] |
| 124 | +func (sysErrprApi *SysErrorApi) FindSysError(c *gin.Context) { |
| 125 | + // 创建业务用Context |
| 126 | + ctx := c.Request.Context() |
| 127 | + |
| 128 | + ID := c.Query("ID") |
| 129 | + resysErrpr, err := sysErrprService.GetSysError(ctx, ID) |
| 130 | + if err != nil { |
| 131 | + global.GVA_LOG.Error("查询失败!", zap.Error(err)) |
| 132 | + response.FailWithMessage("查询失败:"+err.Error(), c) |
| 133 | + return |
| 134 | + } |
| 135 | + response.OkWithData(resysErrpr, c) |
| 136 | +} |
| 137 | + |
| 138 | +// GetSysErrorList 分页获取错误日志列表 |
| 139 | +// @Tags SysError |
| 140 | +// @Summary 分页获取错误日志列表 |
| 141 | +// @Security ApiKeyAuth |
| 142 | +// @Accept application/json |
| 143 | +// @Produce application/json |
| 144 | +// @Param data query systemReq.SysErrorSearch true "分页获取错误日志列表" |
| 145 | +// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功" |
| 146 | +// @Router /sysErrpr/getSysErrorList [get] |
| 147 | +func (sysErrprApi *SysErrorApi) GetSysErrorList(c *gin.Context) { |
| 148 | + // 创建业务用Context |
| 149 | + ctx := c.Request.Context() |
| 150 | + |
| 151 | + var pageInfo systemReq.SysErrorSearch |
| 152 | + err := c.ShouldBindQuery(&pageInfo) |
| 153 | + if err != nil { |
| 154 | + response.FailWithMessage(err.Error(), c) |
| 155 | + return |
| 156 | + } |
| 157 | + list, total, err := sysErrprService.GetSysErrorInfoList(ctx, pageInfo) |
| 158 | + if err != nil { |
| 159 | + global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| 160 | + response.FailWithMessage("获取失败:"+err.Error(), c) |
| 161 | + return |
| 162 | + } |
| 163 | + response.OkWithDetailed(response.PageResult{ |
| 164 | + List: list, |
| 165 | + Total: total, |
| 166 | + Page: pageInfo.Page, |
| 167 | + PageSize: pageInfo.PageSize, |
| 168 | + }, "获取成功", c) |
| 169 | +} |
0 commit comments