This commit is contained in:
zhangwenjian
2020-04-13 00:30:58 +08:00
parent f25da5f1ee
commit 1df55e75e5
72 changed files with 1401 additions and 1559 deletions
+19
View File
@@ -0,0 +1,19 @@
package system
import (
"github.com/gin-gonic/gin"
"go-admin/pkg"
"go-admin/pkg/app"
"go-admin/pkg/captcha"
)
func GenerateCaptchaHandler(c *gin.Context) {
id, b64s, err := captcha.DriverDigitFunc()
pkg.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 (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/models"
"go-admin/pkg"
"go-admin/pkg/app"
"go-admin/pkg/app/msg"
"go-admin/pkg/utils"
"net/http"
)
// @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} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/configList [get]
// @Security
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 = pkg.StrToInt(err, size)
}
if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex = pkg.StrToInt(err, index)
}
data.ConfigKey = c.Request.FormValue("configKey")
data.ConfigName = c.Request.FormValue("configName")
data.ConfigType = c.Request.FormValue("configType")
data.DataScope = utils.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex)
pkg.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} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/config/{configId} [get]
// @Security
func GetConfig(c *gin.Context) {
var Config models.SysConfig
Config.ConfigId, _ = utils.StringToInt(c.Param("configId"))
result, err := Config.Get()
pkg.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} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/configKey/{configKey} [get]
// @Security
func GetConfigByConfigKey(c *gin.Context) {
var Config models.SysConfig
Config.ConfigKey = c.Param("configKey")
result, err := Config.Get()
pkg.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 = utils.GetUserIdStr(c)
pkg.HasError(err, "", 500)
result, err := data.Create()
pkg.HasError(err, "", -1)
app.OK(c, result,"")
}
// @Summary 修改配置
// @Description 获取JSON
// @Tags 配置
// @Accept application/json
// @Product application/json
// @Param data body models.Config 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)
pkg.HasError(err, "数据解析失败", -1)
data.UpdateBy = utils.GetUserIdStr(c)
result, err := data.Update(data.ConfigId)
pkg.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
id, err := utils.StringToInt(c.Param("configId"))
data.UpdateBy = utils.GetUserIdStr(c)
data.ConfigId = id
_, err = data.Delete()
pkg.HasError(err, "修改失败", 500)
app.OK(c, nil,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/models"
"go-admin/pkg"
"go-admin/pkg/app"
"go-admin/pkg/app/msg"
"go-admin/pkg/utils"
)
// @Summary 分页部门列表数据
// @Description 分页列表
// @Tags 部门
// @Param name query string false "name"
// @Param id query string false "id"
// @Param position query string false "position"
// @Success 200 {object} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/deptList [get]
// @Security
func GetDeptList(c *gin.Context) {
var Dept models.Dept
Dept.DeptName = c.Request.FormValue("deptName")
Dept.Status = c.Request.FormValue("status")
Dept.DeptId, _ = utils.StringToInt(c.Request.FormValue("deptId"))
Dept.DataScope = utils.GetUserIdStr(c)
result, err := Dept.SetDept(true)
pkg.HasError(err, "抱歉未找到相关信息", -1)
app.OK(c,result,"")
}
func GetDeptTree(c *gin.Context) {
var Dept models.Dept
Dept.DeptName = c.Request.FormValue("deptName")
Dept.Status= c.Request.FormValue("status")
Dept.DeptId, _ = utils.StringToInt(c.Request.FormValue("deptId"))
result, err := Dept.SetDept(false)
pkg.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} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dept/{deptId} [get]
// @Security
func GetDept(c *gin.Context) {
var Dept models.Dept
Dept.DeptId, _ = utils.StringToInt(c.Param("deptId"))
Dept.DataScope = utils.GetUserIdStr(c)
result, err := Dept.Get()
pkg.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.Dept 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.Dept
err := c.BindWith(&data, binding.JSON)
pkg.HasError(err, "", 500)
data.CreateBy = utils.GetUserIdStr(c)
result, err := data.Create()
pkg.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.Dept 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.Dept
err := c.BindWith(&data, binding.JSON)
pkg.HasError(err, "", -1)
data.UpdateBy = utils.GetUserIdStr(c)
result, err := data.Update(data.DeptId)
pkg.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.Dept
id, err := utils.StringToInt(c.Param("id"))
_, err = data.Delete(id)
pkg.HasError(err, "删除失败", 500)
app.OK(c,"",msg.DeletedSuccess)
}
func GetDeptTreeRoleselect(c *gin.Context) {
var Dept models.Dept
var SysRole models.SysRole
id, err := utils.StringToInt(c.Param("roleId"))
SysRole.RoleId = id
result, err := Dept.SetDeptLable()
pkg.HasError(err, msg.NotFound, -1)
menuIds := make([]int, 0)
if id != 0 {
menuIds, err = SysRole.GetRoleDeptId()
pkg.HasError(err, "抱歉未找到相关信息", -1)
}
app.Custum(c,gin.H{
"code": 200,
"depts": result,
"checkedKeys": menuIds,
})
}
+156
View File
@@ -0,0 +1,156 @@
package dict
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/models"
"go-admin/pkg"
"go-admin/pkg/app"
"go-admin/pkg/utils"
"net/http"
)
// @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} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/data/list [get]
// @Security
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 = pkg.StrToInt(err, size)
}
if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex = pkg.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, _ = utils.StringToInt(id)
data.DataScope = utils.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex)
pkg.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} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/data/{dictCode} [get]
// @Security
func GetDictData(c *gin.Context) {
var DictData models.DictData
DictData.DictLabel = c.Request.FormValue("dictLabel")
DictData.DictCode, _ = utils.StringToInt(c.Param("dictCode"))
result, err := DictData.GetByCode()
pkg.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} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/databyType/{dictType} [get]
// @Security
func GetDictDataByDictType(c *gin.Context) {
var DictData models.DictData
DictData.DictType = c.Param("dictType")
result, err := DictData.Get()
pkg.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.BindWith(&data, binding.JSON)
data.CreateBy = utils.GetUserIdStr(c)
pkg.HasError(err, "", 500)
result, err := data.Create()
pkg.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 = utils.GetUserIdStr(c)
pkg.HasError(err, "", -1)
result, err := data.Update(data.DictCode)
pkg.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
id, err := utils.StringToInt(c.Param("dictCode"))
data.UpdateBy = utils.GetUserIdStr(c)
_, err = data.Delete(id)
pkg.HasError(err, "修改失败", 500)
var res app.Response
res.Msg = "删除成功"
c.JSON(http.StatusOK, res.ReturnOK())
}
+149
View File
@@ -0,0 +1,149 @@
package dict
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/models"
"go-admin/pkg"
"go-admin/pkg/app"
"go-admin/pkg/utils"
"net/http"
)
// @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} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/type/list [get]
// @Security
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 = pkg.StrToInt(err, size)
}
if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex = pkg.StrToInt(err, index)
}
data.DictName = c.Request.FormValue("dictName")
id := c.Request.FormValue("dictId")
data.DictId, _ = utils.StringToInt(id)
data.DictType = c.Request.FormValue("dictType")
data.DataScope = utils.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex)
pkg.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 通过字典id获取字典类型
// @Description 获取JSON
// @Tags 字典类型
// @Param dictId path int true "字典类型编码"
// @Success 200 {object} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/type/{dictId} [get]
// @Security
func GetDictType(c *gin.Context) {
var DictType models.DictType
DictType.DictName = c.Request.FormValue("dictName")
DictType.DictId, _ = utils.StringToInt(c.Param("dictId"))
result, err := DictType.Get()
pkg.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, _ = utils.StringToInt(c.Param("dictId"))
result, err := DictType.GetList()
pkg.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 = utils.GetUserIdStr(c)
pkg.HasError(err, "", 500)
result, err := data.Create()
pkg.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 = utils.GetUserIdStr(c)
pkg.HasError(err, "", -1)
result, err := data.Update(data.DictId)
pkg.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
id, err := utils.StringToInt(c.Param("dictId"))
data.UpdateBy = utils.GetUserIdStr(c)
_, err = data.Delete(id)
pkg.HasError(err, "修改失败", 500)
c.JSON(http.StatusOK, gin.H{
"code": 200,
"message": "删除成功",
})
}
+44
View File
@@ -0,0 +1,44 @@
package system
import (
"github.com/gin-gonic/gin"
"go-admin/models"
"go-admin/pkg"
"go-admin/pkg/app"
"go-admin/pkg/utils"
)
func GetInfo(c *gin.Context) {
var roles = make([]string, 1)
roles[0] = utils.GetRoleName(c)
var permissions = make([]string, 1)
permissions[0] = "*:*:*"
RoleMenu := models.RoleMenu{}
RoleMenu.RoleId = utils.GetRoleId(c)
var mp = make(map[string]interface{})
mp["roles"] = roles
if utils.GetRoleName(c) == "admin" || utils.GetRoleName(c) == "系统管理员" {
mp["permissions"] = permissions
} else {
list, _ := RoleMenu.GetPermis()
mp["permissions"] = list
}
sysuser := models.SysUser{}
sysuser.UserId = utils.GetUserId(c)
user, err := sysuser.Get()
pkg.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["name"] = user.NickName
app.OK(c,mp,"")
}
+175
View File
@@ -0,0 +1,175 @@
package system
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/models"
"go-admin/pkg"
"go-admin/pkg/app"
"go-admin/pkg/utils"
)
// @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.DataScope = utils.GetUserIdStr(c)
result, err := Menu.SetMenu()
pkg.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 := utils.StringToInt(c.Param("id"))
data.MenuId = id
result, err := data.GetByMenuId()
pkg.HasError(err, "抱歉未找到相关信息", -1)
app.OK(c,result,"")
}
func GetMenuTreeRoleselect(c *gin.Context) {
var Menu models.Menu
var SysRole models.SysRole
id, err := utils.StringToInt(c.Param("roleId"))
SysRole.RoleId = id
result, err := Menu.SetMenuLable()
pkg.HasError(err, "抱歉未找到相关信息", -1)
menuIds := make([]int, 0)
if id != 0 {
menuIds, err = SysRole.GetRoleMeunId()
pkg.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()
pkg.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)
pkg.HasError(err, "抱歉未找到相关信息", -1)
data.CreateBy = utils.GetUserIdStr(c)
result, err := data.Create()
pkg.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 = utils.GetUserIdStr(c)
pkg.HasError(err2, "修改失败", -1)
_, err := data.Update(data.MenuId)
pkg.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 := utils.StringToInt(c.Param("id"))
data.UpdateBy = utils.GetUserIdStr(c)
_, err = data.Delete(id)
pkg.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(utils.GetRoleName(c))
pkg.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 = utils.GetUserIdStr(c)
result, err := data.GetIDS()
pkg.HasError(err, "获取失败", 500)
app.OK(c,result,"")
}
+115
View File
@@ -0,0 +1,115 @@
package system
import (
"github.com/gin-gonic/gin"
"go-admin/models"
"go-admin/pkg"
"go-admin/pkg/app"
"go-admin/pkg/utils"
)
// @Summary 职位列表数据
// @Description 获取JSON
// @Tags 职位
// @Param name query string false "name"
// @Param id query string false "id"
// @Param position query string false "position"
// @Success 200 {object} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/post [get]
// @Security
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 = pkg.StrToInt(err, size)
}
if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex = pkg.StrToInt(err, index)
}
data.PostName = c.Request.FormValue("postName")
id := c.Request.FormValue("postId")
data.PostId, _ = utils.StringToInt(id)
data.PostName = c.Request.FormValue("postName")
data.DataScope = utils.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex)
pkg.HasError(err, "", -1)
app.PageOK(c, result, count, pageIndex, pageSize, "")
}
// @Summary 获取字典数据
// @Description 获取JSON
// @Tags 字典数据
// @Param postId path int true "postId"
// @Success 200 {object} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/post/{postId} [get]
// @Security
func GetPost(c *gin.Context) {
var Post models.Post
Post.PostId, _ = utils.StringToInt(c.Param("postId"))
result, err := Post.Get()
pkg.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 = utils.GetUserIdStr(c)
pkg.HasError(err, "", 500)
result, err := data.Create()
pkg.HasError(err, "", -1)
app.OK(c,result,"")
}
// @Summary 修改职位
// @Description 获取JSON
// @Tags 职位
// @Accept application/json
// @Product application/json
// @Param data body models.Dept 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 = utils.GetUserIdStr(c)
pkg.HasError(err, "", -1)
result, err := data.Update(data.PostId)
pkg.HasError(err, "", -1)
app.OK(c,result,"修改成功")
}
// @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/post/{postId} [delete]
func DeletePost(c *gin.Context) {
var data models.Post
id, err := utils.StringToInt(c.Param("postId"))
data.UpdateBy = utils.GetUserIdStr(c)
_, err = data.Delete(id)
pkg.HasError(err, "删除失败", 500)
app.OK(c,"","删除成功")
}
+149
View File
@@ -0,0 +1,149 @@
package system
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go-admin/models"
"go-admin/pkg"
"go-admin/pkg/app"
"go-admin/pkg/utils"
)
// @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} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/rolelist [get]
// @Security
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 = pkg.StrToInt(err, size)
}
if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex = pkg.StrToInt(err, index)
}
data.RoleKey = c.Request.FormValue("roleKey")
data.RoleName = c.Request.FormValue("roleName")
data.Status = c.Request.FormValue("status")
data.DataScope = utils.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex)
pkg.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, _ = utils.StringToInt(c.Param("roleId"))
result, err := Role.Get()
menuIds := make([]int, 0)
menuIds, err = Role.GetRoleMeunId()
pkg.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.Config 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 = utils.GetUserIdStr(c)
err := c.BindWith(&data, binding.JSON)
pkg.HasError(err, "", 500)
id, err := data.Insert()
data.RoleId = id
pkg.HasError(err, "", -1)
var t models.RoleMenu
_, err = t.Insert(id, data.MenuIds)
pkg.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 = utils.GetUserIdStr(c)
err := c.Bind(&data)
pkg.HasError(err, "数据解析失败", -1)
result, err := data.Update(data.RoleId)
var t models.RoleMenu
_, err = t.DeleteRoleMenu(data.RoleId)
pkg.HasError(err, "添加失败1", -1)
_, err2 := t.Insert(data.RoleId, data.MenuIds)
pkg.HasError(err2, "添加失败2", -1)
app.OK(c, result, "修改成功")
}
func UpdateRoleDataScope(c *gin.Context) {
var data models.SysRole
data.UpdateBy = utils.GetUserIdStr(c)
err := c.Bind(&data)
pkg.HasError(err, "数据解析失败", -1)
result, err := data.Update(data.RoleId)
var t models.SysRoleDept
_, err = t.DeleteRoleDept(data.RoleId)
pkg.HasError(err, "添加失败1", -1)
if data.DataScope == "2" {
_, err2 := t.Insert(data.RoleId, data.DeptIds)
pkg.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 = utils.GetUserIdStr(c)
IDS := utils.IdsStrToIdsIntGroup("roleId", c)
_, err := Role.BatchDelete(IDS)
pkg.HasError(err, "删除失败1", -1)
var t models.RoleMenu
_, err = t.BatchDeleteRoleMenu(IDS)
pkg.HasError(err, "删除失败1", -1)
app.OK(c, "", "删除成功")
}
+71
View File
@@ -0,0 +1,71 @@
package system
import (
"fmt"
"github.com/gin-gonic/gin"
"go-admin/models"
"go-admin/pkg/app"
"net/http"
)
// @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
}
+232
View File
@@ -0,0 +1,232 @@
package system
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/google/uuid"
"go-admin/models"
"go-admin/pkg"
"go-admin/pkg/app"
"go-admin/pkg/utils"
"log"
)
// @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 = pkg.StrToInt(err, size)
}
index := c.Request.FormValue("pageIndex")
if index != "" {
pageIndex = pkg.StrToInt(err, index)
}
data.Username = c.Request.FormValue("userName")
postId := c.Request.FormValue("postId")
data.PostId, _ = utils.StringToInt(postId)
deptId := c.Request.FormValue("deptId")
data.DeptId, _ = utils.StringToInt(deptId)
data.DataScope = utils.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex)
pkg.HasError(err, "", -1)
app.PageOK(c, result, count, pageIndex, pageSize, "")
}
// @Summary 获取用户
// @Description 获取JSON
// @Tags 用户
// @Param userId path int true "用户编码"
// @Success 200 {object} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/sysUser/{userId} [get]
// @Security
func GetSysUser(c *gin.Context) {
var SysUser models.SysUser
SysUser.UserId, _ = utils.StringToInt(c.Param("userId"))
result, err := SysUser.Get()
pkg.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} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/user/profile [get]
// @Security
func GetSysUserProfile(c *gin.Context) {
var SysUser models.SysUser
userId := utils.GetUserIdStr(c)
SysUser.UserId, _ = utils.StringToInt(userId)
result, err := SysUser.Get()
pkg.HasError(err, "抱歉未找到相关信息", -1)
var SysRole models.SysRole
var Post models.Post
var Dept models.Dept
//获取角色列表
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} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/sysUser [get]
// @Security
func GetSysUserInit(c *gin.Context) {
var SysRole models.SysRole
var Post models.Post
roles, err := SysRole.GetList()
posts, err := Post.GetList()
pkg.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)
pkg.HasError(err, "非法数据格式", 500)
sysuser.CreateBy = utils.GetUserIdStr(c)
id, err := sysuser.Insert()
pkg.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.BindWith(&data, binding.JSON)
pkg.HasError(err, "数据解析失败", -1)
data.UpdateBy = utils.GetUserIdStr(c)
result, err := data.Update(data.UserId)
pkg.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 = utils.GetUserIdStr(c)
IDS := utils.IdsStrToIdsIntGroup("userId", c)
result, err := data.BatchDelete(IDS)
pkg.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 {
log.Println(file.Filename)
// 上传文件至指定目录
_ = c.SaveUploadedFile(file, filPath)
}
sysuser := models.SysUser{}
sysuser.UserId = utils.GetUserId(c)
sysuser.Avatar = "/" + filPath
sysuser.UpdateBy = utils.GetUserIdStr(c)
sysuser.Update(sysuser.UserId)
app.OK(c, filPath, "修改成功")
}
func SysUserUpdatePwd(c *gin.Context) {
var pwd models.SysUserPwd
err := c.Bind(&pwd)
pkg.HasError(err, "数据解析失败", 500)
sysuser := models.SysUser{}
sysuser.UserId = utils.GetUserId(c)
sysuser.SetPwd(pwd)
app.OK(c, "", "密码修改成功")
}