123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- package admin
- import (
- "strconv"
- "strings"
- "ulink-admin/frame"
- "ulink-admin/modules/system/models/model"
- "ulink-admin/modules/system/models/req"
- "ulink-admin/modules/system/service"
- "ulink-admin/pkg/jwt/admin"
- "ulink-admin/pkg/library/tree/tree_dept"
- )
- type DeptApi struct {
- DeptService *service.DeptService `inject:""`
- }
- // TreeSelect 查询部门部门树
- // @Summary 加载对应角色部门列表树接口
- // @Description 加载对应角色部门列表树接口
- // @Tags 部门相关接口
- // @Accept application/json
- // @Produce application/json
- // @Param Authorization header string false "Bearer 令牌"
- // @Param id path int true "id" id
- // @Security ApiKeyAuth
- // @Success 200 {object} resp.Response{data=map[INode]interface{}} "返回部门查询"
- // @Router /dept/teeselect [get]
- func (a DeptApi) TreeSelect(c *frame.Context) {
- query := req.DeptQuery{}
- c.ValidteError(c.ShouldBind(&query), &query)
- treeSelect := a.DeptService.TreeSelect(query)
- var list tree_dept.DeptList = *treeSelect
- c.Ok(list.GetTree())
- }
- // RoleDeptTreeSelect 加载对应角色部门列表树
- // @Summary 加载对应角色部门列表树接口
- // @Description 加载对应角色部门列表树接口
- // @Tags 部门相关接口
- // @Accept application/json
- // @Produce application/json
- // @Param Authorization header string false "Bearer 令牌"
- // @Param id path int true "id" id
- // @Security ApiKeyAuth
- // @Success 200 {object} resp.Response{data=map[INode]interface{}} "返回部门查询"
- // @Router /dept/roleDeptTreeselect [get]
- func (a DeptApi) RoleDeptTreeSelect(c *frame.Context) {
- m := make(map[string]interface{})
- param := c.Param("id")
- id, _ := strconv.ParseInt(param, 10, 64)
- checkedKeys := a.DeptService.SelectDeptListByRoleId(id)
- m["checkedKeys"] = checkedKeys
- treeSelect := a.DeptService.TreeSelect(req.DeptQuery{})
- var list tree_dept.DeptList = *treeSelect
- tree := list.GetTree()
- m["depts"] = tree
- c.Ok(m)
- }
- // Find 查询部门列表
- // @Summary 分页查询部门数据接口
- // @Description 分页查询部门数据接口
- // @Tags 部门相关接口
- // @Accept application/json
- // @Produce application/json
- // @Param Authorization header string false "Bearer 令牌"
- // @Param object query req.DeptQuery false "查询参数"
- // @Security ApiKeyAuth
- // @Success 200 {object} resp.Response{data=dept.Page} "分页获取部门列表,返回包括列表,总数,页码,每页数量"
- // @Router /dept/List [get]
- func (a DeptApi) Find(c *frame.Context) {
- query := req.DeptQuery{}
- c.ValidteError(c.ShouldBind(&query), &query)
- c.Ok(a.DeptService.GetList(query))
- }
- // ExcludeChild 查询部门列表(排除节点)
- // @Summary 分页查询部门数据接口 排除节点
- // @Description 分页查询部门数据接口 排除节点
- // @Tags 部门相关接口
- // @Accept application/json
- // @Produce application/json
- // @Param Authorization header string false "Bearer 令牌"
- // @Param object query req.DeptQuery false "查询参数"
- // @Security ApiKeyAuth
- // @Success 200 {object} resp.Response{data=model.SysDept} "分页获取部门列表,返回包括列表,总数,页码,每页数量"
- // @Router /dept/list/exclude [get]
- func (a DeptApi) ExcludeChild(c *frame.Context) {
- var params struct {
- Id int64 `uri:"id" binding:"required" msg:"id不存在"` //ids
- }
- c.ValidteError(c.ShouldBindUri(¶ms), ¶ms)
- list := a.DeptService.GetList(req.DeptQuery{})
- var depts = *list
- deptList := make([]model.SysDept, 0)
- for _, dept := range depts {
- if dept.Id == params.Id || strings.Contains(dept.Ancestors, strconv.FormatInt(params.Id, 10)) {
- continue
- }
- deptList = append(deptList, dept)
- }
- c.Ok(deptList)
- }
- // GetInfo 根据部门编号获取详细信息
- // @Summary 部门详情查询接口
- // @Description 部门详情查询接口
- // @Tags 部门相关接口
- // @Accept application/json
- // @Produce application/json
- // @Param Authorization header string false "Bearer 令牌"
- // @Param id path int true "id" id
- // @Security ApiKeyAuth
- // @Success 200 {object} resp.Response{data=model.SysDept} "返回部门详情查询"
- // @Router /dept [get]
- func (a DeptApi) GetInfo(c *frame.Context) {
- var params struct {
- Id int64 `uri:"id" binding:"required" msg:"id不存在"` //ids
- }
- c.ValidteError(c.ShouldBindUri(¶ms), ¶ms)
- c.Ok(a.DeptService.GetDeptById(params.Id))
- }
- // Add 添加部门
- // @Summary 新增部门接口
- // @Description 新增部门接口
- // @Tags 部门相关接口
- // @Accept application/json
- // @Produce application/json
- // @Param Authorization header string false "Bearer 令牌"
- // @Param data body model.SysDept true "部门实体对象"
- // @Success 200 {object} resp.Response{msg=string} "操作状态"
- // @Router /dept/add [post]
- func (a DeptApi) Add(c *frame.Context) {
- dept := model.SysDept{}
- c.ValidteError(c.ShouldBind(&dept), &dept)
- //校验部门名称是否唯一
- unique := a.DeptService.CheckDeptNameUnique(dept)
- if unique {
- frame.Throw(frame.BUSINESS_CODE, "新增部门'"+dept.DeptName+"'失败,部门名称已存在")
- return
- }
- info := a.DeptService.GetDeptById(dept.ParentId)
- if info == nil {
- frame.Throw(frame.BUSINESS_CODE, "部门查询异常'")
- return
- }
- if info.Status == 1 {
- frame.Throw(frame.BUSINESS_CODE, "部门停用,不允许新增")
- return
- }
- dept.Ancestors = info.Ancestors + "," + strconv.FormatInt(dept.ParentId, 10)
- dept.CreateBy = admin.GetUserInfo(c).UserName
- a.DeptService.Insert(dept)
- }
- // Edit 修改部门数据
- // @Summary 修改部门接口
- // @Description 新增部门接口
- // @Tags 部门相关接口
- // @Accept application/json
- // @Produce application/json
- // @Param Authorization header string false "Bearer 令牌"
- // @Param data body model.SysDept true "部门实体对象"
- // @Success 200 {object} resp.Response{msg=string} "操作状态"
- // @Router /dept/edit [put]
- func (a DeptApi) Edit(c *frame.Context) {
- dept := model.SysDept{}
- c.ValidteError(c.ShouldBind(&dept), &dept)
- a.DeptService.Update(dept)
- }
- // Delete 删除部门
- // @Summary 删除部门接口
- // @Description 删除部门接口
- // @Tags 部门相关接口
- // @Accept application/json
- // @Produce application/json
- // @Param Authorization header string false "Bearer 令牌"
- // @Param id path int true "id" id
- // @Success 200 {object} resp.Response{msg=string} "操作状态"
- // @Router /dept/remove [delete]
- func (a DeptApi) Delete(c *frame.Context) {
- var params struct {
- Id int64 `uri:"id" binding:"required" msg:"id不存在"` //ids
- }
- c.ValidteError(c.ShouldBindUri(¶ms), ¶ms)
- //是否存在部门子节点
- if a.DeptService.HasChildByDeptId(params.Id) > 0 {
- frame.Throw(frame.BUSINESS_CODE, "存在下级部门,不允许删除")
- return
- }
- if a.DeptService.CheckDeptExistUser(params.Id) > 0 {
- frame.Throw(frame.BUSINESS_CODE, "部门存在用户,不允许删除")
- return
- }
- a.DeptService.Remove(params.Id)
- }
|