调整整体架构写法

调整db用法
调整日志用法
调整模版
This commit is contained in:
linwenxiang committed 2021-03-04 23:45:16 +08:00
1 parent 734a48dbb8
commit e2952fa393
137 files changed
+3638 -3544

No files matched your search

+67 -19
View File
@@ -1,28 +1,38 @@
package sys_post
import (
"net/http"
"github.com/gin-gonic/gin"
"go-admin/app/admin/models/system"
"go-admin/app/admin/service"
"go-admin/app/admin/service/dto"
"go-admin/common/apis"
"go-admin/common/log"
"go-admin/tools"
"net/http"
)
type SysPost struct {
apis.Api
}
// @Summary 岗位列表数据
// @Description 获取JSON
// @Tags 岗位
// @Param postName query string false "postName"
// @Param postCode query string false "postCode"
// @Param postId query string false "postId"
// @Param status query string false "status"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/post [get]
// @Security Bearer
func (e *SysPost) GetSysPostList(c *gin.Context) {
msgID := tools.GenerateMsgIDFromContext(c)
log := e.GetLogger(c)
d := new(dto.SysPostSearch)
db, err := tools.GetOrm(c)
if err != nil {
log.Error(err)
log.Errorf("get db connection error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
@@ -36,7 +46,7 @@ func (e *SysPost) GetSysPostList(c *gin.Context) {
list := make([]system.SysPost, 0)
var count int64
serviceStudent := service.SysPost{}
serviceStudent.MsgID = msgID
serviceStudent.Log = log
serviceStudent.Orm = db
err = serviceStudent.GetSysPostPage(d, &list, &count)
if err != nil {
@@ -47,15 +57,23 @@ func (e *SysPost) GetSysPostList(c *gin.Context) {
e.PageOK(c, list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
}
// @Summary 获取岗位信息
// @Description 获取JSON
// @Tags 岗位
// @Param postId path int true "postId"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/post/{postId} [get]
// @Security Bearer
func (e *SysPost) GetSysPost(c *gin.Context) {
log := e.GetLogger(c)
control := new(dto.SysPostById)
db, err := tools.GetOrm(c)
if err != nil {
log.Error(err)
log.Errorf("get db connection error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
msgID := tools.GenerateMsgIDFromContext(c)
//查看详情
err = control.Bind(c)
if err != nil {
@@ -65,7 +83,7 @@ func (e *SysPost) GetSysPost(c *gin.Context) {
var object system.SysPost
serviceSysOperlog := service.SysPost{}
serviceSysOperlog.MsgID = msgID
serviceSysOperlog.Log = log
serviceSysOperlog.Orm = db
err = serviceSysOperlog.GetSysPost(control, &object)
if err != nil {
@@ -76,15 +94,26 @@ func (e *SysPost) GetSysPost(c *gin.Context) {
e.OK(c, object, "查看成功")
}
// @Summary 添加岗位
// @Description 获取JSON
// @Tags 岗位
// @Accept application/json
// @Product application/json
// @Param data body models.Post true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/post [post]
// @Security Bearer
func (e *SysPost) InsertSysPost(c *gin.Context) {
log := e.GetLogger(c)
control := new(dto.SysPostControl)
db, err := tools.GetOrm(c)
if err != nil {
log.Error(err)
log.Errorf("get db connection error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
msgID := tools.GenerateMsgIDFromContext(c)
//新增操作
err = control.Bind(c)
if err != nil {
@@ -101,7 +130,7 @@ func (e *SysPost) InsertSysPost(c *gin.Context) {
serviceSysPost := service.SysPost{}
serviceSysPost.Orm = db
serviceSysPost.MsgID = msgID
serviceSysPost.Log = log
err = serviceSysPost.InsertSysPost(object)
if err != nil {
log.Error(err)
@@ -112,15 +141,26 @@ func (e *SysPost) InsertSysPost(c *gin.Context) {
e.OK(c, object.GetId(), "创建成功")
}
// @Summary 修改岗位
// @Description 获取JSON
// @Tags 岗位
// @Accept application/json
// @Product application/json
// @Param data body models.Post true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/post/ [put]
// @Security Bearer
func (e *SysPost) UpdateSysPost(c *gin.Context) {
log := e.GetLogger(c)
control := new(dto.SysPostControl)
db, err := tools.GetOrm(c)
if err != nil {
log.Error(err)
log.Errorf("get db connection error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
msgID := tools.GenerateMsgIDFromContext(c)
//更新操作
err = control.Bind(c)
if err != nil {
@@ -136,7 +176,7 @@ func (e *SysPost) UpdateSysPost(c *gin.Context) {
serviceSysPost := service.SysPost{}
serviceSysPost.Orm = db
serviceSysPost.MsgID = msgID
serviceSysPost.Log = log
err = serviceSysPost.UpdateSysPost(object)
if err != nil {
log.Error(err)
@@ -145,26 +185,34 @@ func (e *SysPost) UpdateSysPost(c *gin.Context) {
e.OK(c, object.GetId(), "更新成功")
}
// @Summary 删除岗位
// @Description 删除数据
// @Tags 岗位
// @Param id path int true "id"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 500 {string} string "{"code": 500, "message": "删除失败"}"
// @Router /api/v1/post/{postId} [delete]
func (e *SysPost) DeleteSysPost(c *gin.Context) {
log := e.GetLogger(c)
control := new(dto.SysPostById)
db, err := tools.GetOrm(c)
if err != nil {
log.Error(err)
log.Errorf("get db connection error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
msgID := tools.GenerateMsgIDFromContext(c)
//删除操作
err = control.Bind(c)
if err != nil {
log.Errorf("MsgID[%s] Bind error: %s", msgID, err)
log.Errorf("Bind error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
serviceSysPost := service.SysPost{}
serviceSysPost.Orm = db
serviceSysPost.MsgID = msgID
serviceSysPost.Log = log
err = serviceSysPost.RemoveSysPost(control)
if err != nil {
log.Error(err)