ExpandController.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * Neither the name of the dreamlu.net developer nor the names of its
  13. * contributors may be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. * Author: Chill 庄骞 (smallchill@163.com)
  16. */
  17. package org.springblade.modules.systemexpand.controller;
  18. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  19. import com.baomidou.mybatisplus.core.metadata.IPage;
  20. import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
  21. import io.swagger.annotations.*;
  22. import lombok.AllArgsConstructor;
  23. import org.apache.commons.lang3.StringUtils;
  24. import org.springblade.common.cache.DictCache;
  25. import org.springblade.common.enums.DictEnum;
  26. import org.springblade.core.boot.ctrl.BladeController;
  27. import org.springblade.core.cache.utils.CacheUtil;
  28. import org.springblade.core.launch.constant.AppConstant;
  29. import org.springblade.core.mp.support.Condition;
  30. import org.springblade.core.mp.support.Query;
  31. import org.springblade.core.secure.BladeUser;
  32. import org.springblade.core.secure.annotation.PreAuth;
  33. import org.springblade.core.secure.utils.AuthUtil;
  34. import org.springblade.core.tenant.annotation.NonDS;
  35. import org.springblade.core.tool.api.R;
  36. import org.springblade.core.tool.constant.BladeConstant;
  37. import org.springblade.core.tool.constant.RoleConstant;
  38. import org.springblade.core.tool.support.Kv;
  39. import org.springblade.core.tool.utils.Func;
  40. import org.springblade.core.tool.utils.StringPool;
  41. import org.springblade.modules.system.entity.Dept;
  42. import org.springblade.modules.system.entity.User;
  43. import org.springblade.modules.system.service.IDeptService;
  44. import org.springblade.modules.system.service.IUserService;
  45. import org.springblade.modules.system.vo.DeptVO;
  46. import org.springblade.modules.system.vo.UserVO;
  47. import org.springblade.modules.system.wrapper.DeptWrapper;
  48. import org.springblade.modules.system.wrapper.UserWrapper;
  49. import org.springframework.web.bind.annotation.*;
  50. import springfox.documentation.annotations.ApiIgnore;
  51. import javax.validation.Valid;
  52. import java.util.ArrayList;
  53. import java.util.List;
  54. import java.util.Map;
  55. import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
  56. /**
  57. * 控制器
  58. *
  59. * @author Chill
  60. */
  61. @NonDS
  62. @RestController
  63. @AllArgsConstructor
  64. @RequestMapping(AppConstant.APPLICATION_SYSTEM_NAME + "/expand")
  65. @Api(value = "扩展", tags = "扩展")
  66. public class ExpandController extends BladeController {
  67. private final IDeptService deptService;
  68. private final IUserService userService;
  69. /**
  70. * 获取当前用户的部门信息
  71. */
  72. @GetMapping("/dept/getCurrentDept")
  73. @ApiOperationSupport(order = 8)
  74. @ApiOperation(value = "获取当前用户的部门信息", notes = "")
  75. public R<DeptVO> getCurrentDept() {
  76. BladeUser user = AuthUtil.getUser();
  77. Dept currDept = deptService.getById(user.getDeptId());
  78. return R.data(DeptWrapper.build().entityVO(currDept));
  79. }
  80. /**
  81. * 详情
  82. */
  83. @GetMapping("/dept/getChildsDept")
  84. @ApiOperationSupport(order = 8)
  85. @ApiOperation(value = "详情", notes = "传入dept")
  86. public R getChildsDept() {
  87. Dept dept = deptService.getById(AuthUtil.getDeptId());
  88. List<Dept> list = new ArrayList<>();
  89. if (!dept.getOrgNo().startsWith("999") && !dept.getDeptCategory().equals(1)){
  90. list.add(dept);
  91. }
  92. List<Dept> deptChild = deptService.getDeptChild(dept.getId());
  93. list.addAll(deptChild);
  94. return R.data(list);
  95. }
  96. /**
  97. * 获取当前用户的部门信息
  98. */
  99. @GetMapping("/dept/getDeptByOrgNo")
  100. @ApiOperationSupport(order = 8)
  101. @ApiOperation(value = "获取当前用户的部门信息", notes = "")
  102. public R<Dept> getDeptByOrgNo(String orgNo) {
  103. Dept dept = deptService.getOne(new QueryWrapper<>(new Dept()).lambda().eq(Dept::getOrgNo, orgNo));
  104. return R.data(dept);
  105. }
  106. /**
  107. * 获取部门树形结构
  108. */
  109. @GetMapping("/dept/tree")
  110. @ApiOperationSupport(order = 4)
  111. @ApiOperation(value = "树形结构", notes = "树形结构")
  112. public R<List<DeptVO>> tree(BladeUser bladeUser) {
  113. String tenantId = "000000";
  114. List<DeptVO> tree = deptService.tree(Func.toStrWithEmpty(tenantId, bladeUser.getTenantId()));
  115. return R.data(tree);
  116. }
  117. /**
  118. * 自定义用户列表
  119. */
  120. @GetMapping("/user/page")
  121. @ApiImplicitParams({
  122. @ApiImplicitParam(name = "account", value = "账号名", paramType = "query", dataType = "string"),
  123. @ApiImplicitParam(name = "realName", value = "姓名", paramType = "query", dataType = "string")
  124. })
  125. @ApiOperationSupport(order = 3)
  126. @ApiOperation(value = "列表", notes = "传入account和realName")
  127. public R<IPage<UserVO>> page(@ApiIgnore User user, Query query, String hasOrgNo, BladeUser bladeUser) {
  128. // deptId = Long.valueOf(bladeUser.getDeptId());
  129. // IPage<User> pages = userService.selectUserPage(Condition.getPage(query), user, deptId, (bladeUser.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? StringPool.EMPTY : bladeUser.getTenantId()));
  130. IPage<User> pages = userService.selectMyUserPage(Condition.getPage(query), user, Long.valueOf(bladeUser.getDeptId()), hasOrgNo, (bladeUser.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? StringPool.EMPTY : bladeUser.getTenantId()));
  131. return R.data(UserWrapper.build().pageVO(pages));
  132. }
  133. }