修改文件目录

This commit is contained in:
linwenxiang committed 2020-09-04 00:21:52 +08:00
1 parent 41b06c806a
commit 01ea376015
109 files changed
+180 -172

No files matched your search

+134
View File
@@ -0,0 +1,134 @@
package log
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/app/admin/models"
"go-admin/tools"
"go-admin/tools/app"
)
// @Summary 登录日志列表
// @Description 获取JSON
// @Tags 登录日志
// @Param status query string false "status"
// @Param dictCode query string false "dictCode"
// @Param dictType query string false "dictType"
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/loginloglist [get]
// @Security Bearer
func GetLoginLogList(c *gin.Context) {
var data models.LoginLog
var err error
var pageSize = 10
var pageIndex = 1
size := c.Request.FormValue("pageSize")
if size != "" {
pageSize = tools.StrToInt(err, size)
}
index := c.Request.FormValue("pageIndex")
if index != "" {
pageIndex = tools.StrToInt(err, index)
}
data.Username = c.Request.FormValue("username")
data.Status = c.Request.FormValue("status")
data.Ipaddr = c.Request.FormValue("ipaddr")
result, count, err := data.GetPage(pageSize, pageIndex)
tools.HasError(err, "", -1)
var mp = make(map[string]interface{}, 3)
mp["list"] = result
mp["count"] = count
mp["pageIndex"] = pageIndex
mp["pageSize"] = pageSize
var res app.Response
res.Data = mp
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 通过编码获取登录日志
// @Description 获取JSON
// @Tags 登录日志
// @Param infoId path int true "infoId"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/loginlog/{infoId} [get]
// @Security Bearer
func GetLoginLog(c *gin.Context) {
var LoginLog models.LoginLog
LoginLog.InfoId, _ = tools.StringToInt(c.Param("infoId"))
result, err := LoginLog.Get()
tools.HasError(err, "抱歉未找到相关信息", -1)
var res app.Response
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 添加登录日志
// @Description 获取JSON
// @Tags 登录日志
// @Accept application/json
// @Product application/json
// @Param data body models.LoginLog true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/loginlog [post]
// @Security Bearer
func InsertLoginLog(c *gin.Context) {
var data models.LoginLog
err := c.BindWith(&data, binding.JSON)
tools.HasError(err, "", 500)
result, err := data.Create()
tools.HasError(err, "", -1)
var res app.Response
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 修改登录日志
// @Description 获取JSON
// @Tags 登录日志
// @Accept application/json
// @Product application/json
// @Param data body models.LoginLog true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/loginlog [put]
// @Security Bearer
func UpdateLoginLog(c *gin.Context) {
var data models.LoginLog
err := c.BindWith(&data, binding.JSON)
tools.HasError(err, "", -1)
result, err := data.Update(data.InfoId)
tools.HasError(err, "", -1)
var res app.Response
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 批量删除登录日志
// @Description 删除数据
// @Tags 登录日志
// @Param infoId path string true "以逗号(,)分割的infoId"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/loginlog/{infoId} [delete]
func DeleteLoginLog(c *gin.Context) {
var data models.LoginLog
data.UpdateBy = tools.GetUserIdStr(c)
IDS := tools.IdsStrToIdsIntGroup("infoId", c)
_, err := data.BatchDelete(IDS)
tools.HasError(err, "修改失败", 500)
var res app.Response
res.Msg = "删除成功"
c.JSON(http.StatusOK, res.ReturnOK())
}
+113
View File
@@ -0,0 +1,113 @@
package log
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/app/admin/models"
"go-admin/tools"
"go-admin/tools/app"
)
// @Summary 登录日志列表
// @Description 获取JSON
// @Tags 登录日志
// @Param status query string false "status"
// @Param dictCode query string false "dictCode"
// @Param dictType query string false "dictType"
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/operloglist [get]
// @Security Bearer
func GetOperLogList(c *gin.Context) {
var data models.SysOperLog
var err error
var pageSize = 10
var pageIndex = 1
size := c.Request.FormValue("pageSize")
if size != "" {
pageSize = tools.StrToInt(err, size)
}
index := c.Request.FormValue("pageIndex")
if index != "" {
pageIndex = tools.StrToInt(err, index)
}
data.OperName = c.Request.FormValue("operName")
data.Status = c.Request.FormValue("status")
data.OperIp = c.Request.FormValue("operIp")
result, count, err := data.GetPage(pageSize, pageIndex)
tools.HasError(err, "", -1)
var mp = make(map[string]interface{}, 3)
mp["list"] = result
mp["count"] = count
mp["pageIndex"] = pageIndex
mp["pageSize"] = pageSize
var res app.Response
res.Data = mp
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 通过编码获取登录日志
// @Description 获取JSON
// @Tags 登录日志
// @Param infoId path int true "infoId"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/operlog/{infoId} [get]
// @Security Bearer
func GetOperLog(c *gin.Context) {
var OperLog models.SysOperLog
OperLog.OperId, _ = tools.StringToInt(c.Param("operId"))
result, err := OperLog.Get()
tools.HasError(err, "抱歉未找到相关信息", -1)
var res app.Response
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 添加操作日志
// @Description 获取JSON
// @Tags 操作日志
// @Accept application/json
// @Product application/json
// @Param data body models.SysOperLog true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/operlog [post]
// @Security Bearer
func InsertOperLog(c *gin.Context) {
var data models.SysOperLog
err := c.BindWith(&data, binding.JSON)
tools.HasError(err, "", 500)
result, err := data.Create()
tools.HasError(err, "", -1)
var res app.Response
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 批量删除操作日志
// @Description 删除数据
// @Tags 操作日志
// @Param operId path string true "以逗号(,)分割的operId"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/operlog/{operId} [delete]
func DeleteOperLog(c *gin.Context) {
var data models.SysOperLog
data.UpdateBy = tools.GetUserIdStr(c)
IDS := tools.IdsStrToIdsIntGroup("operId", c)
_, err := data.BatchDelete(IDS)
tools.HasError(err, "删除失败", 500)
var res app.Response
res.Msg = "删除成功"
c.JSON(http.StatusOK, res.ReturnOK())
}
+70
View File
@@ -0,0 +1,70 @@
package monitor
import (
"runtime"
"github.com/gin-gonic/gin"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/mem"
"go-admin/tools"
"go-admin/tools/app"
)
const (
B = 1
KB = 1024 * B
MB = 1024 * KB
GB = 1024 * MB
)
// @Summary 系统信息
// @Description 获取JSON
// @Tags 系统信息
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/settings/serverInfo [get]
func ServerInfo(c *gin.Context) {
osDic := make(map[string]interface{}, 0)
osDic["goOs"] = runtime.GOOS
osDic["arch"] = runtime.GOARCH
osDic["mem"] = runtime.MemProfileRate
osDic["compiler"] = runtime.Compiler
osDic["version"] = runtime.Version()
osDic["numGoroutine"] = runtime.NumGoroutine()
osDic["ip"] = tools.GetLocaHonst()
osDic["projectDir"] = tools.GetCurrentPath()
dis, _ := disk.Usage("/")
diskTotalGB := int(dis.Total) / GB
diskFreeGB := int(dis.Free) / GB
diskDic := make(map[string]interface{}, 0)
diskDic["total"] = diskTotalGB
diskDic["free"] = diskFreeGB
mem, _ := mem.VirtualMemory()
memUsedMB := int(mem.Used) / GB
memTotalMB := int(mem.Total) / GB
memFreeMB := int(mem.Free) / GB
memUsedPercent := int(mem.UsedPercent)
memDic := make(map[string]interface{}, 0)
memDic["total"] = memTotalMB
memDic["used"] = memUsedMB
memDic["free"] = memFreeMB
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["cpuNum"], _ = cpu.Counts(false)
app.Custum(c, gin.H{
"code": 200,
"os": osDic,
"mem": memDic,
"cpu": cpuDic,
"disk": diskDic,
})
}
+65
View File
@@ -0,0 +1,65 @@
package public
import (
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"go-admin/pkg/utils"
"go-admin/tools/app"
)
// @Summary 上传图片
// @Description 获取JSON
// @Tags 公共接口
// @Accept multipart/form-data
// @Param type query string true "type" (1:单图,2:多图, 3:base64图片)
// @Param file formData file true "file"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @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(""), "缺少标识")
return
} else {
switch tag {
case "1": // 单图
files, err := c.FormFile("file")
if err != nil {
app.Error(c, 200, errors.New(""), "图片不能为空")
return
}
// 上传文件至指定目录
guid := uuid.New().String()
singleFile := "static/uploadfile/" + guid + utils.GetExt(files.Filename)
_ = c.SaveUploadedFile(files, singleFile)
app.OK(c, urlPerfix+singleFile, "上传成功")
return
case "2": // 多图
files := c.Request.MultipartForm.File["file"]
multipartFile := make([]string, len(files))
for _, f := range files {
guid := uuid.New().String()
multipartFileName := "static/uploadfile/" + guid + utils.GetExt(f.Filename)
_ = c.SaveUploadedFile(f, multipartFileName)
multipartFile = append(multipartFile, urlPerfix+multipartFileName)
}
app.OK(c, multipartFile, "上传成功")
return
case "3": // base64
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", "上传成功")
}
}
}
+83
View File
@@ -0,0 +1,83 @@
package syscategory
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/app/admin/models"
"go-admin/tools"
"go-admin/tools/app"
"go-admin/tools/app/msg"
)
func GetSysCategoryList(c *gin.Context) {
var data models.SysCategory
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)
}
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)
app.PageOK(c, result, count, pageIndex, pageSize, "")
}
func GetSysCategory(c *gin.Context) {
var data models.SysCategory
data.Id, _ = tools.StringToInt(c.Param("id"))
result, err := data.Get()
tools.HasError(err, "抱歉未找到相关信息", -1)
app.OK(c, result, "")
}
// @Summary 添加分类
// @Description 获取JSON
// @Tags 分类
// @Accept application/json
// @Product application/json
// @Param data body models.SysCategory true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/syscategory [post]
func InsertSysCategory(c *gin.Context) {
var data models.SysCategory
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 UpdateSysCategory(c *gin.Context) {
var data models.SysCategory
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, "")
}
func DeleteSysCategory(c *gin.Context) {
var data models.SysCategory
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)
}
+84
View File
@@ -0,0 +1,84 @@
package syscontent
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/app/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
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.DataScope = tools.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex)
tools.HasError(err, "", -1)
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)
app.OK(c, result, "")
}
// @Summary 添加内容管理
// @Description 获取JSON
// @Tags 内容管理
// @Accept application/json
// @Product application/json
// @Param data body models.SysContent true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @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, "")
}
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)
app.OK(c, result, "")
}
func DeleteSysContent(c *gin.Context) {
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)
}
+71
View File
@@ -0,0 +1,71 @@
package sysfiledir
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/app/admin/models"
"go-admin/tools"
"go-admin/tools/app"
"go-admin/tools/app/msg"
)
func GetSysFileDirList(c *gin.Context) {
var SysFileDir models.SysFileDir
SysFileDir.Label = c.Request.FormValue("label")
SysFileDir.PId, _ = tools.StringToInt(c.Request.FormValue("pid"))
SysFileDir.Id, _ = tools.StringToInt(c.Request.FormValue("id"))
SysFileDir.DataScope = tools.GetUserIdStr(c)
result, err := SysFileDir.SetSysFileDir()
tools.HasError(err, "抱歉未找到相关信息", -1)
app.OK(c, result, "")
}
func GetSysFileDir(c *gin.Context) {
var data models.SysFileDir
data.Id, _ = tools.StringToInt(c.Param("id"))
result, err := data.Get()
tools.HasError(err, "抱歉未找到相关信息", -1)
app.OK(c, result, "")
}
// @Summary 添加SysFileDir
// @Description 获取JSON
// @Tags SysFileDir
// @Accept application/json
// @Product application/json
// @Param data body models.SysFileDir true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/sysfiledir [post]
func InsertSysFileDir(c *gin.Context) {
var data models.SysFileDir
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 UpdateSysFileDir(c *gin.Context) {
var data models.SysFileDir
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, "")
}
func DeleteSysFileDir(c *gin.Context) {
var data models.SysFileDir
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)
}
+77
View File
@@ -0,0 +1,77 @@
package sysfileinfo
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/app/admin/models"
"go-admin/tools"
"go-admin/tools/app"
"go-admin/tools/app/msg"
)
func GetSysFileInfoList(c *gin.Context) {
var data models.SysFileInfo
var err error
var pageSize = 10
var pageIndex = 1
if size := c.Request.FormValue("pageSize"); size != "" {
pageSize, err = tools.StringToInt(size)
}
tools.HasError(err, "", -1)
if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex, err = tools.StringToInt(index)
}
tools.HasError(err, "", -1)
if pid := c.Request.FormValue("pId"); pid != "" {
data.PId, err = tools.StringToInt(pid)
}
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, "")
}
func GetSysFileInfo(c *gin.Context) {
var data models.SysFileInfo
data.Id, _ = tools.StringToInt(c.Param("id"))
result, err := data.Get()
tools.HasError(err, "抱歉未找到相关信息", -1)
app.OK(c, result, "")
}
func InsertSysFileInfo(c *gin.Context) {
var data models.SysFileInfo
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 UpdateSysFileInfo(c *gin.Context) {
var data models.SysFileInfo
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, "")
}
func DeleteSysFileInfo(c *gin.Context) {
var data models.SysFileInfo
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)
}
+67
View File
@@ -0,0 +1,67 @@
package sysjob
import (
"go-admin/common/dto"
"time"
"github.com/gin-gonic/gin"
"go-admin/app/admin/models"
"go-admin/app/jobs"
"go-admin/tools"
"go-admin/tools/app"
"go-admin/tools/app/msg"
)
func RemoveJob(c *gin.Context) {
var data models.SysJob
var v dto.GeneralDelDto
err := c.BindUri(&v)
tools.HasError(err, "", 500)
data.JobId = v.Id
err = data.Get(data.JobId)
tools.HasError(err, "", 500)
cn := jobs.Remove(data.EntryId)
select {
case res := <-cn:
if res {
_, _ = data.RemoveEntryID(data.EntryId)
app.OK(c, nil, msg.DeletedSuccess)
}
case <-time.After(time.Second * 1):
app.OK(c, nil, msg.TimeOut)
}
}
func StartJob(c *gin.Context) {
var data models.SysJob
var v dto.GeneralGetDto
err := c.BindUri(&v)
tools.HasError(err, "", 500)
data.JobId = v.Id
err = data.Get(data.JobId)
tools.HasError(err, "", 500)
if data.JobType == 1 {
var j = &jobs.HttpJob{}
j.InvokeTarget = data.InvokeTarget
j.CronExpression = data.CronExpression
j.JobId = data.JobId
j.Name = data.JobName
data.EntryId, err = jobs.AddJob(j)
} else {
var j = &jobs.ExecJob{}
j.InvokeTarget = data.InvokeTarget
j.CronExpression = data.CronExpression
j.JobId = data.JobId
j.Name = data.JobName
j.Args = data.Args
data.EntryId, err = jobs.AddJob(j)
}
tools.HasError(err, "", 500)
err = data.Update(data.JobId)
tools.HasError(err, "", 500)
app.OK(c, nil, msg.DeletedSuccess)
}
+20
View File
@@ -0,0 +1,20 @@
package system
import (
"github.com/gin-gonic/gin"
"go-admin/tools"
"go-admin/tools/app"
"go-admin/tools/captcha"
)
func GenerateCaptchaHandler(c *gin.Context) {
id, b64s, err := captcha.DriverDigitFunc()
tools.HasError(err, "验证码获取失败", 500)
app.Custum(c, gin.H{
"code": 200,
"data": b64s,
"id": id,
"msg": "success",
})
}
+149
View File
@@ -0,0 +1,149 @@
package system
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/app/admin/models"
"go-admin/tools"
"go-admin/tools/app"
"go-admin/tools/app/msg"
)
// @Summary 配置列表数据
// @Description 获取JSON
// @Tags 配置
// @Param configKey query string false "configKey"
// @Param configName query string false "configName"
// @Param configType query string false "configType"
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/configList [get]
// @Security Bearer
func GetConfigList(c *gin.Context) {
var data models.SysConfig
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)
}
data.ConfigKey = c.Request.FormValue("configKey")
data.ConfigName = c.Request.FormValue("configName")
data.ConfigType = c.Request.FormValue("configType")
data.DataScope = tools.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex)
tools.HasError(err, "", -1)
var mp = make(map[string]interface{}, 3)
mp["list"] = result
mp["count"] = count
mp["pageIndex"] = pageIndex
mp["pageSize"] = pageSize
var res app.Response
res.Data = mp
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 获取配置
// @Description 获取JSON
// @Tags 配置
// @Param configId path int true "配置编码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/config/{configId} [get]
// @Security Bearer
func GetConfig(c *gin.Context) {
var Config models.SysConfig
Config.ConfigId, _ = tools.StringToInt(c.Param("configId"))
result, err := Config.Get()
tools.HasError(err, "抱歉未找到相关信息", -1)
var res app.Response
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 获取配置
// @Description 获取JSON
// @Tags 配置
// @Param configKey path int true "configKey"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/configKey/{configKey} [get]
// @Security Bearer
func GetConfigByConfigKey(c *gin.Context) {
var Config models.SysConfig
Config.ConfigKey = c.Param("configKey")
result, err := Config.Get()
tools.HasError(err, "抱歉未找到相关信息", -1)
app.OK(c, result, result.ConfigValue)
}
// @Summary 添加配置
// @Description 获取JSON
// @Tags 配置
// @Accept application/json
// @Product application/json
// @Param data body models.SysConfig true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/dict/data [post]
// @Security Bearer
func InsertConfig(c *gin.Context) {
var data models.SysConfig
err := c.BindWith(&data, binding.JSON)
data.CreateBy = tools.GetUserIdStr(c)
tools.HasError(err, "", 500)
result, err := data.Create()
tools.HasError(err, "", -1)
app.OK(c, result, "")
}
// @Summary 修改配置
// @Description 获取JSON
// @Tags 配置
// @Accept application/json
// @Product application/json
// @Param data body models.SysConfig true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/config [put]
// @Security Bearer
func UpdateConfig(c *gin.Context) {
var data models.SysConfig
err := c.BindWith(&data, binding.JSON)
tools.HasError(err, "数据解析失败", -1)
data.UpdateBy = tools.GetUserIdStr(c)
result, err := data.Update(data.ConfigId)
tools.HasError(err, "", -1)
app.OK(c, result, "")
}
// @Summary 删除配置
// @Description 删除数据
// @Tags 配置
// @Param configId path int true "configId"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/config/{configId} [delete]
func DeleteConfig(c *gin.Context) {
var data models.SysConfig
data.UpdateBy = tools.GetUserIdStr(c)
IDS := tools.IdsStrToIdsIntGroup("configId", c)
result, err := data.BatchDelete(IDS)
tools.HasError(err, "修改失败", 500)
app.OK(c, result, msg.DeletedSuccess)
}
+133
View File
@@ -0,0 +1,133 @@
package system
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/app/admin/models"
"go-admin/tools"
"go-admin/tools/app"
"go-admin/tools/app/msg"
)
// @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/deptList [get]
// @Security Bearer
func GetDeptList(c *gin.Context) {
var Dept models.SysDept
Dept.DeptName = c.Request.FormValue("deptName")
Dept.Status = c.Request.FormValue("status")
Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId"))
Dept.DataScope = tools.GetUserIdStr(c)
result, err := Dept.SetDept(true)
tools.HasError(err, "抱歉未找到相关信息", -1)
app.OK(c, result, "")
}
func GetDeptTree(c *gin.Context) {
var Dept models.SysDept
Dept.DeptName = c.Request.FormValue("deptName")
Dept.Status = c.Request.FormValue("status")
Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId"))
result, err := Dept.SetDept(false)
tools.HasError(err, "抱歉未找到相关信息", -1)
app.OK(c, result, "")
}
// @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 GetDept(c *gin.Context) {
var Dept models.SysDept
Dept.DeptId, _ = tools.StringToInt(c.Param("deptId"))
Dept.DataScope = tools.GetUserIdStr(c)
result, err := Dept.Get()
tools.HasError(err, msg.NotFound, 404)
app.OK(c, result, msg.GetSuccess)
}
// @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 InsertDept(c *gin.Context) {
var data models.SysDept
err := c.BindWith(&data, binding.JSON)
tools.HasError(err, "", 500)
data.CreateBy = tools.GetUserIdStr(c)
result, err := data.Create()
tools.HasError(err, "", -1)
app.OK(c, result, msg.CreatedSuccess)
}
// @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 [put]
// @Security Bearer
func UpdateDept(c *gin.Context) {
var data models.SysDept
err := c.BindJSON(&data)
tools.HasError(err, "", -1)
data.UpdateBy = tools.GetUserIdStr(c)
result, err := data.Update(data.DeptId)
tools.HasError(err, "", -1)
app.OK(c, result, msg.UpdatedSuccess)
}
// @Summary 删除部门
// @Description 删除数据
// @Tags 部门
// @Param id path int true "id"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/dept/{id} [delete]
func DeleteDept(c *gin.Context) {
var data models.SysDept
id, err := tools.StringToInt(c.Param("id"))
_, err = data.Delete(id)
tools.HasError(err, "删除失败", 500)
app.OK(c, "", msg.DeletedSuccess)
}
func GetDeptTreeRoleselect(c *gin.Context) {
var Dept models.SysDept
var SysRole models.SysRole
id, err := tools.StringToInt(c.Param("roleId"))
SysRole.RoleId = id
result, err := Dept.SetDeptLable()
tools.HasError(err, msg.NotFound, -1)
menuIds := make([]int, 0)
if id != 0 {
menuIds, err = SysRole.GetRoleDeptId()
tools.HasError(err, "抱歉未找到相关信息", -1)
}
app.Custum(c, gin.H{
"code": 200,
"depts": result,
"checkedKeys": menuIds,
})
}
+154
View File
@@ -0,0 +1,154 @@
package dict
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/app/admin/models"
"go-admin/tools"
"go-admin/tools/app"
)
// @Summary 字典数据列表
// @Description 获取JSON
// @Tags 字典数据
// @Param status query string false "status"
// @Param dictCode query string false "dictCode"
// @Param dictType query string false "dictType"
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/data/list [get]
// @Security Bearer
func GetDictDataList(c *gin.Context) {
var data models.DictData
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)
}
data.DictLabel = c.Request.FormValue("dictLabel")
data.Status = c.Request.FormValue("status")
data.DictType = c.Request.FormValue("dictType")
id := c.Request.FormValue("dictCode")
data.DictCode, _ = tools.StringToInt(id)
data.DataScope = tools.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex)
tools.HasError(err, "", -1)
var mp = make(map[string]interface{}, 3)
mp["list"] = result
mp["count"] = count
mp["pageIndex"] = pageIndex
mp["pageSize"] = pageSize
var res app.Response
res.Data = mp
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 通过编码获取字典数据
// @Description 获取JSON
// @Tags 字典数据
// @Param dictCode path int true "字典编码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/data/{dictCode} [get]
// @Security Bearer
func GetDictData(c *gin.Context) {
var DictData models.DictData
DictData.DictLabel = c.Request.FormValue("dictLabel")
DictData.DictCode, _ = tools.StringToInt(c.Param("dictCode"))
result, err := DictData.GetByCode()
tools.HasError(err, "抱歉未找到相关信息", -1)
var res app.Response
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 通过字典类型获取字典数据
// @Description 获取JSON
// @Tags 字典数据
// @Param dictType path int true "dictType"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/databyType/{dictType} [get]
// @Security Bearer
func GetDictDataByDictType(c *gin.Context) {
var DictData models.DictData
DictData.DictType = c.Param("dictType")
result, err := DictData.Get()
tools.HasError(err, "抱歉未找到相关信息", -1)
var res app.Response
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 添加字典数据
// @Description 获取JSON
// @Tags 字典数据
// @Accept application/json
// @Product application/json
// @Param data body models.DictType true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/dict/data [post]
// @Security Bearer
func InsertDictData(c *gin.Context) {
var data models.DictData
err := c.ShouldBindJSON(&data)
data.CreateBy = tools.GetUserIdStr(c)
tools.HasError(err, "", 500)
result, err := data.Create()
tools.HasError(err, "", -1)
var res app.Response
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 修改字典数据
// @Description 获取JSON
// @Tags 字典数据
// @Accept application/json
// @Product application/json
// @Param data body models.DictType true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/dict/data [put]
// @Security Bearer
func UpdateDictData(c *gin.Context) {
var data models.DictData
err := c.BindWith(&data, binding.JSON)
data.UpdateBy = tools.GetUserIdStr(c)
tools.HasError(err, "", -1)
result, err := data.Update(data.DictCode)
tools.HasError(err, "", -1)
var res app.Response
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 删除字典数据
// @Description 删除数据
// @Tags 字典数据
// @Param dictCode path int true "dictCode"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/dict/data/{dictCode} [delete]
func DeleteDictData(c *gin.Context) {
var data models.DictData
data.UpdateBy = tools.GetUserIdStr(c)
IDS := tools.IdsStrToIdsIntGroup("dictCode", c)
result, err := data.BatchDelete(IDS)
tools.HasError(err, "修改失败", 500)
app.OK(c, result, "删除成功")
}
+137
View File
@@ -0,0 +1,137 @@
package dict
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/app/admin/models"
"go-admin/tools"
"go-admin/tools/app"
)
// @Summary 字典类型列表数据
// @Description 获取JSON
// @Tags 字典类型
// @Param dictName query string false "dictName"
// @Param dictId query string false "dictId"
// @Param dictType query string false "dictType"
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {object} app.PageResponse "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/type/list [get]
// @Security Bearer
func GetDictTypeList(c *gin.Context) {
var data models.DictType
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)
}
data.DictName = c.Request.FormValue("dictName")
id := c.Request.FormValue("dictId")
data.DictId, _ = tools.StringToInt(id)
data.DictType = c.Request.FormValue("dictType")
data.DataScope = tools.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex)
tools.HasError(err, "", -1)
app.PageOK(c, result, count, pageIndex, pageSize, "")
}
// @Summary 通过字典id获取字典类型
// @Description 获取JSON
// @Tags 字典类型
// @Param dictId path int true "字典类型编码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/type/{dictId} [get]
// @Security Bearer
func GetDictType(c *gin.Context) {
var DictType models.DictType
DictType.DictName = c.Request.FormValue("dictName")
DictType.DictId, _ = tools.StringToInt(c.Param("dictId"))
result, err := DictType.Get()
tools.HasError(err, "抱歉未找到相关信息", -1)
var res app.Response
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
func GetDictTypeOptionSelect(c *gin.Context) {
var DictType models.DictType
DictType.DictName = c.Request.FormValue("dictName")
DictType.DictId, _ = tools.StringToInt(c.Param("dictId"))
result, err := DictType.GetList()
tools.HasError(err, "抱歉未找到相关信息", -1)
var res app.Response
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 添加字典类型
// @Description 获取JSON
// @Tags 字典类型
// @Accept application/json
// @Product application/json
// @Param data body models.DictType true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/dict/type [post]
// @Security Bearer
func InsertDictType(c *gin.Context) {
var data models.DictType
err := c.BindWith(&data, binding.JSON)
data.CreateBy = tools.GetUserIdStr(c)
tools.HasError(err, "", 500)
result, err := data.Create()
tools.HasError(err, "", -1)
var res app.Response
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 修改字典类型
// @Description 获取JSON
// @Tags 字典类型
// @Accept application/json
// @Product application/json
// @Param data body models.DictType true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/dict/type [put]
// @Security Bearer
func UpdateDictType(c *gin.Context) {
var data models.DictType
err := c.BindWith(&data, binding.JSON)
data.UpdateBy = tools.GetUserIdStr(c)
tools.HasError(err, "", -1)
result, err := data.Update(data.DictId)
tools.HasError(err, "", -1)
var res app.Response
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 删除字典类型
// @Description 删除数据
// @Tags 字典类型
// @Param dictId path int true "dictId"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/dict/type/{dictId} [delete]
func DeleteDictType(c *gin.Context) {
var data models.DictType
data.UpdateBy = tools.GetUserIdStr(c)
IDS := tools.IdsStrToIdsIntGroup("dictId", c)
result, err := data.BatchDelete(IDS)
tools.HasError(err, "修改失败", 500)
app.OK(c, result, "删除成功")
}
+39
View File
@@ -0,0 +1,39 @@
package system
import (
"github.com/gin-gonic/gin"
)
const INDEX = `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>GO-ADMIN欢迎您</title>
<style>
body{
margin:0;
padding:0;
overflow-y:hidden
}
</style>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script type="text/javascript">
window.onerror=function(){return true;}
$(function(){
headerH = 0;
var h=$(window).height();
$("#iframe").height((h-headerH)+"px");
});
</script>
</head>
<body>
<iframe id="iframe" frameborder="0" src="http://doc.zhangwj.com/go-admin-site/" style="width:100%;"></iframe>
</body>
</html>
`
func HelloWorld(c *gin.Context) {
c.Header("Content-Type", "text/html; charset=utf-8")
c.String(200, INDEX)
}
+53
View File
@@ -0,0 +1,53 @@
package system
import (
"github.com/gin-gonic/gin"
"go-admin/app/admin/models"
"go-admin/tools"
"go-admin/tools/app"
)
func GetInfo(c *gin.Context) {
var roles = make([]string, 1)
roles[0] = tools.GetRoleName(c)
var permissions = make([]string, 1)
permissions[0] = "*:*:*"
var buttons = make([]string, 1)
buttons[0] = "*:*:*"
RoleMenu := models.RoleMenu{}
RoleMenu.RoleId = tools.GetRoleId(c)
var mp = make(map[string]interface{})
mp["roles"] = roles
if tools.GetRoleName(c) == "admin" || tools.GetRoleName(c) == "系统管理员" {
mp["permissions"] = permissions
mp["buttons"] = buttons
} else {
list, _ := RoleMenu.GetPermis()
mp["permissions"] = list
mp["buttons"] = list
}
sysuser := models.SysUser{}
sysuser.UserId = tools.GetUserId(c)
user, err := sysuser.Get()
tools.HasError(err, "", 500)
mp["introduction"] = " am a super administrator"
mp["avatar"] = "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif"
if user.Avatar != "" {
mp["avatar"] = user.Avatar
}
mp["userName"] = user.NickName
mp["userId"] = user.UserId
mp["deptId"] = user.DeptId
mp["name"] = user.NickName
app.OK(c, mp, "")
}
+177
View File
@@ -0,0 +1,177 @@
package system
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/app/admin/models"
"go-admin/tools"
"go-admin/tools/app"
)
// @Summary Menu列表数据
// @Description 获取JSON
// @Tags 菜单
// @Param menuName query string false "menuName"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
// @Router /api/v1/menulist [get]
// @Security Bearer
func GetMenuList(c *gin.Context) {
var Menu models.Menu
Menu.MenuName = c.Request.FormValue("menuName")
Menu.Visible = c.Request.FormValue("visible")
Menu.Title = c.Request.FormValue("title")
Menu.DataScope = tools.GetUserIdStr(c)
result, err := Menu.SetMenu()
tools.HasError(err, "抱歉未找到相关信息", -1)
app.OK(c, result, "")
}
// @Summary Menu列表数据
// @Description 获取JSON
// @Tags 菜单
// @Param menuName query string false "menuName"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
// @Router /api/v1/menu [get]
// @Security Bearer
func GetMenu(c *gin.Context) {
var data models.Menu
id, err := tools.StringToInt(c.Param("id"))
data.MenuId = id
result, err := data.GetByMenuId()
tools.HasError(err, "抱歉未找到相关信息", -1)
app.OK(c, result, "")
}
func GetMenuTreeRoleselect(c *gin.Context) {
var Menu models.Menu
var SysRole models.SysRole
id, err := tools.StringToInt(c.Param("roleId"))
SysRole.RoleId = id
result, err := Menu.SetMenuLable()
tools.HasError(err, "抱歉未找到相关信息", -1)
menuIds := make([]int, 0)
if id != 0 {
menuIds, err = SysRole.GetRoleMeunId()
tools.HasError(err, "抱歉未找到相关信息", -1)
}
app.Custum(c, gin.H{
"code": 200,
"menus": result,
"checkedKeys": menuIds,
})
}
// @Summary 获取菜单树
// @Description 获取JSON
// @Tags 菜单
// @Accept application/x-www-form-urlencoded
// @Product application/x-www-form-urlencoded
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/menuTreeselect [get]
// @Security Bearer
func GetMenuTreeelect(c *gin.Context) {
var data models.Menu
result, err := data.SetMenuLable()
tools.HasError(err, "抱歉未找到相关信息", -1)
app.OK(c, result, "")
}
// @Summary 创建菜单
// @Description 获取JSON
// @Tags 菜单
// @Accept application/x-www-form-urlencoded
// @Product application/x-www-form-urlencoded
// @Param menuName formData string true "menuName"
// @Param Path formData string false "Path"
// @Param Action formData string true "Action"
// @Param Permission formData string true "Permission"
// @Param ParentId formData string true "ParentId"
// @Param IsDel formData string true "IsDel"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/menu [post]
// @Security Bearer
func InsertMenu(c *gin.Context) {
var data models.Menu
err := c.BindWith(&data, binding.JSON)
tools.HasError(err, "抱歉未找到相关信息", -1)
data.CreateBy = tools.GetUserIdStr(c)
result, err := data.Create()
tools.HasError(err, "抱歉未找到相关信息", -1)
app.OK(c, result, "")
}
// @Summary 修改菜单
// @Description 获取JSON
// @Tags 菜单
// @Accept application/x-www-form-urlencoded
// @Product application/x-www-form-urlencoded
// @Param id path int true "id"
// @Param data body models.Menu true "body"
// @Success 200 {string} string "{"code": 200, "message": "修改成功"}"
// @Success 200 {string} string "{"code": -1, "message": "修改失败"}"
// @Router /api/v1/menu/{id} [put]
// @Security Bearer
func UpdateMenu(c *gin.Context) {
var data models.Menu
err2 := c.BindWith(&data, binding.JSON)
data.UpdateBy = tools.GetUserIdStr(c)
tools.HasError(err2, "修改失败", -1)
_, err := data.Update(data.MenuId)
tools.HasError(err, "", 501)
app.OK(c, "", "修改成功")
}
// @Summary 删除菜单
// @Description 删除数据
// @Tags 菜单
// @Param id path int true "id"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/menu/{id} [delete]
func DeleteMenu(c *gin.Context) {
var data models.Menu
id, err := tools.StringToInt(c.Param("id"))
data.UpdateBy = tools.GetUserIdStr(c)
_, err = data.Delete(id)
tools.HasError(err, "删除失败", 500)
app.OK(c, "", "删除成功")
}
// @Summary 根据角色名称获取菜单列表数据(左菜单使用)
// @Description 获取JSON
// @Tags 菜单
// @Param id path int true "id"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
// @Router /api/v1/menurole [get]
// @Security Bearer
func GetMenuRole(c *gin.Context) {
var Menu models.Menu
result, err := Menu.SetMenuRole(tools.GetRoleName(c))
tools.HasError(err, "获取失败", 500)
app.OK(c, result, "")
}
// @Summary 获取角色对应的菜单id数组
// @Description 获取JSON
// @Tags 菜单
// @Param id path int true "id"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
// @Router /api/v1/menuids/{id} [get]
// @Security Bearer
func GetMenuIDS(c *gin.Context) {
var data models.RoleMenu
data.RoleName = c.GetString("role")
data.UpdateBy = tools.GetUserIdStr(c)
result, err := data.GetIDS()
tools.HasError(err, "获取失败", 500)
app.OK(c, result, "")
}
+118
View File
@@ -0,0 +1,118 @@
package system
import (
"github.com/gin-gonic/gin"
"go-admin/app/admin/models"
"go-admin/tools"
"go-admin/tools/app"
)
// @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 GetPostList(c *gin.Context) {
var data models.Post
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)
}
id := c.Request.FormValue("postId")
data.PostId, _ = tools.StringToInt(id)
data.PostCode = c.Request.FormValue("postCode")
data.PostName = c.Request.FormValue("postName")
data.Status = c.Request.FormValue("status")
data.DataScope = tools.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex)
tools.HasError(err, "", -1)
app.PageOK(c, result, count, pageIndex, pageSize, "")
}
// @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 GetPost(c *gin.Context) {
var Post models.Post
Post.PostId, _ = tools.StringToInt(c.Param("postId"))
result, err := Post.Get()
tools.HasError(err, "抱歉未找到相关信息", -1)
app.OK(c, result, "")
}
// @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 InsertPost(c *gin.Context) {
var data models.Post
err := c.Bind(&data)
data.CreateBy = tools.GetUserIdStr(c)
tools.HasError(err, "", 500)
result, err := data.Create()
tools.HasError(err, "", -1)
app.OK(c, result, "")
}
// @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 UpdatePost(c *gin.Context) {
var data models.Post
err := c.Bind(&data)
data.UpdateBy = tools.GetUserIdStr(c)
tools.HasError(err, "", -1)
result, err := data.Update(data.PostId)
tools.HasError(err, "", -1)
app.OK(c, result, "修改成功")
}
// @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 DeletePost(c *gin.Context) {
var data models.Post
data.UpdateBy = tools.GetUserIdStr(c)
IDS := tools.IdsStrToIdsIntGroup("postId", c)
result, err := data.BatchDelete(IDS)
tools.HasError(err, "删除失败", 500)
app.OK(c, result, "删除成功")
}
+150
View File
@@ -0,0 +1,150 @@
package system
import (
"github.com/gin-gonic/gin"
"go-admin/app/admin/models"
"go-admin/tools"
"go-admin/tools/app"
)
// @Summary 角色列表数据
// @Description Get JSON
// @Tags 角色/Role
// @Param roleName query string false "roleName"
// @Param status query string false "status"
// @Param roleKey query string false "roleKey"
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/rolelist [get]
// @Security Bearer
func GetRoleList(c *gin.Context) {
var data models.SysRole
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)
}
data.RoleKey = c.Request.FormValue("roleKey")
data.RoleName = c.Request.FormValue("roleName")
data.Status = c.Request.FormValue("status")
data.DataScope = tools.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex)
tools.HasError(err, "", -1)
app.PageOK(c, result, count, pageIndex, pageSize, "")
}
// @Summary 获取Role数据
// @Description 获取JSON
// @Tags 角色/Role
// @Param roleId path string false "roleId"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
// @Router /api/v1/role [get]
// @Security Bearer
func GetRole(c *gin.Context) {
var Role models.SysRole
Role.RoleId, _ = tools.StringToInt(c.Param("roleId"))
result, err := Role.Get()
menuIds := make([]int, 0)
menuIds, err = Role.GetRoleMeunId()
tools.HasError(err, "抱歉未找到相关信息", -1)
result.MenuIds = menuIds
app.OK(c, result, "")
}
// @Summary 创建角色
// @Description 获取JSON
// @Tags 角色/Role
// @Accept application/json
// @Product application/json
// @Param data body models.SysRole true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/role [post]
func InsertRole(c *gin.Context) {
var data models.SysRole
data.CreateBy = tools.GetUserIdStr(c)
err := c.Bind(&data)
tools.HasError(err, "数据解析失败", 500)
id, err := data.Insert()
tools.HasError(err, "", -1)
data.RoleId = id
var t models.RoleMenu
if len(data.MenuIds) > 0 {
_, err = t.Insert(id, data.MenuIds)
tools.HasError(err, "", -1)
}
app.OK(c, data, "添加成功")
}
// @Summary 修改用户角色
// @Description 获取JSON
// @Tags 角色/Role
// @Accept application/json
// @Product application/json
// @Param data body models.SysRole true "body"
// @Success 200 {string} string "{"code": 200, "message": "修改成功"}"
// @Success 200 {string} string "{"code": -1, "message": "修改失败"}"
// @Router /api/v1/role [put]
func UpdateRole(c *gin.Context) {
var data models.SysRole
data.UpdateBy = tools.GetUserIdStr(c)
err := c.Bind(&data)
tools.HasError(err, "数据解析失败", -1)
result, err := data.Update(data.RoleId)
tools.HasError(err, "", -1)
var t models.RoleMenu
_, err = t.DeleteRoleMenu(data.RoleId)
tools.HasError(err, "修改失败(delete rm)", -1)
if len(data.MenuIds) > 0 {
_, err2 := t.Insert(data.RoleId, data.MenuIds)
tools.HasError(err2, "修改失败(insert)", -1)
}
app.OK(c, result, "修改成功")
}
func UpdateRoleDataScope(c *gin.Context) {
var data models.SysRole
data.UpdateBy = tools.GetUserIdStr(c)
err := c.Bind(&data)
tools.HasError(err, "数据解析失败", -1)
result, err := data.Update(data.RoleId)
var t models.SysRoleDept
_, err = t.DeleteRoleDept(data.RoleId)
tools.HasError(err, "添加失败1", -1)
if data.DataScope == "2" {
_, err2 := t.Insert(data.RoleId, data.DeptIds)
tools.HasError(err2, "添加失败2", -1)
}
app.OK(c, result, "修改成功")
}
// @Summary 删除用户角色
// @Description 删除数据
// @Tags 角色/Role
// @Param roleId path int true "roleId"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/role/{roleId} [delete]
func DeleteRole(c *gin.Context) {
var Role models.SysRole
Role.UpdateBy = tools.GetUserIdStr(c)
IDS := tools.IdsStrToIdsIntGroup("roleId", c)
_, err := Role.BatchDelete(IDS)
tools.HasError(err, "删除失败", -1)
app.OK(c, "", "删除成功")
}
+73
View File
@@ -0,0 +1,73 @@
package system
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
"go-admin/app/admin/models"
"go-admin/tools/app"
)
// @Summary RoleMenu列表数据
// @Description 获取JSON
// @Tags 角色菜单
// @Param RoleId query string false "RoleId"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
// @Router /api/v1/rolemenu [get]
// @Security Bearer
func GetRoleMenu(c *gin.Context) {
var Rm models.RoleMenu
err := c.ShouldBind(&Rm)
result, err := Rm.Get()
var res app.Response
if err != nil {
res.Msg = "抱歉未找到相关信息"
c.JSON(http.StatusOK, res.ReturnError(200))
return
}
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
type RoleMenuPost struct {
RoleId string
RoleMenu []models.RoleMenu
}
func InsertRoleMenu(c *gin.Context) {
var res app.Response
res.Msg = "添加成功"
c.JSON(http.StatusOK, res.ReturnOK())
return
}
// @Summary 删除用户菜单数据
// @Description 删除数据
// @Tags 角色菜单
// @Param id path string true "id"
// @Param menu_id query string false "menu_id"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/rolemenu/{id} [delete]
func DeleteRoleMenu(c *gin.Context) {
var t models.RoleMenu
id := c.Param("id")
menuId := c.Request.FormValue("menu_id")
fmt.Println(menuId)
_, err := t.Delete(id, menuId)
if err != nil {
var res app.Response
res.Msg = "删除失败"
c.JSON(http.StatusOK, res.ReturnError(200))
return
}
var res app.Response
res.Msg = "删除成功"
c.JSON(http.StatusOK, res.ReturnOK())
return
}
+67
View File
@@ -0,0 +1,67 @@
package system
import (
"errors"
"fmt"
"strings"
"github.com/gin-gonic/gin"
"go-admin/app/admin/models"
"go-admin/tools"
"go-admin/tools/app"
)
// @Summary 查询系统信息
// @Description 获取JSON
// @Tags 系统信息
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/setting [get]
func GetSetting(c *gin.Context) {
var s models.SysSetting
r, e := s.Get()
if r.Logo != "" {
if !strings.HasPrefix(r.Logo, "http") {
r.Logo = fmt.Sprintf("http://%s/%s", c.Request.Host, r.Logo)
}
}
tools.HasError(e, "查询失败", 500)
app.OK(c, r, "查询成功")
}
// @Summary 更新或提交系统信息
// @Description 获取JSON
// @Tags 系统信息
// @Param data body models.SysUser true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/system/setting [post]
func CreateSetting(c *gin.Context) {
var s models.ResponseSystemConfig
if err := c.ShouldBind(&s); err != nil {
app.Error(c, 200, errors.New("缺少必要参数"), "")
return
}
var sModel models.SysSetting
sModel.Logo = s.Logo
sModel.Name = s.Name
a, e := sModel.Update()
if e != nil {
app.Error(c, 200, e, "")
return
}
if a.Logo != "" {
if !strings.HasPrefix(a.Logo, "http") {
a.Logo = fmt.Sprintf("http://%s/%s", c.Request.Host, a.Logo)
}
}
app.OK(c, a, "提交成功")
}
+234
View File
@@ -0,0 +1,234 @@
package system
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/google/uuid"
"go-admin/app/admin/models"
"go-admin/common/global"
"go-admin/tools"
"go-admin/tools/app"
)
// @Summary 列表用户信息数据
// @Description 获取JSON
// @Tags 用户
// @Param username query string false "username"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
// @Router /api/v1/sysUserList [get]
// @Security Bearer
func GetSysUserList(c *gin.Context) {
var data models.SysUser
var err error
var pageSize = 10
var pageIndex = 1
size := c.Request.FormValue("pageSize")
if size != "" {
pageSize = tools.StrToInt(err, size)
}
index := c.Request.FormValue("pageIndex")
if index != "" {
pageIndex = tools.StrToInt(err, index)
}
data.Username = c.Request.FormValue("username")
data.Status = c.Request.FormValue("status")
data.Phone = c.Request.FormValue("phone")
postId := c.Request.FormValue("postId")
data.PostId, _ = tools.StringToInt(postId)
deptId := c.Request.FormValue("deptId")
data.DeptId, _ = tools.StringToInt(deptId)
data.DataScope = tools.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex)
tools.HasError(err, "", -1)
app.PageOK(c, result, count, pageIndex, pageSize, "")
}
// @Summary 获取用户
// @Description 获取JSON
// @Tags 用户
// @Param userId path int true "用户编码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/sysUser/{userId} [get]
// @Security Bearer
func GetSysUser(c *gin.Context) {
var SysUser models.SysUser
SysUser.UserId, _ = tools.StringToInt(c.Param("userId"))
result, err := SysUser.Get()
tools.HasError(err, "抱歉未找到相关信息", -1)
var SysRole models.SysRole
var Post models.Post
roles, err := SysRole.GetList()
posts, err := Post.GetList()
postIds := make([]int, 0)
postIds = append(postIds, result.PostId)
roleIds := make([]int, 0)
roleIds = append(roleIds, result.RoleId)
app.Custum(c, gin.H{
"code": 200,
"data": result,
"postIds": postIds,
"roleIds": roleIds,
"roles": roles,
"posts": posts,
})
}
// @Summary 获取个人中心用户
// @Description 获取JSON
// @Tags 个人中心
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/user/profile [get]
// @Security Bearer
func GetSysUserProfile(c *gin.Context) {
var SysUser models.SysUser
userId := tools.GetUserIdStr(c)
SysUser.UserId, _ = tools.StringToInt(userId)
result, err := SysUser.Get()
tools.HasError(err, "抱歉未找到相关信息", -1)
var SysRole models.SysRole
var Post models.Post
var Dept models.SysDept
//获取角色列表
roles, err := SysRole.GetList()
//获取职位列表
posts, err := Post.GetList()
//获取部门列表
Dept.DeptId = result.DeptId
dept, err := Dept.Get()
postIds := make([]int, 0)
postIds = append(postIds, result.PostId)
roleIds := make([]int, 0)
roleIds = append(roleIds, result.RoleId)
app.Custum(c, gin.H{
"code": 200,
"data": result,
"postIds": postIds,
"roleIds": roleIds,
"roles": roles,
"posts": posts,
"dept": dept,
})
}
// @Summary 获取用户角色和职位
// @Description 获取JSON
// @Tags 用户
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/sysUser [get]
// @Security Bearer
func GetSysUserInit(c *gin.Context) {
var SysRole models.SysRole
var Post models.Post
roles, err := SysRole.GetList()
posts, err := Post.GetList()
tools.HasError(err, "抱歉未找到相关信息", -1)
mp := make(map[string]interface{}, 2)
mp["roles"] = roles
mp["posts"] = posts
app.OK(c, mp, "")
}
// @Summary 创建用户
// @Description 获取JSON
// @Tags 用户
// @Accept application/json
// @Product application/json
// @Param data body models.SysUser true "用户数据"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/sysUser [post]
func InsertSysUser(c *gin.Context) {
var sysuser models.SysUser
err := c.BindWith(&sysuser, binding.JSON)
tools.HasError(err, "非法数据格式", 500)
sysuser.CreateBy = tools.GetUserIdStr(c)
id, err := sysuser.Insert()
tools.HasError(err, "添加失败", 500)
app.OK(c, id, "添加成功")
}
// @Summary 修改用户数据
// @Description 获取JSON
// @Tags 用户
// @Accept application/json
// @Product application/json
// @Param data body models.SysUser true "body"
// @Success 200 {string} string "{"code": 200, "message": "修改成功"}"
// @Success 200 {string} string "{"code": -1, "message": "修改失败"}"
// @Router /api/v1/sysuser/{userId} [put]
func UpdateSysUser(c *gin.Context) {
var data models.SysUser
err := c.Bind(&data)
tools.HasError(err, "数据解析失败", -1)
data.UpdateBy = tools.GetUserIdStr(c)
result, err := data.Update(data.UserId)
tools.HasError(err, "修改失败", 500)
app.OK(c, result, "修改成功")
}
// @Summary 删除用户数据
// @Description 删除数据
// @Tags 用户
// @Param userId path int true "userId"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/sysuser/{userId} [delete]
func DeleteSysUser(c *gin.Context) {
var data models.SysUser
data.UpdateBy = tools.GetUserIdStr(c)
IDS := tools.IdsStrToIdsIntGroup("userId", c)
result, err := data.BatchDelete(IDS)
tools.HasError(err, "删除失败", 500)
app.OK(c, result, "删除成功")
}
// @Summary 修改头像
// @Description 获取JSON
// @Tags 用户
// @Accept multipart/form-data
// @Param file formData file true "file"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/user/profileAvatar [post]
func InsetSysUserAvatar(c *gin.Context) {
form, _ := c.MultipartForm()
files := form.File["upload[]"]
guid := uuid.New().String()
filPath := "static/uploadfile/" + guid + ".jpg"
for _, file := range files {
global.Logger.Debug(file.Filename)
// 上传文件至指定目录
_ = c.SaveUploadedFile(file, filPath)
}
sysuser := models.SysUser{}
sysuser.UserId = tools.GetUserId(c)
sysuser.Avatar = "/" + filPath
sysuser.UpdateBy = tools.GetUserIdStr(c)
sysuser.Update(sysuser.UserId)
app.OK(c, filPath, "修改成功")
}
func SysUserUpdatePwd(c *gin.Context) {
var pwd models.SysUserPwd
err := c.Bind(&pwd)
tools.HasError(err, "数据解析失败", 500)
sysuser := models.SysUser{}
sysuser.UserId = tools.GetUserId(c)
sysuser.SetPwd(pwd)
app.OK(c, "", "密码修改成功")
}
+50
View File
@@ -0,0 +1,50 @@
package tools
import (
"net/http"
"github.com/gin-gonic/gin"
"go-admin/app/admin/models/tools"
tools2 "go-admin/tools"
"go-admin/tools/app"
)
// @Summary 分页列表数据 / page list data
// @Description 数据库表列分页列表 / database table column page list
// @Tags 工具 / Tools
// @Param tableName query string false "tableName / 数据表名称"
// @Param pageSize query int false "pageSize / 页条数"
// @Param pageIndex query int false "pageIndex / 页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/db/columns/page [get]
func GetDBColumnList(c *gin.Context) {
var data tools.DBColumns
var err error
var pageSize = 10
var pageIndex = 1
if size := c.Request.FormValue("pageSize"); size != "" {
pageSize = tools2.StrToInt(err, size)
}
if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex = tools2.StrToInt(err, index)
}
data.TableName = c.Request.FormValue("tableName")
tools2.Assert(data.TableName == "", "table name cannot be empty!", 500)
result, count, err := data.GetPage(pageSize, pageIndex)
tools2.HasError(err, "", -1)
var mp = make(map[string]interface{}, 3)
mp["list"] = result
mp["count"] = count
mp["pageIndex"] = pageIndex
mp["pageSize"] = pageSize
var res app.Response
res.Data = mp
c.JSON(http.StatusOK, res.ReturnOK())
}
+55
View File
@@ -0,0 +1,55 @@
package tools
import (
"net/http"
"github.com/gin-gonic/gin"
"go-admin/app/admin/models/tools"
tools2 "go-admin/tools"
"go-admin/tools/app"
"go-admin/tools/config"
)
// @Summary 分页列表数据 / page list data
// @Description 数据库表分页列表 / database table page list
// @Tags 工具 / Tools
// @Param tableName query string false "tableName / 数据表名称"
// @Param pageSize query int false "pageSize / 页条数"
// @Param pageIndex query int false "pageIndex / 页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/db/tables/page [get]
func GetDBTableList(c *gin.Context) {
var res app.Response
var data tools.DBTables
var err error
var pageSize = 10
var pageIndex = 1
if config.DatabaseConfig.Driver == "sqlite3" || config.DatabaseConfig.Driver == "postgres" {
res.Msg = "对不起,sqlite3 或 postgres 不支持代码生成!"
c.JSON(http.StatusOK, res.ReturnError(500))
return
}
if size := c.Request.FormValue("pageSize"); size != "" {
pageSize = tools2.StrToInt(err, size)
}
if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex = tools2.StrToInt(err, index)
}
data.TableName = c.Request.FormValue("tableName")
result, count, err := data.GetPage(pageSize, pageIndex)
tools2.HasError(err, "", -1)
var mp = make(map[string]interface{}, 3)
mp["list"] = result
mp["count"] = count
mp["pageIndex"] = pageIndex
mp["pageSize"] = pageSize
res.Data = mp
c.JSON(http.StatusOK, res.ReturnOK())
}
+379
View File
@@ -0,0 +1,379 @@
package tools
import (
"bytes"
"net/http"
"text/template"
"github.com/gin-gonic/gin"
"go-admin/app/admin/models"
"go-admin/app/admin/models/tools"
"go-admin/common/global"
tools2 "go-admin/tools"
"go-admin/tools/app"
"go-admin/tools/config"
)
func Preview(c *gin.Context) {
table := tools.SysTables{}
id, err := tools2.StringToInt(c.Param("tableId"))
tools2.HasError(err, "", -1)
table.TableId = id
t1, err := template.ParseFiles("template/model.go.template")
tools2.HasError(err, "", -1)
t2, err := template.ParseFiles("template/api.go.template")
tools2.HasError(err, "", -1)
t3, err := template.ParseFiles("template/js.go.template")
tools2.HasError(err, "", -1)
t4, err := template.ParseFiles("template/vue.go.template")
tools2.HasError(err, "", -1)
t5, err := template.ParseFiles("template/router.go.template")
tools2.HasError(err, "", -1)
t6, err := template.ParseFiles("template/dto.go.template")
tools2.HasError(err, "", -1)
tab, _ := table.Get()
var b1 bytes.Buffer
err = t1.Execute(&b1, tab)
var b2 bytes.Buffer
err = t2.Execute(&b2, tab)
var b3 bytes.Buffer
err = t3.Execute(&b3, tab)
var b4 bytes.Buffer
err = t4.Execute(&b4, tab)
var b5 bytes.Buffer
err = t5.Execute(&b5, tab)
var b6 bytes.Buffer
err = t6.Execute(&b6, tab)
mp := make(map[string]interface{})
mp["template/model.go.template"] = b1.String()
mp["template/api.go.template"] = b2.String()
mp["template/js.go.template"] = b3.String()
mp["template/vue.go.template"] = b4.String()
mp["template/router.go.template"] = b5.String()
mp["template/dto.go.template"] = b6.String()
var res app.Response
res.Data = mp
c.JSON(http.StatusOK, res.ReturnOK())
}
func GenCode(c *gin.Context) {
table := tools.SysTables{}
id, err := tools2.StringToInt(c.Param("tableId"))
tools2.HasError(err, "", -1)
table.TableId = id
tab, _ := table.Get()
ischeckrole := true
routerfile := "template/routercheckrole.go.template"
if c.Request.FormValue("ischeckrole") != "" {
ischeckrole, err = tools2.StringToBool(c.Request.FormValue("ischeckrole"))
if err != nil {
ischeckrole = true
}
}
oldTest := "// {{认证路由自动补充在此处请勿删除}}"
newText := "// {{认证路由自动补充在此处请勿删除}} \r\n register" + tab.ClassName + "Router(v1,authMiddleware)"
if !ischeckrole {
oldTest = "// {{无需认证路由自动补充在此处请勿删除}}"
newText = "// {{无需认证路由自动补充在此处请勿删除}} \r\n register" + tab.ClassName + "Router(v1)"
routerfile = "template/routernocheckrole.go.template"
}
t1, err := template.ParseFiles("template/model.go.template")
tools2.HasError(err, "", -1)
t2, err := template.ParseFiles("template/api.go.template")
tools2.HasError(err, "", -1)
t3, err := template.ParseFiles(routerfile)
tools2.HasError(err, "", -1)
t4, err := template.ParseFiles("template/js.go.template")
tools2.HasError(err, "", -1)
t5, err := template.ParseFiles("template/vue.go.template")
tools2.HasError(err, "", -1)
t6, err := template.ParseFiles("template/dto.go.template")
tools2.HasError(err, "", -1)
_ = tools2.PathCreate("./apis/" + tab.ModuleName + "/")
_ = tools2.PathCreate("./models/")
_ = tools2.PathCreate("./router/")
_ = tools2.PathCreate("./dto/")
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/api/")
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.PackageName)
var b1 bytes.Buffer
err = t1.Execute(&b1, tab)
var b2 bytes.Buffer
err = t2.Execute(&b2, tab)
var b3 bytes.Buffer
err = t3.Execute(&b3, tab)
var b4 bytes.Buffer
err = t4.Execute(&b4, tab)
var b5 bytes.Buffer
err = t5.Execute(&b5, tab)
var b6 bytes.Buffer
err = t6.Execute(&b6, tab)
tools2.FileCreate(b1, "./models/"+tab.PackageName+".go")
tools2.FileCreate(b2, "./apis/"+tab.ModuleName+"/"+tab.PackageName+".go")
tools2.FileCreate(b3, "./router/"+tab.PackageName+".go")
tools2.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.PackageName+".js")
tools2.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.PackageName+"/index.vue")
tools2.FileCreate(b6, "./dto/"+tab.PackageName+".go")
helper := tools2.ReplaceHelper{
Root: "./router/router.go",
OldText: oldTest,
NewText: newText,
}
if helper.OldText == helper.NewText {
global.Logger.Println("error !! the NewText isEqual the OldText")
return
}
if err := helper.DoWrok(); err != nil {
global.Logger.Print("error:", err.Error())
} else {
global.Logger.Print("done!")
}
app.OK(c, "", "Code generated successfully!")
}
func GenMenuAndApi(c *gin.Context) {
table := tools.SysTables{}
timeNow := tools2.GetCurrentTime()
id, err := tools2.StringToInt(c.Param("tableId"))
tools2.HasError(err, "", -1)
table.TableId = id
tab, _ := table.Get()
Mmenu := models.Menu{}
Mmenu.MenuName = tab.TBName + "Manage"
Mmenu.Title = tab.TableComment
Mmenu.Icon = "pass"
Mmenu.Path = "/" + tab.TBName
Mmenu.MenuType = "M"
Mmenu.Action = "无"
Mmenu.ParentId = 0
Mmenu.NoCache = false
Mmenu.Component = "Layout"
Mmenu.Sort = 0
Mmenu.Visible = "0"
Mmenu.IsFrame = "0"
Mmenu.CreateBy = "1"
Mmenu.UpdateBy = "1"
Mmenu.CreatedAt = timeNow
Mmenu.UpdatedAt = timeNow
Mmenu.MenuId, err = Mmenu.Create()
Cmenu := models.Menu{}
Cmenu.MenuName = tab.TBName
Cmenu.Title = tab.TableComment
Cmenu.Icon = "pass"
Cmenu.Path = tab.TBName
Cmenu.MenuType = "C"
Cmenu.Action = "无"
Cmenu.Permission = tab.PackageName + ":" + tab.ModuleName + ":list"
Cmenu.ParentId = Mmenu.MenuId
Cmenu.NoCache = false
Cmenu.Component = "/" + tab.ModuleName + "/index"
Cmenu.Sort = 0
Cmenu.Visible = "0"
Cmenu.IsFrame = "0"
Cmenu.CreateBy = "1"
Cmenu.UpdateBy = "1"
Cmenu.CreatedAt = timeNow
Cmenu.UpdatedAt = timeNow
Cmenu.MenuId, err = Cmenu.Create()
MList := models.Menu{}
MList.MenuName = ""
MList.Title = "分页获取" + tab.TableComment
MList.Icon = ""
MList.Path = tab.TBName
MList.MenuType = "F"
MList.Action = "无"
MList.Permission = tab.PackageName + ":" + tab.ModuleName + ":query"
MList.ParentId = Cmenu.MenuId
MList.NoCache = false
MList.Sort = 0
MList.Visible = "0"
MList.IsFrame = "0"
MList.CreateBy = "1"
MList.UpdateBy = "1"
MList.CreatedAt = timeNow
MList.UpdatedAt = timeNow
MList.MenuId, err = MList.Create()
MCreate := models.Menu{}
MCreate.MenuName = ""
MCreate.Title = "创建" + tab.TableComment
MCreate.Icon = ""
MCreate.Path = tab.TBName
MCreate.MenuType = "F"
MCreate.Action = "无"
MCreate.Permission = tab.PackageName + ":" + tab.ModuleName + ":add"
MCreate.ParentId = Cmenu.MenuId
MCreate.NoCache = false
MCreate.Sort = 0
MCreate.Visible = "0"
MCreate.IsFrame = "0"
MCreate.CreateBy = "1"
MCreate.UpdateBy = "1"
MCreate.CreatedAt = timeNow
MCreate.UpdatedAt = timeNow
MCreate.MenuId, err = MCreate.Create()
MUpdate := models.Menu{}
MUpdate.MenuName = ""
MUpdate.Title = "修改" + tab.TableComment
MUpdate.Icon = ""
MUpdate.Path = tab.TBName
MUpdate.MenuType = "F"
MUpdate.Action = "无"
MUpdate.Permission = tab.PackageName + ":" + tab.ModuleName + ":edit"
MUpdate.ParentId = Cmenu.MenuId
MUpdate.NoCache = false
MUpdate.Sort = 0
MUpdate.Visible = "0"
MUpdate.IsFrame = "0"
MUpdate.CreateBy = "1"
MUpdate.UpdateBy = "1"
MUpdate.CreatedAt = timeNow
MUpdate.UpdatedAt = timeNow
MUpdate.MenuId, err = MUpdate.Create()
MDelete := models.Menu{}
MDelete.MenuName = ""
MDelete.Title = "删除" + tab.TableComment
MDelete.Icon = ""
MDelete.Path = tab.TBName
MDelete.MenuType = "F"
MDelete.Action = "无"
MDelete.Permission = tab.PackageName + ":" + tab.ModuleName + ":remove"
MDelete.ParentId = Cmenu.MenuId
MDelete.NoCache = false
MDelete.Sort = 0
MDelete.Visible = "0"
MDelete.IsFrame = "0"
MDelete.CreateBy = "1"
MDelete.UpdateBy = "1"
MDelete.CreatedAt = timeNow
MDelete.UpdatedAt = timeNow
MDelete.MenuId, err = MDelete.Create()
var InterfaceId = 63
Amenu := models.Menu{}
Amenu.MenuName = tab.TBName
Amenu.Title = tab.TableComment
Amenu.Icon = "bug"
Amenu.Path = tab.TBName
Amenu.MenuType = "M"
Amenu.Action = "无"
Amenu.ParentId = InterfaceId
Amenu.NoCache = false
Amenu.Sort = 0
Amenu.Visible = "1"
Amenu.IsFrame = "0"
Amenu.CreateBy = "1"
Amenu.UpdateBy = "1"
Amenu.CreatedAt = timeNow
Amenu.UpdatedAt = timeNow
Amenu.MenuId, err = Amenu.Create()
AList := models.Menu{}
AList.MenuName = ""
AList.Title = "分页获取" + tab.TableComment
AList.Icon = "bug"
AList.Path = "/api/v1/" + tab.ModuleName
AList.MenuType = "A"
AList.Action = "GET"
AList.ParentId = Amenu.MenuId
AList.NoCache = false
AList.Sort = 0
AList.Visible = "1"
AList.IsFrame = "0"
AList.CreateBy = "1"
AList.UpdateBy = "1"
AList.CreatedAt = timeNow
AList.UpdatedAt = timeNow
AList.MenuId, err = AList.Create()
AGet := models.Menu{}
AGet.MenuName = ""
AGet.Title = "根据id获取" + tab.TableComment
AGet.Icon = "bug"
AGet.Path = "/api/v1/" + tab.ModuleName + "/:id"
AGet.MenuType = "A"
AGet.Action = "GET"
AGet.ParentId = Amenu.MenuId
AGet.NoCache = false
AGet.Sort = 0
AGet.Visible = "1"
AGet.IsFrame = "0"
AGet.CreateBy = "1"
AGet.UpdateBy = "1"
AGet.CreatedAt = timeNow
AGet.UpdatedAt = timeNow
AGet.MenuId, err = AGet.Create()
ACreate := models.Menu{}
ACreate.MenuName = ""
ACreate.Title = "创建" + tab.TableComment
ACreate.Icon = "bug"
ACreate.Path = "/api/v1/" + tab.ModuleName
ACreate.MenuType = "A"
ACreate.Action = "POST"
ACreate.ParentId = Amenu.MenuId
ACreate.NoCache = false
ACreate.Sort = 0
ACreate.Visible = "1"
ACreate.IsFrame = "0"
ACreate.CreateBy = "1"
ACreate.UpdateBy = "1"
ACreate.CreatedAt = timeNow
ACreate.UpdatedAt = timeNow
ACreate.MenuId, err = ACreate.Create()
AUpdate := models.Menu{}
AUpdate.MenuName = ""
AUpdate.Title = "修改" + tab.TableComment
AUpdate.Icon = "bug"
AUpdate.Path = "/api/v1/" + tab.ModuleName + "/:id"
AUpdate.MenuType = "A"
AUpdate.Action = "PUT"
AUpdate.ParentId = Amenu.MenuId
AUpdate.NoCache = false
AUpdate.Sort = 0
AUpdate.Visible = "1"
AUpdate.IsFrame = "0"
AUpdate.CreateBy = "1"
AUpdate.UpdateBy = "1"
AUpdate.CreatedAt = timeNow
AUpdate.UpdatedAt = timeNow
AUpdate.MenuId, err = AUpdate.Create()
ADelete := models.Menu{}
ADelete.MenuName = ""
ADelete.Title = "删除" + tab.TableComment
ADelete.Icon = "bug"
ADelete.Path = "/api/v1/" + tab.ModuleName + "/:id"
ADelete.MenuType = "A"
ADelete.Action = "DELETE"
ADelete.ParentId = Amenu.MenuId
ADelete.NoCache = false
ADelete.Sort = 0
ADelete.Visible = "1"
ADelete.IsFrame = "0"
ADelete.CreateBy = "1"
ADelete.UpdateBy = "1"
ADelete.CreatedAt = timeNow
ADelete.UpdatedAt = timeNow
ADelete.MenuId, err = ADelete.Create()
app.OK(c, "", "数据生成成功!")
}
+258
View File
@@ -0,0 +1,258 @@
package tools
import (
"net/http"
"strings"
"github.com/gin-gonic/gin"
"go-admin/app/admin/models/tools"
tools2 "go-admin/tools"
"go-admin/tools/app"
)
// @Summary 分页列表数据
// @Description 生成表分页列表
// @Tags 工具 - 生成表
// @Param tableName query string false "tableName / 数据表名称"
// @Param pageSize query int false "pageSize / 页条数"
// @Param pageIndex query int false "pageIndex / 页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/sys/tables/page [get]
func GetSysTableList(c *gin.Context) {
var data tools.SysTables
var err error
var pageSize = 10
var pageIndex = 1
if size := c.Request.FormValue("pageSize"); size != "" {
pageSize, err = tools2.StringToInt(size)
}
if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex, err = tools2.StringToInt(index)
}
data.TBName = c.Request.FormValue("tableName")
data.TableComment = c.Request.FormValue("tableComment")
result, count, err := data.GetPage(pageSize, pageIndex)
tools2.HasError(err, "", -1)
var mp = make(map[string]interface{}, 3)
mp["list"] = result
mp["count"] = count
mp["pageIndex"] = pageIndex
mp["pageSize"] = pageSize
var res app.Response
res.Data = mp
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 获取配置
// @Description 获取JSON
// @Tags 工具 - 生成表
// @Param configKey path int true "configKey"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/sys/tables/info/{tableId} [get]
// @Security Bearer
func GetSysTables(c *gin.Context) {
var data tools.SysTables
data.TableId, _ = tools2.StringToInt(c.Param("tableId"))
result, err := data.Get()
tools2.HasError(err, "抱歉未找到相关信息", -1)
var res app.Response
res.Data = result
mp := make(map[string]interface{})
mp["list"] = result.Columns
mp["info"] = result
res.Data = mp
c.JSON(http.StatusOK, res.ReturnOK())
}
func GetSysTablesInfo(c *gin.Context) {
var data tools.SysTables
if c.Request.FormValue("tableName") != "" {
data.TBName = c.Request.FormValue("tableName")
}
result, err := data.Get()
tools2.HasError(err, "抱歉未找到相关信息", -1)
var res app.Response
res.Data = result
mp := make(map[string]interface{})
mp["list"] = result.Columns
mp["info"] = result
res.Data = mp
c.JSON(http.StatusOK, res.ReturnOK())
}
func GetSysTablesTree(c *gin.Context) {
var data tools.SysTables
result, err := data.GetTree()
tools2.HasError(err, "抱歉未找到相关信息", -1)
var res app.Response
res.Data = result
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 添加表结构
// @Description 添加表结构
// @Tags 工具 - 生成表
// @Accept application/json
// @Product application/json
// @Param tables query string false "tableName / 数据表名称"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/sys/tables/info [post]
// @Security Bearer
func InsertSysTable(c *gin.Context) {
tablesList := strings.Split(c.Request.FormValue("tables"), ",")
for i := 0; i < len(tablesList); i++ {
data, err := genTableInit(tablesList, i, c)
_, err = data.Create()
tools2.HasError(err, "", -1)
}
var res app.Response
res.Msg = "添加成功!"
c.JSON(http.StatusOK, res.ReturnOK())
}
func genTableInit(tablesList []string, i int, c *gin.Context) (tools.SysTables, error) {
var data tools.SysTables
var dbTable tools.DBTables
var dbColumn tools.DBColumns
data.TBName = tablesList[i]
data.CreateBy = tools2.GetUserIdStr(c)
dbTable.TableName = data.TBName
dbtable, err := dbTable.Get()
dbColumn.TableName = data.TBName
tablenamelist := strings.Split(dbColumn.TableName, "_")
for i := 0; i < len(tablenamelist); i++ {
strStart := string([]byte(tablenamelist[i])[:1])
strend := string([]byte(tablenamelist[i])[1:])
data.ClassName += strings.ToUpper(strStart) + strend
data.PackageName += strings.ToLower(strStart) + strings.ToLower(strend)
data.ModuleName += strings.ToLower(strStart) + strings.ToLower(strend)
}
data.TplCategory = "crud"
data.Crud = true
dbcolumn, err := dbColumn.GetList()
data.CreateBy = tools2.GetUserIdStr(c)
data.TableComment = dbtable.TableComment
if dbtable.TableComment == "" {
data.TableComment = data.ClassName
}
data.FunctionName = data.TableComment
data.BusinessName = data.ModuleName
data.IsLogicalDelete = "1"
data.LogicalDelete = true
data.LogicalDeleteColumn = "is_del"
data.FunctionAuthor = "wenjianzhang"
for i := 0; i < len(dbcolumn); i++ {
var column tools.SysColumns
column.ColumnComment = dbcolumn[i].ColumnComment
column.ColumnName = dbcolumn[i].ColumnName
column.ColumnType = dbcolumn[i].ColumnType
column.Sort = i + 1
column.Insert = true
column.IsInsert = "1"
column.QueryType = "EQ"
column.IsPk = "0"
namelist := strings.Split(dbcolumn[i].ColumnName, "_")
for i := 0; i < len(namelist); i++ {
strStart := string([]byte(namelist[i])[:1])
strend := string([]byte(namelist[i])[1:])
column.GoField += strings.ToUpper(strStart) + strend
if i == 0 {
column.JsonField = strings.ToLower(strStart) + strend
} else {
column.JsonField += strings.ToUpper(strStart) + strend
}
}
if strings.Contains(dbcolumn[i].ColumnKey, "PR") {
column.IsPk = "1"
column.Pk = true
data.PkColumn = dbcolumn[i].ColumnName
data.PkGoField = column.GoField
data.PkJsonField = column.JsonField
}
column.IsRequired = "0"
if strings.Contains(dbcolumn[i].IsNullable, "NO") {
column.IsRequired = "1"
column.Required = true
}
if strings.Contains(dbcolumn[i].ColumnType, "int") {
if strings.Contains(dbcolumn[i].ColumnKey, "PR") {
column.GoType = "int"
} else {
column.GoType = "string"
}
column.HtmlType = "input"
} else if strings.Contains(dbcolumn[i].ColumnType, "timestamp") {
column.GoType = "time.Time"
column.HtmlType = "datetime"
} else {
column.GoType = "string"
column.HtmlType = "input"
}
data.Columns = append(data.Columns, column)
}
return data, err
}
// @Summary 修改表结构
// @Description 修改表结构
// @Tags 工具 - 生成表
// @Accept application/json
// @Product application/json
// @Param data body tools.SysTables true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/sys/tables/info [put]
// @Security Bearer
func UpdateSysTable(c *gin.Context) {
var data tools.SysTables
err := c.Bind(&data)
tools2.HasError(err, "数据解析失败", 500)
data.UpdateBy = tools2.GetUserIdStr(c)
result, err := data.Update()
tools2.HasError(err, "", -1)
var res app.Response
res.Data = result
res.Msg = "修改成功"
c.JSON(http.StatusOK, res.ReturnOK())
}
// @Summary 删除表结构
// @Description 删除表结构
// @Tags 工具 - 生成表
// @Param tableId path int true "tableId"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/sys/tables/info/{tableId} [delete]
func DeleteSysTables(c *gin.Context) {
var data tools.SysTables
IDS := tools2.IdsStrToIdsIntGroup("tableId", c)
_, err := data.BatchDelete(IDS)
tools2.HasError(err, "删除失败", 500)
var res app.Response
res.Msg = "删除成功"
c.JSON(http.StatusOK, res.ReturnOK())
}