update project path
This commit is contained in:
1 parent
26acdbd0d1
commit
e027e6a259
76 files changed
+2562
-106
No files matched your search
@@ -0,0 +1 @@
|
||||
package apis
|
||||
@@ -0,0 +1,40 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"github.com/mojocn/base64Captcha"
|
||||
"image/color"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//configJsonBody json request body.
|
||||
type configJsonBody struct {
|
||||
Id string
|
||||
CaptchaType string
|
||||
VerifyValue string
|
||||
DriverAudio *base64Captcha.DriverAudio
|
||||
DriverString *base64Captcha.DriverString
|
||||
DriverChinese *base64Captcha.DriverChinese
|
||||
DriverMath *base64Captcha.DriverMath
|
||||
DriverDigit *base64Captcha.DriverDigit
|
||||
}
|
||||
|
||||
var store = base64Captcha.DefaultMemStore
|
||||
|
||||
func GenerateCaptchaHandler(c *gin.Context) {
|
||||
|
||||
var param configJsonBody
|
||||
param.Id = uuid.New().String()
|
||||
param.CaptchaType = "string"
|
||||
param.DriverString = base64Captcha.NewDriverString(46, 140, 2, 2, 4, "234567890abcdefghjkmnpqrstuvwxyz", &color.RGBA{240, 240, 246, 246}, []string{"wqy-microhei.ttc"})
|
||||
driver := param.DriverString.ConvertFonts()
|
||||
|
||||
cap := base64Captcha.NewCaptcha(driver, store)
|
||||
id, b64s, err := cap.Generate()
|
||||
body := map[string]interface{}{"code": 200, "data": b64s, "id": id, "msg": "success"}
|
||||
if err != nil {
|
||||
body = map[string]interface{}{"code": 0, "msg": err.Error()}
|
||||
}
|
||||
c.JSON(http.StatusOK, body)
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"go-admin/models"
|
||||
"go-admin/pkg"
|
||||
"go-admin/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.Config
|
||||
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.AssertErr(err, "", -1)
|
||||
|
||||
var mp = make(map[string]interface{}, 3)
|
||||
mp["list"] = result
|
||||
mp["count"] = count
|
||||
mp["pageIndex"] = pageIndex
|
||||
mp["pageIndex"] = pageSize
|
||||
|
||||
var res models.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.Config
|
||||
Config.ConfigId, _ = utils.StringToInt64(c.Param("configId"))
|
||||
result, err := Config.Get()
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
var res models.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.Config
|
||||
Config.ConfigKey = c.Param("configKey")
|
||||
result, err := Config.Get()
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
res.Msg = result.ConfigValue
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @Summary 添加配置
|
||||
// @Description 获取JSON
|
||||
// @Tags 配置
|
||||
// @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/dict/data [post]
|
||||
// @Security Bearer
|
||||
func InsertConfig(c *gin.Context) {
|
||||
var data models.Config
|
||||
err := c.BindWith(&data, binding.JSON)
|
||||
data.CreateBy = utils.GetUserIdStr(c)
|
||||
pkg.AssertErr(err, "", 500)
|
||||
result, err := data.Create()
|
||||
pkg.AssertErr(err, "", -1)
|
||||
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
|
||||
}
|
||||
|
||||
// @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.Config
|
||||
err := c.BindWith(&data, binding.JSON)
|
||||
pkg.AssertErr(err, "数据解析失败", -1)
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
result, err := data.Update(data.ConfigId)
|
||||
pkg.AssertErr(err, "", -1)
|
||||
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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.Config
|
||||
id, err := utils.StringToInt64(c.Param("configId"))
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
_, err = data.Delete(id)
|
||||
pkg.AssertErr(err, "修改失败", 500)
|
||||
|
||||
var res models.Response
|
||||
res.Msg = "删除成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"go-admin/models"
|
||||
"go-admin/pkg"
|
||||
"go-admin/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// @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.StringToInt64(c.Request.FormValue("deptId"))
|
||||
Dept.DataScope = utils.GetUserIdStr(c)
|
||||
result, err := Dept.SetDept(true)
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
func GetDeptTree(c *gin.Context) {
|
||||
var Dept models.Dept
|
||||
Dept.Deptname = c.Request.FormValue("deptName")
|
||||
Dept.Status = c.Request.FormValue("status")
|
||||
Dept.Deptid, _ = utils.StringToInt64(c.Request.FormValue("deptId"))
|
||||
result, err := Dept.SetDept(false)
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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, _ = strconv.ParseInt(c.Param("deptId"), 10, 64)
|
||||
Dept.DataScope = utils.GetUserIdStr(c)
|
||||
result, err := Dept.Get()
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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.AssertErr(err, "", 500)
|
||||
data.CreateBy = utils.GetUserIdStr(c)
|
||||
result, err := data.Create()
|
||||
pkg.AssertErr(err, "", -1)
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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.AssertErr(err, "", -1)
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
result, err := data.Update(data.Deptid)
|
||||
pkg.AssertErr(err, "", -1)
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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 := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
_, err = data.Delete(id)
|
||||
pkg.AssertErr(err, "删除失败", 500)
|
||||
|
||||
var res models.Response
|
||||
res.Msg = "删除成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
func GetDeptTreeRoleselect(c *gin.Context) {
|
||||
var Dept models.Dept
|
||||
var SysRole models.SysRole
|
||||
id, err := strconv.ParseInt(c.Param("roleId"), 10, 64)
|
||||
SysRole.Id = id
|
||||
result, err := Dept.SetDeptLable()
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
menuIds := make([]int64, 0)
|
||||
if id != 0 {
|
||||
menuIds, err = SysRole.GetRoleDeptId()
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 200,
|
||||
"depts": result,
|
||||
"checkedKeys": menuIds,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"go-admin/models"
|
||||
"go-admin/pkg"
|
||||
"go-admin/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.StringToInt64(id)
|
||||
data.Status = c.Request.FormValue("status")
|
||||
data.DataScope = utils.GetUserIdStr(c)
|
||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||
pkg.AssertErr(err, "", -1)
|
||||
|
||||
var mp = make(map[string]interface{}, 3)
|
||||
mp["list"] = result
|
||||
mp["count"] = count
|
||||
mp["pageIndex"] = pageIndex
|
||||
mp["pageIndex"] = pageSize
|
||||
|
||||
var res models.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.StringToInt64(c.Param("dictCode"))
|
||||
result, err := DictData.GetByCode()
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
var res models.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.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
var res models.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.AssertErr(err, "", 500)
|
||||
result, err := data.Create()
|
||||
pkg.AssertErr(err, "", -1)
|
||||
var res models.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.AssertErr(err, "", -1)
|
||||
result, err := data.Update(data.DictCode)
|
||||
pkg.AssertErr(err, "", -1)
|
||||
var res models.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.StringToInt64(c.Param("dictCode"))
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
_, err = data.Delete(id)
|
||||
pkg.AssertErr(err, "修改失败", 500)
|
||||
|
||||
var res models.Response
|
||||
res.Msg = "删除成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"go-admin/models"
|
||||
"go-admin/pkg"
|
||||
"go-admin/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// @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.StringToInt64(id)
|
||||
data.DictType = c.Request.FormValue("dictType")
|
||||
data.DataScope = utils.GetUserIdStr(c)
|
||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||
pkg.AssertErr(err, "", -1)
|
||||
|
||||
var mp = make(map[string]interface{}, 3)
|
||||
mp["list"] = result
|
||||
mp["count"] = count
|
||||
mp["pageIndex"] = pageIndex
|
||||
mp["pageIndex"] = pageSize
|
||||
|
||||
var res models.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, _ = strconv.ParseInt(c.Param("dictId"), 10, 64)
|
||||
result, err := DictType.Get()
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
var res models.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.AssertErr(err, "", 500)
|
||||
result, err := data.Create()
|
||||
pkg.AssertErr(err, "", -1)
|
||||
var res models.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.AssertErr(err, "", -1)
|
||||
result, err := data.Update(data.DictId)
|
||||
pkg.AssertErr(err, "", -1)
|
||||
var res models.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.StringToInt64(c.Param("dictId"))
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
_, err = data.Delete(id)
|
||||
pkg.AssertErr(err, "修改失败", 500)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 200,
|
||||
"message": "删除成功",
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/models"
|
||||
"go-admin/pkg"
|
||||
"go-admin/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
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.Id = utils.GetUserId(c)
|
||||
user, err := sysuser.Get()
|
||||
pkg.AssertErr(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
|
||||
|
||||
var res models.Response
|
||||
res.Data = mp
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"go-admin/models"
|
||||
"go-admin/pkg"
|
||||
"go-admin/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// @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/loginloglist [get]
|
||||
// @Security
|
||||
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 = pkg.StrToInt(err, size)
|
||||
}
|
||||
|
||||
index := c.Request.FormValue("pageIndex")
|
||||
if index != "" {
|
||||
pageIndex = pkg.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)
|
||||
pkg.AssertErr(err, "", -1)
|
||||
|
||||
var mp = make(map[string]interface{}, 3)
|
||||
mp["list"] = result
|
||||
mp["count"] = count
|
||||
mp["pageIndex"] = pageIndex
|
||||
mp["pageIndex"] = pageSize
|
||||
|
||||
var res models.Response
|
||||
res.Data = mp
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @Summary 通过编码获取登录日志
|
||||
// @Description 获取JSON
|
||||
// @Tags 登录日志
|
||||
// @Param infoId path int true "infoId"
|
||||
// @Success 200 {object} models.Response "{"code": 200, "data": [...]}"
|
||||
// @Router /api/v1/loginlog/{infoId} [get]
|
||||
// @Security
|
||||
func GetLoginLog(c *gin.Context) {
|
||||
var LoginLog models.LoginLog
|
||||
LoginLog.InfoId, _ = strconv.ParseInt(c.Param("infoId"), 10, 64)
|
||||
result, err := LoginLog.Get()
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
var res models.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)
|
||||
pkg.AssertErr(err, "", 500)
|
||||
result, err := data.Create()
|
||||
pkg.AssertErr(err, "", -1)
|
||||
var res models.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)
|
||||
pkg.AssertErr(err, "", -1)
|
||||
result, err := data.Update(data.InfoId)
|
||||
pkg.AssertErr(err, "", -1)
|
||||
var res models.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 = utils.GetUserIdStr(c)
|
||||
IDS := utils.IdsStrToIdsInt64Group("infoId", c)
|
||||
_, err := data.BatchDelete(IDS)
|
||||
pkg.AssertErr(err, "修改失败", 500)
|
||||
var res models.Response
|
||||
res.Msg = "删除成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
+195
@@ -0,0 +1,195 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"go-admin/models"
|
||||
"go-admin/pkg"
|
||||
"go-admin/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// @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.DataScope = utils.GetUserIdStr(c)
|
||||
result, err := Menu.SetMenu()
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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 := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
data.MenuId = id
|
||||
result, err := data.GetByMenuId()
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
func GetMenuTreeRoleselect(c *gin.Context) {
|
||||
var Menu models.Menu
|
||||
var SysRole models.SysRole
|
||||
id, err := strconv.ParseInt(c.Param("roleId"), 10, 64)
|
||||
SysRole.Id = id
|
||||
result, err := Menu.SetMenuLable()
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
menuIds := make([]int64, 0)
|
||||
if id != 0 {
|
||||
menuIds, err = SysRole.GetRoleMeunId()
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
}
|
||||
c.JSON(http.StatusOK, 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.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
data.CreateBy = utils.GetUserIdStr(c)
|
||||
result, err := data.Create()
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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.AssertErr(err2, "修改失败", -1)
|
||||
_, err := data.Update(data.MenuId)
|
||||
pkg.AssertErr(err, "", 501)
|
||||
|
||||
var res models.Response
|
||||
res.Msg = "修改成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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.StringToInt64(c.Param("id"))
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
_, err = data.Delete(id)
|
||||
pkg.AssertErr(err, "删除失败", 500)
|
||||
|
||||
var res models.Response
|
||||
res.Msg = "删除成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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.AssertErr(err, "获取失败", 500)
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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.AssertErr(err, "获取失败", 500)
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"go-admin/models"
|
||||
"go-admin/pkg"
|
||||
"go-admin/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// @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/operloglist [get]
|
||||
// @Security
|
||||
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 = pkg.StrToInt(err, size)
|
||||
}
|
||||
|
||||
index := c.Request.FormValue("pageIndex")
|
||||
if index != "" {
|
||||
pageIndex = pkg.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)
|
||||
pkg.AssertErr(err, "", -1)
|
||||
|
||||
var mp = make(map[string]interface{}, 3)
|
||||
mp["list"] = result
|
||||
mp["count"] = count
|
||||
mp["pageIndex"] = pageIndex
|
||||
mp["pageIndex"] = pageSize
|
||||
|
||||
var res models.Response
|
||||
res.Data = mp
|
||||
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @Summary 通过编码获取登录日志
|
||||
// @Description 获取JSON
|
||||
// @Tags 登录日志
|
||||
// @Param infoId path int true "infoId"
|
||||
// @Success 200 {object} models.Response "{"code": 200, "data": [...]}"
|
||||
// @Router /api/v1/operlog/{infoId} [get]
|
||||
// @Security
|
||||
func GetOperLog(c *gin.Context) {
|
||||
var OperLog models.SysOperLog
|
||||
OperLog.OperId, _ = strconv.ParseInt(c.Param("operId"), 10, 64)
|
||||
result, err := OperLog.Get()
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
var res models.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)
|
||||
pkg.AssertErr(err, "", 500)
|
||||
result, err := data.Create()
|
||||
pkg.AssertErr(err, "", -1)
|
||||
var res models.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 = utils.GetUserIdStr(c)
|
||||
IDS := utils.IdsStrToIdsInt64Group("operId", c)
|
||||
_, err := data.BatchDelete(IDS)
|
||||
pkg.AssertErr(err, "删除失败", 500)
|
||||
var res models.Response
|
||||
res.Msg = "删除成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/models"
|
||||
"go-admin/pkg"
|
||||
"go-admin/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// @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.StringToInt64(id)
|
||||
|
||||
data.PostName = c.Request.FormValue("postName")
|
||||
data.DataScope = utils.GetUserIdStr(c)
|
||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||
pkg.AssertErr(err, "", -1)
|
||||
|
||||
var mp = make(map[string]interface{}, 3)
|
||||
mp["list"] = result
|
||||
mp["count"] = count
|
||||
mp["pageIndex"] = pageIndex
|
||||
mp["pageIndex"] = pageSize
|
||||
|
||||
var res models.Response
|
||||
res.Data = mp
|
||||
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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, _ = strconv.ParseInt(c.Param("postId"), 10, 64)
|
||||
result, err := Post.Get()
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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.AssertErr(err, "", 500)
|
||||
result, err := data.Create()
|
||||
pkg.AssertErr(err, "", -1)
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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.AssertErr(err, "", -1)
|
||||
result, err := data.Update(data.PostId)
|
||||
pkg.AssertErr(err, "", -1)
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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.StringToInt64(c.Param("postId"))
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
_, err = data.Delete(id)
|
||||
pkg.AssertErr(err, "删除失败", 500)
|
||||
var res models.Response
|
||||
res.Msg = "删除成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"go-admin/models"
|
||||
"go-admin/pkg"
|
||||
"go-admin/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// @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/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.Name = c.Request.FormValue("roleName")
|
||||
data.Status = c.Request.FormValue("status")
|
||||
data.DataScope = utils.GetUserIdStr(c)
|
||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||
pkg.AssertErr(err, "", -1)
|
||||
|
||||
var mp = make(map[string]interface{}, 3)
|
||||
mp["list"] = result
|
||||
mp["count"] = count
|
||||
mp["pageIndex"] = pageIndex
|
||||
mp["pageIndex"] = pageSize
|
||||
|
||||
var res models.Response
|
||||
res.Data = mp
|
||||
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @Summary 获取Role数据
|
||||
// @Description 获取JSON
|
||||
// @Tags 角色
|
||||
// @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.Id, _ = strconv.ParseInt(c.Param("roleId"), 10, 64)
|
||||
result, err := Role.Get()
|
||||
|
||||
menuIds := make([]int64, 0)
|
||||
|
||||
menuIds, err = Role.GetRoleMeunId()
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
result.MenuIds = menuIds
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": -1,
|
||||
"msg": "抱歉未找到相关信息",
|
||||
})
|
||||
return
|
||||
}
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @Summary 创建角色
|
||||
// @Description 获取JSON
|
||||
// @Tags 角色
|
||||
// @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.AssertErr(err, "", 500)
|
||||
id, err := data.Insert()
|
||||
data.Id = id
|
||||
pkg.AssertErr(err, "", -1)
|
||||
var t models.RoleMenu
|
||||
_, err = t.Insert(id, data.MenuIds)
|
||||
pkg.AssertErr(err, "", -1)
|
||||
var res models.Response
|
||||
res.Data = data
|
||||
res.Msg = "添加成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @Summary 修改用户角色
|
||||
// @Description 获取JSON
|
||||
// @Tags 角色
|
||||
// @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.AssertErr(err, "数据解析失败", -1)
|
||||
result, err := data.Update(data.Id)
|
||||
|
||||
var t models.RoleMenu
|
||||
_, err = t.DeleteRoleMenu(data.Id)
|
||||
pkg.AssertErr(err, "添加失败1", -1)
|
||||
|
||||
_, err2 := t.Insert(data.Id, data.MenuIds)
|
||||
pkg.AssertErr(err2, "添加失败2", -1)
|
||||
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
res.Msg = "修改成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
func UpdateRoleDataScope(c *gin.Context) {
|
||||
var data models.SysRole
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
err := c.Bind(&data)
|
||||
pkg.AssertErr(err, "数据解析失败", -1)
|
||||
result, err := data.Update(data.Id)
|
||||
|
||||
var t models.SysRoleDept
|
||||
_, err = t.DeleteRoleDept(data.Id)
|
||||
pkg.AssertErr(err, "添加失败1", -1)
|
||||
if data.DataScope == "2" {
|
||||
_, err2 := t.Insert(data.Id, data.DeptIds)
|
||||
pkg.AssertErr(err2, "添加失败2", -1)
|
||||
}
|
||||
var res models.Response
|
||||
res.Data = result
|
||||
res.Msg = "修改成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @Summary 删除用户角色
|
||||
// @Description 删除数据
|
||||
// @Tags 角色
|
||||
// @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.IdsStrToIdsInt64Group("roleId", c)
|
||||
_, err := Role.BatchDelete(IDS)
|
||||
pkg.AssertErr(err, "删除失败1", -1)
|
||||
var t models.RoleMenu
|
||||
_, err = t.BatchDeleteRoleMenu(IDS)
|
||||
pkg.AssertErr(err, "删除失败1", -1)
|
||||
|
||||
var res models.Response
|
||||
res.Msg = "删除成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/models"
|
||||
"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 models.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
|
||||
}
|
||||
|
||||
// @Summary 创建角色菜单
|
||||
// @Description 获取JSON
|
||||
// @Tags 角色菜单
|
||||
// @Accept application/x-www-form-urlencoded
|
||||
// @Product application/x-www-form-urlencoded
|
||||
// @Param role_id formData string true "role_id"
|
||||
// @Param menu_id formData string true "menu_id"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
||||
// @Router /api/v1/rolemenu [post]
|
||||
func InsertRoleMenu(c *gin.Context) {
|
||||
//roleId := c.Request.FormValue("role_id")
|
||||
//menuId := c.Request.FormValue("menu_id")
|
||||
//menus := strings.Split(menuId, ",")
|
||||
//fmt.Println(menus)
|
||||
//var t models.RoleMenu
|
||||
//_,err := t.DeleteRoleMenu(roleId)
|
||||
//if err != nil {
|
||||
// c.JSON(http.StatusOK, gin.H{
|
||||
// "code": -1,
|
||||
// "message": "添加失败1",
|
||||
// })
|
||||
// return
|
||||
//}
|
||||
//_, err2 := t.Insert(roleId, menus)
|
||||
//if err2 != nil {
|
||||
// c.JSON(http.StatusOK, gin.H{
|
||||
// "code": -1,
|
||||
// "message": "添加失败2",
|
||||
// })
|
||||
// return
|
||||
//}
|
||||
var res models.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) {
|
||||
fmt.Println("!!!!!!!!!!!!!!")
|
||||
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 models.Response
|
||||
res.Msg = "删除失败"
|
||||
c.JSON(http.StatusOK, res.ReturnError(200))
|
||||
return
|
||||
}
|
||||
var res models.Response
|
||||
res.Msg = "删除成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
return
|
||||
}
|
||||
+276
@@ -0,0 +1,276 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"github.com/google/uuid"
|
||||
"go-admin/models"
|
||||
"go-admin/pkg"
|
||||
"go-admin/utils"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// @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, _ = strconv.ParseInt(postId, 10, 64)
|
||||
|
||||
deptId := c.Request.FormValue("deptId")
|
||||
data.DeptId, _ = strconv.ParseInt(deptId, 10, 64)
|
||||
|
||||
data.DataScope = utils.GetUserIdStr(c)
|
||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||
pkg.AssertErr(err, "", -1)
|
||||
|
||||
var mp = make(map[string]interface{}, 3)
|
||||
mp["list"] = result
|
||||
mp["count"] = count
|
||||
mp["pageIndex"] = pageIndex
|
||||
mp["pageIndex"] = pageSize
|
||||
|
||||
var res models.Response
|
||||
res.Data = mp
|
||||
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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.Id, _ = strconv.ParseInt(c.Param("userId"), 10, 64)
|
||||
result, err := SysUser.Get()
|
||||
pkg.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
var SysRole models.SysRole
|
||||
var Post models.Post
|
||||
roles, err := SysRole.GetList()
|
||||
posts, err := Post.GetList()
|
||||
|
||||
postIds := make([]int64, 0)
|
||||
postIds = append(postIds, result.PostId)
|
||||
|
||||
roleIds := make([]int64, 0)
|
||||
roleIds = append(roleIds, result.RoleId)
|
||||
|
||||
c.JSON(http.StatusOK, 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.Id, _ = strconv.ParseInt(userId, 10, 64)
|
||||
result, err := SysUser.Get()
|
||||
pkg.AssertErr(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([]int64, 0)
|
||||
postIds = append(postIds, result.PostId)
|
||||
|
||||
roleIds := make([]int64, 0)
|
||||
roleIds = append(roleIds, result.RoleId)
|
||||
|
||||
c.JSON(http.StatusOK, 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.AssertErr(err, "抱歉未找到相关信息", -1)
|
||||
mp := make(map[string]interface{}, 2)
|
||||
mp["roles"] = roles
|
||||
mp["posts"] = posts
|
||||
var res models.Response
|
||||
res.Data = mp
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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.AssertErr(err, "非法数据格式", 500)
|
||||
|
||||
sysuser.CreateTime = utils.GetCurrntTime()
|
||||
sysuser.UpdateTime = utils.GetCurrntTime()
|
||||
sysuser.CreateBy = utils.GetUserIdStr(c)
|
||||
id, err := sysuser.Insert()
|
||||
var res models.Response
|
||||
if err != nil {
|
||||
res.Msg = "添加失败"
|
||||
c.JSON(http.StatusOK, res.ReturnError(200))
|
||||
return
|
||||
}
|
||||
res.Data = id
|
||||
res.Msg = "添加成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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.AssertErr(err, "数据解析失败", -1)
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
result, err := data.Update(data.Id)
|
||||
var res models.Response
|
||||
if err != nil || result.Id == 0 {
|
||||
res.Msg = "修改失败"
|
||||
c.JSON(http.StatusOK, res.ReturnError(200))
|
||||
return
|
||||
}
|
||||
res.Msg = "修改成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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.IdsStrToIdsInt64Group("userId", c)
|
||||
result, err := data.BatchDelete(IDS)
|
||||
if err != nil || !result {
|
||||
var res models.Response
|
||||
res.Msg = "删除失败"
|
||||
c.JSON(http.StatusOK, res.ReturnError(501))
|
||||
return
|
||||
}
|
||||
var res models.Response
|
||||
res.Msg = "删除成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @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.Id = utils.GetUserId(c)
|
||||
sysuser.Avatar = "/" + filPath
|
||||
sysuser.UpdateBy = utils.GetUserIdStr(c)
|
||||
sysuser.Update(sysuser.Id)
|
||||
|
||||
c.JSON(http.StatusCreated, gin.H{
|
||||
"code": 200,
|
||||
"data": filPath,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func SysUserUpdatePwd(c *gin.Context) {
|
||||
var pwd models.SysUserPwd
|
||||
err := c.Bind(&pwd)
|
||||
pkg.AssertErr(err, "数据解析失败", 500)
|
||||
sysuser := models.SysUser{}
|
||||
sysuser.Id = utils.GetUserId(c)
|
||||
sysuser.SetPwd(pwd)
|
||||
c.JSON(http.StatusCreated, gin.H{
|
||||
"code": 200,
|
||||
"data": "密码修改成功",
|
||||
})
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user