123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- using Attribute;
- using Common;
- using Dto;
- using Enums;
- using Extensions;
- using Filters;
- using Infrastructure;
- using Mapster;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using Middleware;
- using Model;
- using Model.Base;
- using Services;
- using System.Collections;
- using Util;
- using Vo;
- namespace Controllers
- {
- /// <summary>
- /// 部门
- /// </summary>
- [Verify]
- public class SysDeptController : BaseController
- {
- public ISysDeptService DeptService;
- public ISysUserService UserService;
- public SysDeptController(ISysDeptService deptService
- , ISysUserService userService)
- {
- DeptService = deptService;
- UserService = userService;
- }
- /// <summary>
- /// 获取部门列表
- /// </summary>
- /// <returns></returns>
- [HttpGet("list")]
- public IActionResult List([FromQuery] SysDeptQueryDto dept)
- {
- return SUCCESS(DeptService.GetSysDepts(dept), TIME_FORMAT_FULL);
- }
- /// <summary>
- /// 获取所有部门列表
- /// </summary>
- /// <returns></returns>
- [HttpGet("/v1/tel/sysServer/dept/list")]
- public IActionResult AllList()
- {
- return SUCCESS(DeptService.GetList(), TIME_FORMAT_FULL);
- }
- [AllowAnonymous]
- [HttpGet("/feign/dept/query")]
- public DeptFeignVo Query([FromQuery] long id)
- {
- var info = DeptService.GetFirst(m => m.deptId == id).Adapt<DeptFeignVo>();
- return info;
- }
- /// <summary>
- /// 查询部门列表(排除节点)
- /// </summary>
- /// <param name="deptId"></param>
- /// <returns></returns>
- [HttpGet("list/exclude/{deptId}")]
- public IActionResult ExcludeChild(long deptId)
- {
- var depts = DeptService.GetSysDepts(new SysDeptQueryDto());
- // for (int i = 0; i < depts.Count; i++)
- // {
- // SysDept d = depts[i];
- // long[] deptIds = Tools.SpitLongArrary(d.Ancestors);
- // if (d.DeptId == deptId || ((IList)deptIds).Contains(deptId))
- // {
- // depts.Remove(d);
- // }
- // }
- return SUCCESS(depts);
- }
- /// <summary>
- /// 获取部门下拉树列表
- /// </summary>
- /// <param name="dept"></param>
- /// <returns></returns>
- [HttpGet("/v1/tel/sysServer/dept/tree")]
- public IActionResult TreeSelect(SysDeptQueryDto dept)
- {
- var depts = DeptService.GetSysDepts(dept);
- return SUCCESS(DeptService.BuildDeptTreeSelect(depts), TIME_FORMAT_FULL);
- }
- /// <summary>
- /// 获取角色部门信息
- /// 加载对应角色部门列表树
- /// </summary>
- /// <param name="roleId"></param>
- /// <returns></returns>
- [HttpGet("roleDeptTreeselect/{roleId}")]
- public IActionResult RoleMenuTreeselect(int roleId)
- {
- var depts = DeptService.GetSysDepts(new SysDeptQueryDto());
- var checkedKeys = DeptService.SelectRoleDepts(roleId);
- return SUCCESS(new
- {
- checkedKeys,
- depts = DeptService.BuildDeptTreeSelect(depts),
- });
- }
- /// <summary>
- /// 根据部门编号获取详细信息
- /// </summary>
- /// <returns></returns>
- [HttpGet("{deptId}")]
- [ActionPermissionFilter(Permission = "system:dept:query")]
- public IActionResult GetInfo(long deptId)
- {
- var info = DeptService.GetFirst(f => f.deptId == deptId);
- return SUCCESS(info);
- }
- /// <summary>
- /// 新增部门
- /// </summary>
- /// <param name="dept"></param>
- /// <returns></returns>
- [HttpPost("/v1/tel/sysServer/dept/add")]
- public IActionResult Add([FromBody] SysDept dept)
- {
- if (UserConstants.NOT_UNIQUE.Equals(DeptService.CheckDeptNameUnique(dept)))
- {
- return ToResponse(ResultCode.CUSTOM_ERROR, $"新增部门{dept.name}失败,部门名称已存在");
- }
- TokenModel loginUser = JwtUtil.GetLoginUser(HttpContext);
- dept.CreateBy = loginUser.username;
- dept.UpdateBy = loginUser.username;
- dept.DelFlag = "0";
- return SUCCESS(DeptService.InsertDept(dept));
- }
- /// <summary>
- /// 修改部门
- /// </summary>
- /// <param name="dept"></param>
- /// <returns></returns>
- [HttpPut("/v1/tel/sysServer/dept/update")]
- public IActionResult Update([FromBody] SysDept dept)
- {
- if (UserConstants.NOT_UNIQUE.Equals(DeptService.CheckDeptNameUnique(dept)))
- {
- return ToResponse(ResultCode.CUSTOM_ERROR, $"修改部门{dept.name}失败,部门名称已存在");
- }
- else if (dept.parentId.Equals(dept.deptId))
- {
- return ToResponse(ResultCode.CUSTOM_ERROR, $"修改部门{dept.name}失败,上级部门不能是自己");
- }
- TokenModel loginUser = JwtUtil.GetLoginUser(HttpContext);
- dept.UpdateBy = loginUser.username;
- return SUCCESS(DeptService.UpdateDept(dept));
- }
- /// <summary>
- /// 删除部门
- /// </summary>
- /// <returns></returns>
- [HttpDelete("/v1/tel/sysServer/dept/removeById/{id}")]
- public IActionResult Remove(int id)
- {
- if (DeptService.Queryable().Count(it => it.parentId == id && it.DelFlag == "0") > 0)
- {
- return ToResponse(ResultCode.CUSTOM_ERROR, $"存在下级部门,不允许删除");
- }
- if (UserService.Queryable().Count(it => it.deptId == id && it.DelFlag == "0") > 0)
- {
- return ToResponse(ResultCode.CUSTOM_ERROR, $"部门存在用户,不允许删除");
- }
- return SUCCESS(DeptService.Delete(id));
- }
- }
- }
|