123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- package apis
- import (
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
- "github.com/go-admin-team/go-admin-core/sdk/api"
- "github.com/go-admin-team/go-admin-core/sdk/pkg"
- "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
- _ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
- "go-admin/app/admin/models"
- "go-admin/app/admin/service"
- "go-admin/app/admin/service/dto"
- )
- type SysDept struct {
- api.Api
- }
- // GetPage
- // @Summary 分页部门列表数据
- // @Description 分页列表
- // @Tags 部门
- // @Param deptName query string false "deptName"
- // @Param deptId query string false "deptId"
- // @Param position query string false "position"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /api/v1/dept [get]
- // @Security Bearer
- func (e SysDept) GetPage(c *gin.Context) {
- s := service.SysDept{}
- req := dto.SysDeptGetPageReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- list := make([]models.SysDept, 0)
- list, err = s.SetDeptPage(&req)
- if err != nil {
- e.Error(500, err, "查询失败")
- return
- }
- e.OK(list, "查询成功")
- }
- // Get
- // @Summary 获取部门数据
- // @Description 获取JSON
- // @Tags 部门
- // @Param deptId path string false "deptId"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /api/v1/dept/{deptId} [get]
- // @Security Bearer
- func (e SysDept) Get(c *gin.Context) {
- s := service.SysDept{}
- req := dto.SysDeptGetReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.JSON, nil).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- var object models.SysDept
- err = s.Get(&req, &object)
- if err != nil {
- e.Error(500, err, "查询失败")
- return
- }
- e.OK(object, "查询成功")
- }
- // Insert 添加部门
- // @Summary 添加部门
- // @Description 获取JSON
- // @Tags 部门
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.SysDeptInsertReq true "data"
- // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
- // @Router /api/v1/dept [post]
- // @Security Bearer
- func (e SysDept) Insert(c *gin.Context) {
- s := service.SysDept{}
- req := dto.SysDeptInsertReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.JSON).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- // 设置创建人
- req.SetCreateBy(user.GetUserId(c))
- err = s.Insert(&req)
- if err != nil {
- e.Error(500, err, "创建失败")
- return
- }
- e.OK(req.GetId(), "创建成功")
- }
- // Update
- // @Summary 修改部门
- // @Description 获取JSON
- // @Tags 部门
- // @Accept application/json
- // @Product application/json
- // @Param id path int true "id"
- // @Param data body dto.SysDeptUpdateReq true "body"
- // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
- // @Router /api/v1/dept/{deptId} [put]
- // @Security Bearer
- func (e SysDept) Update(c *gin.Context) {
- s := service.SysDept{}
- req := dto.SysDeptUpdateReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- req.SetUpdateBy(user.GetUserId(c))
- err = s.Update(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.GetId(), "更新成功")
- }
- // Delete
- // @Summary 删除部门
- // @Description 删除数据
- // @Tags 部门
- // @Param data body dto.SysDeptDeleteReq true "body"
- // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
- // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
- // @Router /api/v1/dept [delete]
- // @Security Bearer
- func (e SysDept) Delete(c *gin.Context) {
- s := service.SysDept{}
- req := dto.SysDeptDeleteReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.JSON, nil).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- err = s.Remove(&req)
- if err != nil {
- e.Error(500, err, "删除失败")
- return
- }
- e.OK(req.GetId(), "删除成功")
- }
- // Get2Tree 用户管理 左侧部门树
- func (e SysDept) Get2Tree(c *gin.Context) {
- s := service.SysDept{}
- req := dto.SysDeptGetPageReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req,binding.Form).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- list := make([]dto.DeptLabel, 0)
- list, err = s.SetDeptTree(&req)
- if err != nil {
- e.Error(500, err, "查询失败")
- return
- }
- e.OK(list, "")
- }
- // GetDeptTreeRoleSelect TODO: 此接口需要调整不应该将list和选中放在一起
- func (e SysDept) GetDeptTreeRoleSelect(c *gin.Context) {
- s := service.SysDept{}
- err := e.MakeContext(c).
- MakeOrm().
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- id, err := pkg.StringToInt(c.Param("roleId"))
- result, err := s.SetDeptLabel()
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- menuIds := make([]int, 0)
- if id != 0 {
- menuIds, err = s.GetWithRoleId(id)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- }
- e.OK(gin.H{
- "depts": result,
- "checkedKeys": menuIds,
- }, "")
- }
|