gorm升级到v2版本

This commit is contained in:
linwenxiang committed 2020-08-27 11:17:15 +08:00
1 parent 93cfe443d6
commit 60c7496f7b
56 files changed
+630 -477

No files matched your search

+3 -3
View File
@@ -53,9 +53,9 @@ func ServerInfo(c *gin.Context) {
memDic["usage"] = memUsedPercent
cpuDic := make(map[string]interface{}, 0)
cpuDic["cpuInfo"],_ = cpu.Info()
percent,_ := cpu.Percent(0,false)
cpuDic["Percent"] = tools.Round(percent[0],2)
cpuDic["cpuInfo"], _ = cpu.Info()
percent, _ := cpu.Percent(0, false)
cpuDic["Percent"] = tools.Round(percent[0], 2)
cpuDic["cpuNum"], _ = cpu.Counts(false)
app.Custum(c, gin.H{
+13 -13
View File
@@ -3,12 +3,12 @@ package public
import (
"encoding/base64"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"go-admin/pkg/utils"
"go-admin/tools/app"
"io/ioutil"
"fmt"
)
// @Summary 上传图片
@@ -21,17 +21,17 @@ import (
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/public/uploadFile [post]
func UploadFile(c *gin.Context) {
tag,_ := c.GetPostForm("type")
urlPerfix := fmt.Sprintf("http://%s/",c.Request.Host)
if tag == ""{
app.Error(c,200,errors.New(""),"缺少标识")
tag, _ := c.GetPostForm("type")
urlPerfix := fmt.Sprintf("http://%s/", c.Request.Host)
if tag == "" {
app.Error(c, 200, errors.New(""), "缺少标识")
return
} else {
switch tag {
case "1": // 单图
files,err := c.FormFile("file")
files, err := c.FormFile("file")
if err != nil {
app.Error(c,200,errors.New(""),"图片不能为空")
app.Error(c, 200, errors.New(""), "图片不能为空")
return
}
// 上传文件至指定目录
@@ -39,7 +39,7 @@ func UploadFile(c *gin.Context) {
singleFile := "static/uploadfile/" + guid + utils.GetExt(files.Filename)
_ = c.SaveUploadedFile(files, singleFile)
app.OK(c, urlPerfix + singleFile, "上传成功")
app.OK(c, urlPerfix+singleFile, "上传成功")
return
case "2": // 多图
files := c.Request.MultipartForm.File["file"]
@@ -48,16 +48,16 @@ func UploadFile(c *gin.Context) {
guid := uuid.New().String()
multipartFileName := "static/uploadfile/" + guid + utils.GetExt(f.Filename)
_ = c.SaveUploadedFile(f, multipartFileName)
multipartFile = append(multipartFile, urlPerfix + multipartFileName)
multipartFile = append(multipartFile, urlPerfix+multipartFileName)
}
app.OK(c, multipartFile, "上传成功")
return
case "3": // base64
files,_ := c.GetPostForm("file")
files, _ := c.GetPostForm("file")
ddd, _ := base64.StdEncoding.DecodeString(files)
guid := uuid.New().String()
_ = ioutil.WriteFile("static/uploadfile/" + guid+ ".jpg", ddd, 0666)
app.OK(c, urlPerfix + "static/uploadfile/" + guid+ ".jpg", "上传成功")
_ = ioutil.WriteFile("static/uploadfile/"+guid+".jpg", ddd, 0666)
app.OK(c, urlPerfix+"static/uploadfile/"+guid+".jpg", "上传成功")
}
}
}
}
+1 -1
View File
@@ -79,4 +79,4 @@ func DeleteSysCategory(c *gin.Context) {
_, err := data.BatchDelete(IDS)
tools.HasError(err, msg.DeletedFail, 500)
app.OK(c, nil, msg.DeletedSuccess)
}
}
+49 -50
View File
@@ -1,46 +1,45 @@
package syscontent
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/models"
"go-admin/tools"
"go-admin/tools/app"
"go-admin/tools/app/msg"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/models"
"go-admin/tools"
"go-admin/tools/app"
"go-admin/tools/app/msg"
)
func GetSysContentList(c *gin.Context) {
var data models.SysContent
var err error
var pageSize = 10
var pageIndex = 1
var data models.SysContent
var err error
var pageSize = 10
var pageIndex = 1
if size := c.Request.FormValue("pageSize"); size != "" {
pageSize = tools.StrToInt(err, size)
}
if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex = tools.StrToInt(err, index)
}
if size := c.Request.FormValue("pageSize"); size != "" {
pageSize = tools.StrToInt(err, size)
}
if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex = tools.StrToInt(err, index)
}
data.CateId = c.Request.FormValue("cateId")
data.Name = c.Request.FormValue("name")
data.Status = c.Request.FormValue("status")
data.CateId = c.Request.FormValue("cateId")
data.Name = c.Request.FormValue("name")
data.Status = c.Request.FormValue("status")
data.DataScope = tools.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex)
tools.HasError(err, "", -1)
data.DataScope = tools.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex)
tools.HasError(err, "", -1)
app.PageOK(c, result, count, pageIndex, pageSize, "")
app.PageOK(c, result, count, pageIndex, pageSize, "")
}
func GetSysContent(c *gin.Context) {
var data models.SysContent
data.Id, _ = tools.StringToInt(c.Param("id"))
result, err := data.Get()
tools.HasError(err, "抱歉未找到相关信息", -1)
var data models.SysContent
data.Id, _ = tools.StringToInt(c.Param("id"))
result, err := data.Get()
tools.HasError(err, "抱歉未找到相关信息", -1)
app.OK(c, result, "")
app.OK(c, result, "")
}
// @Summary 添加内容管理
@@ -53,32 +52,32 @@ app.OK(c, result, "")
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/syscontent [post]
func InsertSysContent(c *gin.Context) {
var data models.SysContent
err := c.ShouldBindJSON(&data)
data.CreateBy = tools.GetUserIdStr(c)
tools.HasError(err, "", 500)
result, err := data.Create()
tools.HasError(err, "", -1)
app.OK(c, result, "")
var data models.SysContent
err := c.ShouldBindJSON(&data)
data.CreateBy = tools.GetUserIdStr(c)
tools.HasError(err, "", 500)
result, err := data.Create()
tools.HasError(err, "", -1)
app.OK(c, result, "")
}
func UpdateSysContent(c *gin.Context) {
var data models.SysContent
err := c.BindWith(&data, binding.JSON)
tools.HasError(err, "数据解析失败", -1)
data.UpdateBy = tools.GetUserIdStr(c)
result, err := data.Update(data.Id)
tools.HasError(err, "", -1)
var data models.SysContent
err := c.BindWith(&data, binding.JSON)
tools.HasError(err, "数据解析失败", -1)
data.UpdateBy = tools.GetUserIdStr(c)
result, err := data.Update(data.Id)
tools.HasError(err, "", -1)
app.OK(c, result, "")
app.OK(c, result, "")
}
func DeleteSysContent(c *gin.Context) {
var data models.SysContent
data.UpdateBy = tools.GetUserIdStr(c)
var data models.SysContent
data.UpdateBy = tools.GetUserIdStr(c)
IDS := tools.IdsStrToIdsIntGroup("id", c)
_, err := data.BatchDelete(IDS)
tools.HasError(err, msg.DeletedFail, 500)
app.OK(c, nil, msg.DeletedSuccess)
}
IDS := tools.IdsStrToIdsIntGroup("id", c)
_, err := data.BatchDelete(IDS)
tools.HasError(err, msg.DeletedFail, 500)
app.OK(c, nil, msg.DeletedSuccess)
}
+1 -1
View File
@@ -67,4 +67,4 @@ func DeleteSysFileDir(c *gin.Context) {
_, err := data.BatchDelete(IDS)
tools.HasError(err, msg.DeletedFail, 500)
app.OK(c, nil, msg.DeletedSuccess)
}
}
+1 -1
View File
@@ -101,7 +101,7 @@ func StartJob(c *gin.Context) {
data.JobId, _ = tools.StringToInt(c.Param("jobId"))
result, err := data.Get()
tools.HasError(err, "", 500)
if result.JobType == 1{
if result.JobType == 1 {
var j = &jobs.HttpJob{}
j.InvokeTarget = result.InvokeTarget
j.CronExpression = result.CronExpression
+2 -2
View File
@@ -81,7 +81,7 @@ func InsertRole(c *gin.Context) {
data.RoleId = id
var t models.RoleMenu
if len(data.MenuIds)>0 {
if len(data.MenuIds) > 0 {
_, err = t.Insert(id, data.MenuIds)
tools.HasError(err, "", -1)
}
@@ -107,7 +107,7 @@ func UpdateRole(c *gin.Context) {
var t models.RoleMenu
_, err = t.DeleteRoleMenu(data.RoleId)
tools.HasError(err, "修改失败(delete rm)", -1)
if len(data.MenuIds)>0 {
if len(data.MenuIds) > 0 {
_, err2 := t.Insert(data.RoleId, data.MenuIds)
tools.HasError(err2, "修改失败(insert)", -1)
}
+1 -1
View File
@@ -72,7 +72,7 @@ func GetSysTables(c *gin.Context) {
func GetSysTablesInfo(c *gin.Context) {
var data tools.SysTables
if c.Request.FormValue("tableName")!="" {
if c.Request.FormValue("tableName") != "" {
data.TBName = c.Request.FormValue("tableName")
}
result, err := data.Get()