调整整体架构写法
调整db用法 调整日志用法 调整模版
This commit is contained in:
1 parent
734a48dbb8
commit
e2952fa393
137 files changed
+3638
-3544
No files matched your search
@@ -1,27 +1,37 @@
|
||||
package sys_dept
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/app/admin/models"
|
||||
|
||||
"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 SysDept struct {
|
||||
apis.Api
|
||||
}
|
||||
|
||||
// @Summary 分页部门列表数据
|
||||
// @Description 分页列表
|
||||
// @Tags 部门
|
||||
// @Param name query string false "name"
|
||||
// @Param id query string false "id"
|
||||
// @Param position query string false "position"
|
||||
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
|
||||
// @Router /api/v1/dept [get]
|
||||
// @Security Bearer
|
||||
func (e *SysDept) GetSysDeptList(c *gin.Context) {
|
||||
msgID := tools.GenerateMsgIDFromContext(c)
|
||||
log := e.GetLogger(c)
|
||||
d := new(dto.SysDeptSearch)
|
||||
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
|
||||
}
|
||||
|
||||
@@ -32,9 +42,9 @@ func (e *SysDept) GetSysDeptList(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
list := make([]models.SysDept, 0)
|
||||
list := make([]system.SysDept, 0)
|
||||
serviceStudent := service.SysDept{}
|
||||
serviceStudent.MsgID = msgID
|
||||
serviceStudent.Log = log
|
||||
serviceStudent.Orm = db
|
||||
list, err = serviceStudent.SetDeptPage(d)
|
||||
if err != nil {
|
||||
@@ -45,25 +55,34 @@ func (e *SysDept) GetSysDeptList(c *gin.Context) {
|
||||
e.OK(c, list, "查询成功")
|
||||
}
|
||||
|
||||
// @Summary 部门列表数据
|
||||
// @Description 获取JSON
|
||||
// @Tags 部门
|
||||
// @Param deptId path string false "deptId"
|
||||
// @Param position query string false "position"
|
||||
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
|
||||
// @Router /api/v1/dept/{deptId} [get]
|
||||
// @Security Bearer
|
||||
func (e *SysDept) GetSysDept(c *gin.Context) {
|
||||
log := e.GetLogger(c)
|
||||
control := new(dto.SysDeptById)
|
||||
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 {
|
||||
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||
return
|
||||
}
|
||||
var object models.SysDept
|
||||
var object system.SysDept
|
||||
|
||||
serviceSysOperlog := service.SysDept{}
|
||||
serviceSysOperlog.MsgID = msgID
|
||||
serviceSysOperlog.Log = log
|
||||
serviceSysOperlog.Orm = db
|
||||
err = serviceSysOperlog.GetSysDept(control, &object)
|
||||
if err != nil {
|
||||
@@ -74,15 +93,26 @@ func (e *SysDept) GetSysDept(c *gin.Context) {
|
||||
e.OK(c, object, "查看成功")
|
||||
}
|
||||
|
||||
// @Summary 添加部门
|
||||
// @Description 获取JSON
|
||||
// @Tags 部门
|
||||
// @Accept application/json
|
||||
// @Product application/json
|
||||
// @Param data body models.SysDept true "data"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
||||
// @Router /api/v1/dept [post]
|
||||
// @Security Bearer
|
||||
func (e *SysDept) InsertSysDept(c *gin.Context) {
|
||||
log := e.GetLogger(c)
|
||||
control := new(dto.SysDeptControl)
|
||||
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 {
|
||||
@@ -99,7 +129,7 @@ func (e *SysDept) InsertSysDept(c *gin.Context) {
|
||||
|
||||
serviceSysDept := service.SysDept{}
|
||||
serviceSysDept.Orm = db
|
||||
serviceSysDept.MsgID = msgID
|
||||
serviceSysDept.Log = log
|
||||
err = serviceSysDept.InsertSysDept(object)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
@@ -110,15 +140,27 @@ func (e *SysDept) InsertSysDept(c *gin.Context) {
|
||||
e.OK(c, object.GetId(), "创建成功")
|
||||
}
|
||||
|
||||
// @Summary 修改部门
|
||||
// @Description 获取JSON
|
||||
// @Tags 部门
|
||||
// @Accept application/json
|
||||
// @Product application/json
|
||||
// @Param id path int true "id"
|
||||
// @Param data body models.SysDept true "body"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
||||
// @Router /api/v1/dept/{deptId} [put]
|
||||
// @Security Bearer
|
||||
func (e *SysDept) UpdateSysDept(c *gin.Context) {
|
||||
log := e.GetLogger(c)
|
||||
control := new(dto.SysDeptControl)
|
||||
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 {
|
||||
@@ -134,7 +176,7 @@ func (e *SysDept) UpdateSysDept(c *gin.Context) {
|
||||
|
||||
serviceSysDept := service.SysDept{}
|
||||
serviceSysDept.Orm = db
|
||||
serviceSysDept.MsgID = msgID
|
||||
serviceSysDept.Log = log
|
||||
err = serviceSysDept.UpdateSysDept(object)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
@@ -143,29 +185,38 @@ func (e *SysDept) UpdateSysDept(c *gin.Context) {
|
||||
e.OK(c, object.GetId(), "更新成功")
|
||||
}
|
||||
|
||||
// @Summary 删除部门
|
||||
// @Description 删除数据
|
||||
// @Tags 部门
|
||||
// @Param data body []int true "body"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
|
||||
// @Router /api/v1/dept [delete]
|
||||
func (e *SysDept) DeleteSysDept(c *gin.Context) {
|
||||
log := e.GetLogger(c)
|
||||
control := new(dto.SysDeptById)
|
||||
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
|
||||
}
|
||||
|
||||
serviceSysDept := service.SysDept{}
|
||||
serviceSysDept.Orm = db
|
||||
serviceSysDept.MsgID = msgID
|
||||
serviceSysDept.Log = log
|
||||
err = serviceSysDept.RemoveSysDept(control)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Errorf("RemoveSysDept error, %s", err.Error())
|
||||
e.Error(c, http.StatusInternalServerError, err, "删除失败")
|
||||
return
|
||||
}
|
||||
e.OK(c, control.GetId(), "删除成功")
|
||||
@@ -173,11 +224,12 @@ func (e *SysDept) DeleteSysDept(c *gin.Context) {
|
||||
|
||||
// GetDeptTree 用户管理 左侧部门树
|
||||
func (e *SysDept) GetDeptTree(c *gin.Context) {
|
||||
msgID := tools.GenerateMsgIDFromContext(c)
|
||||
log := e.GetLogger(c)
|
||||
d := new(dto.SysDeptSearch)
|
||||
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
|
||||
}
|
||||
|
||||
@@ -190,7 +242,7 @@ func (e *SysDept) GetDeptTree(c *gin.Context) {
|
||||
|
||||
list := make([]dto.DeptLabel, 0)
|
||||
serviceStudent := service.SysDept{}
|
||||
serviceStudent.MsgID = msgID
|
||||
serviceStudent.Log = log
|
||||
serviceStudent.Orm = db
|
||||
list, err = serviceStudent.SetDeptTree(d)
|
||||
if err != nil {
|
||||
@@ -205,4 +257,32 @@ func (e *SysDept) GetDeptTree(c *gin.Context) {
|
||||
//result, err := Dept.SetDept(false)
|
||||
//tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
e.OK(c, list, "")
|
||||
}
|
||||
}
|
||||
|
||||
//func (e *SysDept) GetDeptTreeRoleSelect(c *gin.Context) {
|
||||
// log := e.GetLogger(c)
|
||||
// db, err := tools.GetOrm(c)
|
||||
// if err != nil {
|
||||
// log.Error(err)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// s := service.SysDept{}
|
||||
// s.Orm = db
|
||||
// s.MsgID = msgID
|
||||
// id, err := tools.StringToInt(c.Param("roleId"))
|
||||
// result, err := s.SetDeptLabel()
|
||||
// if err != nil {
|
||||
// log.Errorf("SetDeptLabel error, %s", msgID, err.Error())
|
||||
// e.Error(c, http.StatusInternalServerError, err, "")
|
||||
// }
|
||||
// menuIds := make([]int, 0)
|
||||
// if id != 0 {
|
||||
// menuIds, err = s.GetRoleDeptId(id)
|
||||
// tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
// }
|
||||
// e.OK(c, gin.H{
|
||||
// "depts": result,
|
||||
// "checkedKeys": menuIds,
|
||||
// }, "")
|
||||
//}
|
||||
Reference in new issue
Block a user