调整整体架构写法

调整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

+47 -28
View File
@@ -1,15 +1,15 @@
package sys_file
import (
"github.com/gin-gonic/gin"
"go-admin/app/admin/service"
"net/http"
"github.com/gin-gonic/gin"
"go-admin/app/admin/models"
"go-admin/app/admin/service"
"go-admin/app/admin/service/dto"
"go-admin/common/actions"
"go-admin/common/apis"
"go-admin/common/log"
"go-admin/tools"
)
@@ -18,25 +18,27 @@ type SysFileDir struct {
}
func (e *SysFileDir) GetSysFileDirList(c *gin.Context) {
msgID := tools.GenerateMsgIDFromContext(c)
log := e.GetLogger(c)
search := new(dto.SysFileDirSearch)
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
}
err = c.ShouldBind(search)
if err != nil {
log.Debugf("MsgID[%s] ShouldBind error: %s", msgID, err.Error())
log.Debugf("ShouldBind error: %s", err.Error())
}
var list *[]models.SysFileDirL
serviceStudent := service.SysFileDir{}
serviceStudent.MsgID = msgID
serviceStudent.Log = log
serviceStudent.Orm = db
list, err = serviceStudent.SetSysFileDir(search)
if err != nil {
log.Errorf("SetSysFileDir error, %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
return
}
@@ -46,27 +48,30 @@ func (e *SysFileDir) GetSysFileDirList(c *gin.Context) {
func (e *SysFileDir) GetSysFileDir(c *gin.Context) {
control := new(dto.SysFileDirById)
log := e.GetLogger(c)
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 = c.ShouldBindUri(control)
if err != nil {
log.Debugf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
log.Warnf("ShouldBindUri error: %s", err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
}
var object models.SysFileDir
serviceSysFileDir := service.SysFileDir{}
serviceSysFileDir.MsgID = msgID
serviceSysFileDir.Log = log
serviceSysFileDir.Orm = db
err = serviceSysFileDir.GetSysFileDir(control, &object)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
log.Errorf("GetSysFileDir error, %s", err)
e.Error(c, http.StatusInternalServerError, err, "查询失败")
return
}
@@ -75,31 +80,36 @@ func (e *SysFileDir) GetSysFileDir(c *gin.Context) {
func (e *SysFileDir) InsertSysFileDir(c *gin.Context) {
control := new(dto.SysFileDirControl)
log := e.GetLogger(c)
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 = c.ShouldBindUri(control)
if err != nil {
log.Debugf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
log.Warnf("ShouldBindUri error: %s", err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
err = c.ShouldBind(control)
if err != nil {
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
log.Warnf("ShouldBind error: %s", err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
// 设置创建人
control.CreateBy = tools.GetUserId(c)
serviceSysFileDir := service.SysFileDir{}
serviceSysFileDir.Orm = db
serviceSysFileDir.MsgID = msgID
serviceSysFileDir.Log = log
err = serviceSysFileDir.InsertSysFileDir(control)
if err != nil {
log.Error(err)
log.Errorf("InsertSysFileDir error, %s", err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
return
}
@@ -109,20 +119,23 @@ func (e *SysFileDir) InsertSysFileDir(c *gin.Context) {
func (e *SysFileDir) UpdateSysFileDir(c *gin.Context) {
control := new(dto.SysFileDirControl)
log := e.GetLogger(c)
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 = c.ShouldBindUri(control)
if err != nil {
log.Debugf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
log.Warnf("ShouldBindUri error: %s", err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
}
err = c.ShouldBind(control)
if err != nil {
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
log.Warnf("ShouldBind error: %#v", err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
}
// 设置创建人
control.UpdateBy = tools.GetUserId(c)
@@ -132,10 +145,11 @@ func (e *SysFileDir) UpdateSysFileDir(c *gin.Context) {
serviceSysFileDir := service.SysFileDir{}
serviceSysFileDir.Orm = db
serviceSysFileDir.MsgID = msgID
serviceSysFileDir.Log = log
err = serviceSysFileDir.UpdateSysFileDir(control, p)
if err != nil {
log.Error(err)
log.Errorf("UpdateSysFileDir error, %s", err)
e.Error(c, http.StatusInternalServerError, err, "更新失败")
return
}
e.OK(c, control.ID, "更新成功")
@@ -143,9 +157,11 @@ func (e *SysFileDir) UpdateSysFileDir(c *gin.Context) {
func (e *SysFileDir) DeleteSysFileDir(c *gin.Context) {
control := new(dto.SysFileDirById)
log := e.GetLogger(c)
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
}
@@ -153,11 +169,13 @@ func (e *SysFileDir) DeleteSysFileDir(c *gin.Context) {
//删除操作
err = c.ShouldBindUri(control)
if err != nil {
log.Debugf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
log.Warnf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
}
err = c.ShouldBind(control)
if err != nil {
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
log.Warnf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
}
// 设置编辑人
@@ -171,7 +189,8 @@ func (e *SysFileDir) DeleteSysFileDir(c *gin.Context) {
serviceSysFileDir.MsgID = msgID
err = serviceSysFileDir.RemoveSysFileDir(control, p)
if err != nil {
log.Error(err)
log.Errorf("RemoveSysFileDir error, %s", err)
e.Error(c, http.StatusInternalServerError, err, "删除失败")
return
}
e.OK(c, control.Id, "删除成功")
+48 -40
View File
@@ -1,16 +1,15 @@
package sys_file
import (
"github.com/gin-gonic/gin"
"go-admin/app/admin/service"
"go-admin/tools/app"
"net/http"
"github.com/gin-gonic/gin"
"go-admin/app/admin/models"
"go-admin/app/admin/service"
"go-admin/app/admin/service/dto"
"go-admin/common/actions"
"go-admin/common/apis"
"go-admin/common/log"
"go-admin/tools"
)
@@ -19,17 +18,18 @@ type SysFileInfo struct {
}
func (e *SysFileInfo) GetSysFileInfoList(c *gin.Context) {
msgID := tools.GenerateMsgIDFromContext(c)
log := e.GetLogger(c)
search := new(dto.SysFileInfoSearch)
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
}
err = c.ShouldBind(search)
if err != nil {
log.Errorf("msgID[%s] 参数验证错误, error:%s", msgID, err)
app.Error(c, 422, err, "参数验证失败")
log.Warnf("参数验证错误, error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -39,11 +39,12 @@ func (e *SysFileInfo) GetSysFileInfoList(c *gin.Context) {
list := make([]models.SysFileInfo, 0)
var count int64
serviceStudent := service.SysFileInfo{}
serviceStudent.MsgID = msgID
serviceStudent.Log = log
serviceStudent.Orm = db
err = serviceStudent.GetSysFileInfoPage(search, p, &list, &count)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
log.Errorf("GetSysFileInfoPage error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "查询失败")
return
}
@@ -52,18 +53,19 @@ func (e *SysFileInfo) GetSysFileInfoList(c *gin.Context) {
func (e *SysFileInfo) GetSysFileInfo(c *gin.Context) {
control := new(dto.SysFileInfoById)
log := e.GetLogger(c)
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 = c.ShouldBindUri(control)
if err != nil {
log.Errorf("msgID[%s] 参数验证错误, error:%s", msgID, err)
app.Error(c, 422, err, "参数验证失败")
log.Warnf("参数验证错误, error:%s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
@@ -73,11 +75,12 @@ func (e *SysFileInfo) GetSysFileInfo(c *gin.Context) {
p := actions.GetPermissionFromContext(c)
serviceSysFileInfo := service.SysFileInfo{}
serviceSysFileInfo.MsgID = msgID
serviceSysFileInfo.Log = log
serviceSysFileInfo.Orm = db
err = serviceSysFileInfo.GetSysFileInfo(control, p, &object)
if err != nil {
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
log.Errorf("GetSysFileInfo error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "查询失败")
return
}
@@ -86,24 +89,25 @@ func (e *SysFileInfo) GetSysFileInfo(c *gin.Context) {
func (e *SysFileInfo) InsertSysFileInfo(c *gin.Context) {
control := new(dto.SysFileInfoControl)
log := e.GetLogger(c)
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 = c.ShouldBindUri(control)
if err != nil {
log.Errorf("msgID[%s] 参数验证错误, error:%s", msgID, err)
app.Error(c, 422, err, "参数验证失败")
log.Warnf("参数验证错误, error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
err = c.ShouldBind(control)
if err != nil {
log.Errorf("msgID[%s] 参数验证错误, error:%s", msgID, err)
app.Error(c, 422, err, "参数验证失败")
log.Warnf("参数验证错误, error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
// 设置创建人
@@ -111,10 +115,10 @@ func (e *SysFileInfo) InsertSysFileInfo(c *gin.Context) {
serviceSysFileInfo := service.SysFileInfo{}
serviceSysFileInfo.Orm = db
serviceSysFileInfo.MsgID = msgID
serviceSysFileInfo.Log = log
err = serviceSysFileInfo.InsertSysFileInfo(control)
if err != nil {
log.Error(err)
log.Errorf("InsertSysFileInfo error: %s", err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
return
}
@@ -124,23 +128,24 @@ func (e *SysFileInfo) InsertSysFileInfo(c *gin.Context) {
func (e *SysFileInfo) UpdateSysFileInfo(c *gin.Context) {
control := new(dto.SysFileInfoControl)
log := e.GetLogger(c)
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 = c.ShouldBindUri(control)
if err != nil {
log.Errorf("msgID[%s] 参数验证错误, error:%s", msgID, err)
app.Error(c, 422, err, "参数验证失败")
log.Warnf("参数验证错误, error: %s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
err = c.ShouldBind(control)
if err != nil {
log.Errorf("msgID[%s] 参数验证错误, error:%s", msgID, err)
app.Error(c, 422, err, "参数验证失败")
log.Warnf("参数验证错误, error:%s", err)
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
// 设置创建人
@@ -151,10 +156,11 @@ func (e *SysFileInfo) UpdateSysFileInfo(c *gin.Context) {
serviceSysFileInfo := service.SysFileInfo{}
serviceSysFileInfo.Orm = db
serviceSysFileInfo.MsgID = msgID
serviceSysFileInfo.Log = log
err = serviceSysFileInfo.UpdateSysFileInfo(control, p)
if err != nil {
log.Error(err)
log.Errorf("UpdateSysFileInfo error: %s", err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
return
}
e.OK(c, control.ID, "更新成功")
@@ -162,24 +168,25 @@ func (e *SysFileInfo) UpdateSysFileInfo(c *gin.Context) {
func (e *SysFileInfo) DeleteSysFileInfo(c *gin.Context) {
control := new(dto.SysFileInfoById)
log := e.GetLogger(c)
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 = c.ShouldBindUri(control)
if err != nil {
log.Errorf("msgID[%s] 参数验证错误, error:%s", msgID, err)
app.Error(c, 422, err, "参数验证失败")
log.Warnf("参数验证错误, error: %s", err)
e.Error(c, 422, err, "参数验证失败")
return
}
err = c.ShouldBind(control)
if err != nil {
log.Errorf("msgID[%s] 参数验证错误, error:%s", msgID, err)
app.Error(c, 422, err, "参数验证失败")
log.Warnf("参数验证错误, error: %s", err)
e.Error(c, 422, err, "参数验证失败")
return
}
@@ -191,10 +198,11 @@ func (e *SysFileInfo) DeleteSysFileInfo(c *gin.Context) {
serviceSysFileInfo := service.SysFileInfo{}
serviceSysFileInfo.Orm = db
serviceSysFileInfo.MsgID = msgID
serviceSysFileInfo.Log = log
err = serviceSysFileInfo.RemoveSysFileInfo(control, p)
if err != nil {
log.Error(err)
log.Errorf("RemoveSysFileInfo error: %s", err)
e.Error(c, http.StatusInternalServerError, err, "创建失败")
return
}
e.OK(c, control.Id, "删除成功")