UserController.java 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. package com.xjrsoft.module.organization.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.dev33.satoken.secure.BCrypt;
  4. import cn.dev33.satoken.session.SaSession;
  5. import cn.dev33.satoken.stp.StpUtil;
  6. import cn.hutool.core.bean.BeanUtil;
  7. import cn.hutool.core.util.ObjectUtil;
  8. import cn.hutool.core.util.StrUtil;
  9. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  10. import com.baomidou.mybatisplus.core.metadata.IPage;
  11. import com.baomidou.mybatisplus.core.toolkit.StringPool;
  12. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  13. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  14. import com.fasterxml.jackson.core.type.TypeReference;
  15. import com.github.yulichang.toolkit.MPJWrappers;
  16. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  17. import com.xjrsoft.common.constant.GlobalConstant;
  18. import com.xjrsoft.common.enums.DeleteMark;
  19. import com.xjrsoft.common.enums.EnabledMark;
  20. import com.xjrsoft.common.enums.GenderDictionaryEnum;
  21. import com.xjrsoft.common.enums.RoleEnum;
  22. import com.xjrsoft.common.enums.WorkflowIsRecycleType;
  23. import com.xjrsoft.common.exception.MyException;
  24. import com.xjrsoft.common.model.result.R;
  25. import com.xjrsoft.common.model.result.RT;
  26. import com.xjrsoft.common.page.ConventPage;
  27. import com.xjrsoft.common.page.PageOutput;
  28. import com.xjrsoft.common.sms.SmsCtcc;
  29. import com.xjrsoft.common.utils.RedisUtil;
  30. import com.xjrsoft.common.utils.TreeUtil;
  31. import com.xjrsoft.common.utils.VoToColumnUtil;
  32. import com.xjrsoft.module.base.entity.BaseClass;
  33. import com.xjrsoft.module.base.entity.BaseGrade;
  34. import com.xjrsoft.module.base.entity.WhitelistManagement;
  35. import com.xjrsoft.module.base.service.IBaseClassService;
  36. import com.xjrsoft.module.base.service.IBaseGradeService;
  37. import com.xjrsoft.module.base.service.IWhitelistManagementService;
  38. import com.xjrsoft.module.hikvision.util.DataUtil;
  39. import com.xjrsoft.module.organization.dto.AddUserDto;
  40. import com.xjrsoft.module.organization.dto.BindOpenidDto;
  41. import com.xjrsoft.module.organization.dto.LoginResetPasswordDto;
  42. import com.xjrsoft.module.organization.dto.PersonPageDto;
  43. import com.xjrsoft.module.organization.dto.RegisterDto;
  44. import com.xjrsoft.module.organization.dto.ResetPasswordDto;
  45. import com.xjrsoft.module.organization.dto.UpdateInfoDto;
  46. import com.xjrsoft.module.organization.dto.UpdatePasswordDto;
  47. import com.xjrsoft.module.organization.dto.UpdateUserDto;
  48. import com.xjrsoft.module.organization.dto.UploadSignDto;
  49. import com.xjrsoft.module.organization.dto.UserChangeStatusDto;
  50. import com.xjrsoft.module.organization.dto.UserPageDto;
  51. import com.xjrsoft.module.organization.dto.UserStudentAddDto;
  52. import com.xjrsoft.module.organization.dto.UserStudentBindDto;
  53. import com.xjrsoft.module.organization.dto.UserStudentDeleteDto;
  54. import com.xjrsoft.module.organization.entity.Department;
  55. import com.xjrsoft.module.organization.entity.Post;
  56. import com.xjrsoft.module.organization.entity.Role;
  57. import com.xjrsoft.module.organization.entity.User;
  58. import com.xjrsoft.module.organization.entity.UserDeptRelation;
  59. import com.xjrsoft.module.organization.entity.UserPostRelation;
  60. import com.xjrsoft.module.organization.entity.UserRoleRelation;
  61. import com.xjrsoft.module.organization.entity.UserStudent;
  62. import com.xjrsoft.module.organization.service.IDepartmentService;
  63. import com.xjrsoft.module.organization.service.IPostService;
  64. import com.xjrsoft.module.organization.service.IRoleService;
  65. import com.xjrsoft.module.organization.service.IUserDeptRelationService;
  66. import com.xjrsoft.module.organization.service.IUserPostRelationService;
  67. import com.xjrsoft.module.organization.service.IUserRoleRelationService;
  68. import com.xjrsoft.module.organization.service.IUserService;
  69. import com.xjrsoft.module.organization.service.IUserStudentService;
  70. import com.xjrsoft.module.organization.utils.OrganizationUtil;
  71. import com.xjrsoft.module.organization.vo.PendingCountDto;
  72. import com.xjrsoft.module.organization.vo.PersonPageVo;
  73. import com.xjrsoft.module.organization.vo.ResetUserPageVo;
  74. import com.xjrsoft.module.organization.vo.ResetUserRoleVo;
  75. import com.xjrsoft.module.organization.vo.UserDeptVo;
  76. import com.xjrsoft.module.organization.vo.UserDetailVo;
  77. import com.xjrsoft.module.organization.vo.UserInfoVo;
  78. import com.xjrsoft.module.organization.vo.UserListVo;
  79. import com.xjrsoft.module.organization.vo.UserPageVo;
  80. import com.xjrsoft.module.organization.vo.UserPostVo;
  81. import com.xjrsoft.module.organization.vo.UserRoleVo;
  82. import com.xjrsoft.module.organization.vo.UserStudentInfoVo;
  83. import com.xjrsoft.module.organization.vo.UserStudentVo;
  84. import com.xjrsoft.module.organization.vo.UserVo;
  85. import com.xjrsoft.module.oss.factory.OssFactory;
  86. import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
  87. import com.xjrsoft.module.student.entity.BaseStudentUser;
  88. import com.xjrsoft.module.student.service.IBaseStudentSchoolRollService;
  89. import com.xjrsoft.module.system.entity.DictionaryDetail;
  90. import com.xjrsoft.module.system.entity.File;
  91. import com.xjrsoft.module.system.service.IFileService;
  92. import com.xjrsoft.module.teacher.entity.BaseTeacher;
  93. import com.xjrsoft.module.teacher.entity.XjrUser;
  94. import com.xjrsoft.module.workflow.constant.WorkflowConstant;
  95. import com.xjrsoft.module.workflow.service.IWorkflowExecuteService;
  96. import io.swagger.annotations.Api;
  97. import io.swagger.annotations.ApiOperation;
  98. import lombok.AllArgsConstructor;
  99. import org.camunda.bpm.engine.HistoryService;
  100. import org.camunda.bpm.engine.history.HistoricProcessInstance;
  101. import org.camunda.bpm.engine.history.HistoricProcessInstanceQuery;
  102. import org.springframework.web.bind.annotation.DeleteMapping;
  103. import org.springframework.web.bind.annotation.GetMapping;
  104. import org.springframework.web.bind.annotation.PostMapping;
  105. import org.springframework.web.bind.annotation.PutMapping;
  106. import org.springframework.web.bind.annotation.RequestBody;
  107. import org.springframework.web.bind.annotation.RequestMapping;
  108. import org.springframework.web.bind.annotation.RequestParam;
  109. import org.springframework.web.bind.annotation.RestController;
  110. import org.springframework.web.multipart.MultipartFile;
  111. import javax.validation.Valid;
  112. import java.util.ArrayList;
  113. import java.util.List;
  114. import java.util.Objects;
  115. import java.util.concurrent.CompletableFuture;
  116. import java.util.stream.Collectors;
  117. /**
  118. * <p>
  119. * 用户 前端控制器
  120. * </p>
  121. *
  122. * @author tzx
  123. * @since 2022-03-02
  124. */
  125. @RestController
  126. @RequestMapping(GlobalConstant.ORGANIZATION_MODULE_PREFIX + "/user")
  127. @Api(value = GlobalConstant.ORGANIZATION_MODULE_PREFIX + "/user", tags = "用户")
  128. @AllArgsConstructor
  129. public class UserController {
  130. private final IUserService userService;
  131. private final IDepartmentService departmentService;
  132. private final IPostService postService;
  133. private final IRoleService roleService;
  134. private final IUserRoleRelationService userRoleRelationService;
  135. private final IUserDeptRelationService userDeptRelationService;
  136. private final IUserPostRelationService userPostRelationService;
  137. private final RedisUtil redisUtil;
  138. private final IFileService fileService;
  139. private final SmsCtcc smsCtcc;
  140. private final IBaseGradeService baseGradeService;
  141. private final IUserStudentService userStudentService;
  142. private final IBaseClassService baseClassService;
  143. private final IWorkflowExecuteService workflowExecuteService;
  144. private final HistoryService historyService;
  145. private final IBaseStudentSchoolRollService baseStudentSchoolRollService;
  146. private final IWhitelistManagementService whitelistManagementService;
  147. @GetMapping(value = "/list")
  148. @ApiOperation(value = "用户列表(不分页)")
  149. public R list(String keyword) {
  150. List<User> list = userService.list(Wrappers.lambdaQuery(User.class)
  151. .like(StrUtil.isNotBlank(keyword), User::getUserName, keyword)
  152. .like(StrUtil.isNotBlank(keyword), User::getCode, keyword)
  153. .like(StrUtil.isNotBlank(keyword), User::getName, keyword)
  154. .like(StrUtil.isNotBlank(keyword), User::getMobile, keyword)
  155. .select(User.class, x -> VoToColumnUtil.fieldsToColumns(UserListVo.class).contains(x.getProperty())));
  156. List<UserListVo> userListVos = BeanUtil.copyToList(list, UserListVo.class);
  157. return R.ok(userListVos);
  158. }
  159. @GetMapping(value = "/page")
  160. @ApiOperation(value = "用户列表(分页)")
  161. public R page(UserPageDto dto) {
  162. List<Long> deptIds = new ArrayList<>();
  163. if (ObjectUtil.isNotNull(dto.getDepartmentId())) {
  164. List<Department> list = redisUtil.get(GlobalConstant.DEP_CACHE_KEY, new TypeReference<List<Department>>() {
  165. });
  166. //当前部门的层级
  167. String hierarchy = list.stream().filter(x -> x.getId().equals(dto.getDepartmentId())).findFirst().orElse(new Department()).getHierarchy();
  168. if (StrUtil.isNotBlank(hierarchy)) {
  169. //层级里面包含当前部门层级的就是它的子集,如1-1,下面包含了1-1、1-1-2这种
  170. deptIds = list.stream().filter(x -> StrUtil.isNotBlank(x.getHierarchy()) && x.getHierarchy().contains(hierarchy)).map(Department::getId).collect(Collectors.toList());
  171. } else {
  172. //如果不存在层级就查询自己的数据
  173. deptIds.add(dto.getDepartmentId());
  174. }
  175. }
  176. //因为多表关联 会有多个表都使用了id字段, 所以必须专门指定主表的Id
  177. if (ObjectUtil.isNotNull(dto.getDepartmentId())) {//不为空联合查询
  178. MPJLambdaWrapper<User> queryUser = new MPJLambdaWrapper<>();
  179. queryUser
  180. .disableSubLogicDel()
  181. .distinct()
  182. .like(StrUtil.isNotBlank(dto.getKeyword()), User::getName, dto.getKeyword())
  183. .or(StrUtil.isNotBlank(dto.getKeyword()), x -> x.like(StrUtil.isNotBlank(dto.getKeyword()), User::getCode, dto.getKeyword()))
  184. .in(ObjectUtil.isNotNull(dto.getDepartmentId()), UserDeptRelation::getDeptId, deptIds)
  185. .like(StrUtil.isNotBlank(dto.getUserName()), User::getUserName, dto.getUserName())
  186. .like(StrUtil.isNotBlank(dto.getCode()), User::getCode, dto.getCode())
  187. .like(StrUtil.isNotBlank(dto.getName()), User::getName, dto.getName())
  188. .like(StrUtil.isNotBlank(dto.getMobile()), User::getMobile, dto.getMobile())
  189. .eq((ObjectUtil.isNotNull(dto.getTreeType()) && dto.getTreeType() == 1), Role::getId, dto.getTreeId())
  190. .eq((ObjectUtil.isNotNull(dto.getTreeType()) && dto.getTreeType() == 2), UserDeptRelation::getDeptId, dto.getTreeId())
  191. .eq((ObjectUtil.isNotNull(dto.getTreeType()) && dto.getTreeType() == 3), BaseStudentSchoolRoll::getGradeId, dto.getTreeId())
  192. .eq((ObjectUtil.isNotNull(dto.getTreeType()) && dto.getTreeType() == 4), BaseStudentSchoolRoll::getClassId, dto.getTreeId())
  193. .eq(ObjectUtil.isNotNull(dto.getUserType()), Role::getId, dto.getUserType())
  194. .eq(ObjectUtil.isNotNull(dto.getEmployType()), BaseTeacher::getEmployType, dto.getEmployType())
  195. .eq(ObjectUtil.isNotNull(dto.getEmployWay()), BaseTeacher::getEmployWay, dto.getEmployWay())
  196. .eq(ObjectUtil.isNotNull(dto.getClassId()), BaseStudentSchoolRoll::getClassId, dto.getClassId())
  197. .orderByDesc(User::getId)
  198. .select(User::getId)
  199. .select("d1.name", UserPageVo::getEmployWay)
  200. .select("d2.name", UserPageVo::getEmployType)
  201. .selectAs(BaseStudentSchoolRoll::getClassId, UserPageVo::getClassId)
  202. .select(User.class, x -> VoToColumnUtil.fieldsToColumns(UserPageVo.class).contains(x.getProperty()))
  203. .leftJoin(UserDeptRelation.class, UserDeptRelation::getUserId, User::getId)
  204. .leftJoin(UserRoleRelation.class, UserRoleRelation::getUserId, User::getId)
  205. .leftJoin(BaseTeacher.class, BaseTeacher::getUserId, User::getId)
  206. .leftJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, User::getId)
  207. .leftJoin(DictionaryDetail.class, "d1", DictionaryDetail::getCode, BaseTeacher::getEmployWay)
  208. .leftJoin(DictionaryDetail.class, "d2", DictionaryDetail::getCode, BaseTeacher::getEmployType)
  209. .leftJoin(Role.class, Role::getId, UserRoleRelation::getRoleId);
  210. IPage<UserPageVo> page = userService.selectJoinListPage(ConventPage.getPage(dto), UserPageVo.class, queryUser);
  211. for (UserPageVo record : page.getRecords()) {
  212. record.setGenderCn(GenderDictionaryEnum.getValue(record.getGender()));
  213. }
  214. PageOutput<UserPageVo> pageOutput = ConventPage.getPageOutput(page, UserPageVo.class);
  215. return R.ok(pageOutput);
  216. } else {
  217. // LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
  218. // queryWrapper.like(StrUtil.isNotBlank(dto.getKeyword()), User::getName, dto.getKeyword())
  219. // .or(StrUtil.isNotBlank(dto.getKeyword()), x -> x.like(StrUtil.isNotBlank(dto.getKeyword()), User::getCode, dto.getKeyword()))
  220. // .like(StrUtil.isNotBlank(dto.getUserName()), User::getUserName, dto.getUserName())
  221. // .like(StrUtil.isNotBlank(dto.getCode()), User::getCode, dto.getCode())
  222. // .like(StrUtil.isNotBlank(dto.getName()), User::getName, dto.getName())
  223. // .like(StrUtil.isNotBlank(dto.getMobile()), User::getMobile, dto.getMobile())
  224. // .orderByDesc(User::getCreateDate)
  225. // .select(User.class, x -> VoToColumnUtil.fieldsToColumns(UserPageVo.class).contains(x.getProperty()));
  226. //
  227. // IPage<User> page = userService.page(ConventPage.getPage(dto),queryWrapper);
  228. MPJLambdaWrapper<User> queryUser = new MPJLambdaWrapper<>();
  229. queryUser
  230. .disableSubLogicDel()
  231. .distinct()
  232. .like(StrUtil.isNotBlank(dto.getKeyword()), User::getName, dto.getKeyword())
  233. .or(StrUtil.isNotBlank(dto.getKeyword()), x -> x.like(StrUtil.isNotBlank(dto.getKeyword()), User::getCode, dto.getKeyword()))
  234. .like(StrUtil.isNotBlank(dto.getUserName()), User::getUserName, dto.getUserName())
  235. .like(StrUtil.isNotBlank(dto.getCode()), User::getCode, dto.getCode())
  236. .like(StrUtil.isNotBlank(dto.getName()), User::getName, dto.getName())
  237. .like(StrUtil.isNotBlank(dto.getMobile()), User::getMobile, dto.getMobile())
  238. .eq(ObjectUtil.isNotNull(dto.getUserType()), Role::getId, dto.getUserType())
  239. .eq((ObjectUtil.isNotNull(dto.getTreeType()) && dto.getTreeType() == 1), Role::getId, dto.getTreeId())
  240. .eq((ObjectUtil.isNotNull(dto.getTreeType()) && dto.getTreeType() == 2), UserDeptRelation::getDeptId, dto.getTreeId())
  241. .eq((ObjectUtil.isNotNull(dto.getTreeType()) && dto.getTreeType() == 3), BaseStudentSchoolRoll::getGradeId, dto.getTreeId())
  242. .eq((ObjectUtil.isNotNull(dto.getTreeType()) && dto.getTreeType() == 4), BaseStudentSchoolRoll::getClassId, dto.getTreeId())
  243. .eq(ObjectUtil.isNotNull(dto.getEmployType()), BaseTeacher::getEmployType, dto.getEmployType())
  244. .eq(ObjectUtil.isNotNull(dto.getEmployWay()), BaseTeacher::getEmployWay, dto.getEmployWay())
  245. .eq(ObjectUtil.isNotNull(dto.getClassId()), BaseStudentSchoolRoll::getClassId, dto.getClassId())
  246. .orderByDesc(User::getId)
  247. .select(User::getId)
  248. .select("d1.name", UserPageVo::getEmployWay)
  249. .select("d2.name", UserPageVo::getEmployType)
  250. .selectAs(BaseStudentSchoolRoll::getClassId, UserPageVo::getClassId)
  251. .select(User.class, x -> VoToColumnUtil.fieldsToColumns(UserPageVo.class).contains(x.getProperty()))
  252. .leftJoin(UserRoleRelation.class, UserRoleRelation::getUserId, User::getId)
  253. .leftJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, User::getId)
  254. .leftJoin(UserDeptRelation.class, UserDeptRelation::getUserId, User::getId)
  255. .leftJoin(BaseTeacher.class, BaseTeacher::getUserId, User::getId)
  256. .leftJoin(DictionaryDetail.class, "d1", DictionaryDetail::getCode, BaseTeacher::getEmployWay)
  257. .leftJoin(DictionaryDetail.class, "d2", DictionaryDetail::getCode, BaseTeacher::getEmployType)
  258. .leftJoin(Role.class, Role::getId, UserRoleRelation::getRoleId);
  259. IPage<UserPageVo> page = userService.selectJoinListPage(ConventPage.getPage(dto), UserPageVo.class,queryUser);
  260. for (UserPageVo record : page.getRecords()) {
  261. record.setGenderCn(GenderDictionaryEnum.getValue(record.getGender()));
  262. }
  263. PageOutput<UserPageVo> pageOutput = ConventPage.getPageOutput(page, UserPageVo.class);
  264. return R.ok(pageOutput);
  265. }
  266. }
  267. @GetMapping(value = "/person-page")
  268. @ApiOperation(value = "人员选择组件(分页)")
  269. public R personPage(PersonPageDto dto) {
  270. Page<PersonPageVo> voPage = userService.personPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
  271. PageOutput<PersonPageVo> pageOutput = ConventPage.getPageOutput(voPage, PersonPageVo.class);
  272. return R.ok(pageOutput);
  273. }
  274. @GetMapping(value = "/info")
  275. @ApiOperation(value = "根据id查询用户信息")
  276. public R info(@RequestParam Long id) {
  277. User user = userService.getById(id);
  278. if (user == null) {
  279. R.error("找不到此用户!");
  280. }
  281. UserVo userVo = BeanUtil.toBean(user, UserVo.class);
  282. userVo.setGenderCn(GenderDictionaryEnum.getValue(userVo.getGender()));
  283. List<Long> deptIds = userDeptRelationService.list(Wrappers.lambdaQuery(UserDeptRelation.class)
  284. .eq(UserDeptRelation::getUserId, user.getId()))
  285. .stream().map(UserDeptRelation::getDeptId).collect(Collectors.toList());
  286. String allDeptIdStr = StrUtil.join(StringPool.COMMA, deptIds);
  287. userVo.setDepartmentIds(allDeptIdStr);
  288. List<Long> roleIds = userRoleRelationService.list(
  289. Wrappers.lambdaQuery(UserRoleRelation.class)
  290. .eq(UserRoleRelation::getUserId, user.getId())
  291. ).stream().map(UserRoleRelation::getRoleId).collect(Collectors.toList());
  292. userVo.setRoleIds(roleIds);
  293. return R.ok(userVo);
  294. }
  295. @GetMapping(value = "/detail")
  296. @ApiOperation(value = "根据id查询用户信息")
  297. public RT<UserDetailVo> detail(@RequestParam Long id) {
  298. User user = userService.getById(id);
  299. if (user == null) {
  300. R.error("找不到此用户!");
  301. }
  302. UserDetailVo userVo = BeanUtil.toBean(user, UserDetailVo.class);
  303. List<Long> deptIds = userDeptRelationService.list(Wrappers.lambdaQuery(UserDeptRelation.class)
  304. .eq(UserDeptRelation::getUserId, user.getId()))
  305. .stream().map(UserDeptRelation::getDeptId).collect(Collectors.toList());
  306. String allDeptIdStr = StrUtil.join(StringPool.COMMA, deptIds);
  307. userVo.setDepartmentIds(allDeptIdStr);
  308. return RT.ok(userVo);
  309. }
  310. @PostMapping
  311. @ApiOperation(value = "新增用户")
  312. public R add(@Valid @RequestBody AddUserDto dto) {
  313. if (!OrganizationUtil.validatePassword(dto.getPassword())) {
  314. return R.error("密码必须包含大写字母、小写字母、数字和特殊字符,长度8~16位");
  315. }
  316. return R.ok(userService.add(dto));
  317. }
  318. @PutMapping
  319. @ApiOperation(value = "修改用户 不能修改用户名")
  320. public R update(@Valid @RequestBody UpdateUserDto dto) {
  321. return R.ok(userService.update(dto));
  322. }
  323. @GetMapping(value = "/current/info")
  324. @ApiOperation(value = "当前登录用户信息")
  325. public R info() {
  326. SaSession tokenSession = StpUtil.getTokenSession();
  327. User user = tokenSession.get(GlobalConstant.LOGIN_USER_INFO_KEY, new User());
  328. List<Long> roleIds = userRoleRelationService.list(Wrappers.lambdaQuery(UserRoleRelation.class)
  329. .eq(UserRoleRelation::getUserId, user.getId()))
  330. .stream().map(UserRoleRelation::getRoleId).collect(Collectors.toList());
  331. List<Long> deptIds = userDeptRelationService.list(Wrappers.lambdaQuery(UserDeptRelation.class)
  332. .eq(UserDeptRelation::getUserId, user.getId()))
  333. .stream().map(UserDeptRelation::getDeptId).collect(Collectors.toList());
  334. List<Long> postIds = userPostRelationService.list(Wrappers.lambdaQuery(UserPostRelation.class)
  335. .eq(UserPostRelation::getUserId, user.getId()))
  336. .stream().map(UserPostRelation::getPostId).collect(Collectors.toList());
  337. UserInfoVo vo = BeanUtil.toBean(user, UserInfoVo.class);
  338. vo.setGenderCn(GenderDictionaryEnum.getValue(vo.getGender()));
  339. if (roleIds.size() > 0) {
  340. List<Role> list = roleService.list(Wrappers.lambdaQuery(Role.class).in(Role::getId, roleIds));
  341. List<UserRoleVo> userRoleVoList = BeanUtil.copyToList(list, UserRoleVo.class);
  342. vo.setRoles(userRoleVoList);
  343. }
  344. if (deptIds.size() > 0) {
  345. List<Department> list = departmentService.list(Wrappers.lambdaQuery(Department.class).in(Department::getId, deptIds));
  346. List<UserDeptVo> userDeptVoList = BeanUtil.copyToList(list, UserDeptVo.class);
  347. vo.setDepartments(userDeptVoList);
  348. }
  349. if (postIds.size() > 0) {
  350. List<Post> list = postService.list(Wrappers.lambdaQuery(Post.class).in(Post::getId, postIds));
  351. List<UserPostVo> userPostVoList = BeanUtil.copyToList(list, UserPostVo.class);
  352. vo.setPosts(userPostVoList);
  353. }
  354. // 家长
  355. List<UserStudentVo> list = baseClassService.getStudents(user.getId());
  356. if (list != null) {
  357. vo.setStudents(list);
  358. }
  359. // 学生
  360. UserStudentVo userStudentVo = baseClassService.getClassInfo(user.getId());
  361. if (userStudentVo != null) {
  362. vo.setClassId(userStudentVo.getClassId());
  363. vo.setClassName(userStudentVo.getClassName());
  364. vo.setTeacherId(userStudentVo.getTeacherId());
  365. vo.setTeacherName(userStudentVo.getTeacherName());
  366. vo.setTeacherMobile(userStudentVo.getTeacherMobile());
  367. }
  368. List<File> fileList = fileService.list(Wrappers.lambdaQuery(File.class).eq(File::getFolderId, user.getSignFolderId()));
  369. if(!fileList.isEmpty()){
  370. vo.setSignUrl(fileList.get(0).getFileUrl());
  371. }
  372. return R.ok(vo);
  373. }
  374. @GetMapping(value = "/pending/count")
  375. @ApiOperation(value = "当前待办数量统计")
  376. public RT<PendingCountDto> pendingCount() {
  377. PendingCountDto pendingCountDto = new PendingCountDto();
  378. pendingCountDto.setWfPendingCount(workflowExecuteService.pendingCount());
  379. HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery()
  380. .variableValueEquals(WorkflowConstant.PROCESS_START_USER_ID_KEY, StpUtil.getLoginIdAsLong())
  381. .variableValueEquals(WorkflowConstant.PROCESS_ISRECYCLE_FLAG_KEY, WorkflowIsRecycleType.NO.getCode());
  382. List<HistoricProcessInstance> historicProcessInstances = historicProcessInstanceQuery.orderByProcessInstanceStartTime().desc().list();
  383. //获取到所有流程id
  384. List<String> processIds = historicProcessInstances.stream().map(HistoricProcessInstance::getId).collect(Collectors.toList());
  385. int myApplicationCount = 0;
  386. for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
  387. Long countByProcessId = workflowExecuteService.getCountByProcessId(historicProcessInstance.getId());
  388. if(countByProcessId == 0L){
  389. continue;
  390. }
  391. if (!ObjectUtil.isNotNull(historicProcessInstance.getEndTime())) {
  392. myApplicationCount ++;
  393. }
  394. }
  395. pendingCountDto.setMyApplicationCount(myApplicationCount);
  396. return RT.ok(pendingCountDto);
  397. }
  398. @GetMapping(value = "/reset-user-page")
  399. @ApiOperation(value = "移动端用户列表")
  400. public RT<PageOutput<ResetUserPageVo>> resetUserPage(UserPageDto dto) {
  401. PageOutput<ResetUserPageVo> userPage = userService.getResetUserPage(dto);
  402. return RT.ok(userPage);
  403. }
  404. @GetMapping(value = "/reset-page-role-list")
  405. @ApiOperation(value = "移动端用户列表分类")
  406. public RT<List<ResetUserRoleVo>> resetUserTree() {
  407. List<ResetUserRoleVo> roleList = new ArrayList<>();
  408. roleList.add(new ResetUserRoleVo(){{
  409. setId(null);
  410. setName("全部");
  411. }});
  412. roleList.add(new ResetUserRoleVo(){{
  413. setId(2L);
  414. setName("教师");
  415. }});
  416. roleList.add(new ResetUserRoleVo(){{
  417. setId(3L);
  418. setName("学生");
  419. }});
  420. roleList.add(new ResetUserRoleVo(){{
  421. setId(4L);
  422. setName("家长");
  423. }});
  424. return RT.ok(roleList);
  425. }
  426. @GetMapping(value = "/pc-role-tree")
  427. @ApiOperation(value = "pc端用户列表分类")
  428. public RT<List<ResetUserRoleVo>> pcRoleTree() {
  429. List<Department> departmentList = departmentService.list(
  430. new QueryWrapper<Department>().lambda()
  431. .eq(Department::getDeleteMark, DeleteMark.NODELETE.getCode())
  432. );
  433. List<ResetUserRoleVo> voList = new ArrayList<>();
  434. for (Department department : departmentList) {
  435. ResetUserRoleVo roleVo = BeanUtil.toBean(department, ResetUserRoleVo.class);
  436. roleVo.setType(2);
  437. voList.add(roleVo);
  438. }
  439. List<ResetUserRoleVo> treeVoList = TreeUtil.build(voList);
  440. List<ResetUserRoleVo> roleList = new ArrayList<>();
  441. ResetUserRoleVo roleVo = new ResetUserRoleVo() {{
  442. setId(2L);
  443. setType(1);
  444. setName("教师");
  445. setChildren(treeVoList);
  446. }};
  447. roleList.add(roleVo);
  448. List<ResetUserRoleVo> gradeClassList = new ArrayList<>();
  449. baseClassService.list(
  450. new QueryWrapper<BaseClass>().lambda().eq(BaseClass::getDeleteMark, DeleteMark.NODELETE.getCode())
  451. ).forEach(e->{
  452. ResetUserRoleVo gradeClass = new ResetUserRoleVo();
  453. gradeClass.setType(4);
  454. gradeClass.setName(e.getName());
  455. gradeClass.setId(e.getId());
  456. gradeClass.setParentId(e.getGradeId());
  457. gradeClassList.add(gradeClass);
  458. });
  459. baseGradeService.list(
  460. new QueryWrapper<BaseGrade>().lambda().eq(BaseGrade::getDeleteMark, DeleteMark.NODELETE.getCode())
  461. ).forEach(e->{
  462. ResetUserRoleVo gradeClass = new ResetUserRoleVo();
  463. gradeClass.setType(3);
  464. gradeClass.setName(e.getName());
  465. gradeClass.setId(e.getId());
  466. gradeClass.setParentId(3L);
  467. gradeClassList.add(gradeClass);
  468. });
  469. List<ResetUserRoleVo> gradeClassTreeVoList = TreeUtil.build(gradeClassList);
  470. roleList.add(new ResetUserRoleVo(){{
  471. setId(3L);
  472. setType(1);
  473. setName("学生");
  474. setChildren(gradeClassTreeVoList);
  475. }});
  476. roleList.add(new ResetUserRoleVo(){{
  477. setId(4L);
  478. setType(1);
  479. setName("家长");
  480. }});
  481. return RT.ok(roleList);
  482. }
  483. @PutMapping("/update/info")
  484. @ApiOperation(value = "登陆人修改自己得用户信息")
  485. public R updateInfo(@RequestBody @Valid UpdateInfoDto dto) {
  486. User updateUserInfo = BeanUtil.toBean(dto, User.class);
  487. updateUserInfo.setId(StpUtil.getLoginIdAsLong());
  488. CompletableFuture.runAsync(() -> {
  489. List<User> list = userService.list();
  490. redisUtil.set(GlobalConstant.USER_CACHE_KEY, list);
  491. });
  492. return R.ok(userService.updateById(updateUserInfo));
  493. }
  494. @PutMapping("/update/password")
  495. @ApiOperation(value = "当前登录用户修改本人密码")
  496. public RT<Boolean> updatePassword(@RequestBody @Valid UpdatePasswordDto dto) {
  497. if (!OrganizationUtil.validatePassword(dto.getNewPassword())) {
  498. return RT.error("密码必须包含大写字母、小写字母、数字和特殊字符,长度8~16位");
  499. }
  500. User user = userService.getById(StpUtil.getLoginIdAsLong());
  501. if (!BCrypt.checkpw(dto.getOldPassword(), user.getPassword())) {
  502. return RT.error("当前密码填写错误!");
  503. }
  504. if (!StrUtil.equals(dto.getNewPassword(), dto.getConfirmPassword())) {
  505. return RT.error("2次密码输入不一致!");
  506. }
  507. return RT.ok(userService.updatePassword(dto));
  508. }
  509. @PutMapping("/login/reset-password")
  510. @ApiOperation(value = "登录后修改密码")
  511. public RT<Boolean> loginResetPassword(@RequestBody @Valid LoginResetPasswordDto dto) {
  512. if (!OrganizationUtil.validatePassword(dto.getNewPassword())) {
  513. return RT.error("密码必须包含大写字母、小写字母、数字和特殊字符,长度8~16位");
  514. }
  515. if (!StrUtil.equals(dto.getNewPassword(), dto.getConfirmPassword())) {
  516. return RT.error("2次密码输入不一致!");
  517. }
  518. UpdatePasswordDto pd = BeanUtil.toBean(dto, UpdatePasswordDto.class);
  519. return RT.ok(userService.updatePassword(pd));
  520. }
  521. @PostMapping("/update/avatar")
  522. @ApiOperation(value = "当前登录用户修改头像")
  523. public R uploadAvatar(@RequestParam("file") MultipartFile file) throws Exception {
  524. if (file.isEmpty()) {
  525. throw new MyException("上传文件不能为空");
  526. }
  527. //上传文件
  528. String suffix = Objects.requireNonNull(file.getOriginalFilename()).substring(file.getOriginalFilename().lastIndexOf(StringPool.DOT));
  529. String url = Objects.requireNonNull(OssFactory.build()).uploadSuffix(file.getBytes(), suffix);
  530. User updateUser = new User();
  531. updateUser.setId(StpUtil.getLoginIdAsLong());
  532. updateUser.setAvatar(url);
  533. userService.updateById(updateUser);
  534. SaSession tokenSession = StpUtil.getTokenSession();
  535. User user = tokenSession.get(GlobalConstant.LOGIN_USER_INFO_KEY, new User());
  536. user.setAvatar(url);
  537. tokenSession.set(GlobalConstant.LOGIN_USER_INFO_KEY, user);
  538. return R.ok(url);
  539. }
  540. @DeleteMapping
  541. @ApiOperation(value = "删除用户(可批量)")
  542. public R delete(@RequestBody List<Long> ids) {
  543. if (ids.contains(GlobalConstant.SUPER_ADMIN_USER_ID)) {
  544. R.error("管理员账户不能删除!");
  545. }
  546. if (ids.contains(StpUtil.getLoginIdAsLong())) {
  547. R.error("当前登录账户不能删除!");
  548. }
  549. //删除海康的用户信息
  550. DataUtil dataUtil = new DataUtil();
  551. dataUtil.deletePerson(ids);
  552. //删除时需要同时删除用户部门关联表和用户角色关联表和用户岗位关系表数据。
  553. return R.ok(userService.deleteBatch(ids));
  554. }
  555. @PostMapping(value = "/change-status")
  556. @ApiOperation(value="修改状态")
  557. @SaCheckPermission("classroom:detail")
  558. public RT<Boolean> changeStatus(@Valid @RequestBody UserChangeStatusDto dto) throws Exception {
  559. List<User> list = userService.list(new QueryWrapper<User>().lambda()
  560. .in(User::getId, dto.getUserIds())
  561. );
  562. for (User user : list) {
  563. user.setEnabledMark(dto.getStatus());
  564. userService.updateById(user);
  565. }
  566. return RT.ok(true);
  567. }
  568. @GetMapping("/info/multi")
  569. @ApiOperation(value = "批量获取用户信息")
  570. public R usersInfo(@RequestParam String ids) {
  571. return R.ok(userService.getUsersInfo(ids));
  572. }
  573. @GetMapping("/enabled")
  574. @ApiOperation(value = "启用/禁用用户")
  575. public R enabled(@RequestParam Long id) {
  576. User user = userService.getOne(Wrappers.<User>query().lambda().select(User::getEnabledMark).eq(User::getId, id), false);
  577. if (user != null) {
  578. User updateUser = new User();
  579. updateUser.setId(id);
  580. updateUser.setEnabledMark(user.getEnabledMark() == EnabledMark.ENABLED.getCode() ? EnabledMark.DISABLED.getCode() : EnabledMark.ENABLED.getCode());
  581. return R.ok(userService.updateById(updateUser));
  582. }
  583. CompletableFuture.runAsync(() -> {
  584. List<User> list = userService.list();
  585. redisUtil.set(GlobalConstant.USER_CACHE_KEY, list);
  586. });
  587. return R.error("该用户不存在!");
  588. }
  589. @PutMapping("/reset-password")
  590. @ApiOperation(value = "重置密码")
  591. public RT<Boolean> resetPassword(@RequestBody ResetPasswordDto dto) {
  592. return RT.ok(userService.resetPassword(dto));
  593. }
  594. @PutMapping("/batch-reset-password")
  595. @ApiOperation(value = "批量重置密码")
  596. public RT<Boolean> batchResetPassword(@RequestBody List<Long> ids) {
  597. return RT.ok(userService.batchResetPassword(ids));
  598. }
  599. @PostMapping("/bind-unionid")
  600. @ApiOperation(value = "绑定微信 UnionId")
  601. public R bindUnionId(@RequestBody BindOpenidDto dto) {
  602. User user = userService.getOne(Wrappers.<User>query().lambda().select(User::getId, User::getOpenId, User::getUnionId).eq(User::getId, dto.getId()), false);
  603. if (user != null) {
  604. if (StrUtil.isNotBlank(user.getUnionId())) {
  605. return R.error("该用户已经绑定微信!");
  606. }
  607. long count = userService.count(Wrappers.<User>query().lambda().eq(User::getUnionId, dto.getOpenid()));
  608. if (count > 0) {
  609. return R.error("该用户已经绑定微信!");
  610. }
  611. User updateUser = new User();
  612. updateUser.setId(dto.getId());
  613. // updateUser.setOpenId(dto.getOpenid());
  614. updateUser.setUnionId(dto.getOpenid());
  615. return R.ok(userService.updateById(updateUser));
  616. } else {
  617. long count = userService.count(Wrappers.<User>query().lambda().eq(User::getOpenId, dto.getOpenid()));
  618. if (count > 0) {
  619. return R.error("该用户已经绑定微信!");
  620. }
  621. }
  622. return R.error("该用户不存在!");
  623. }
  624. @PostMapping("/bind-openid")
  625. @ApiOperation(value = "绑定微信 Openid")
  626. public R bindOpenid(@RequestBody BindOpenidDto dto) {
  627. return R.ok(userService.bindOpenid(dto));
  628. }
  629. @GetMapping("/unbind-openid")
  630. @ApiOperation(value = "取消绑定微信 UnionId")
  631. public R unbindOpenid(@RequestParam Long id) {
  632. return R.ok(userService.unbindOpenid(id));
  633. }
  634. @PostMapping("/register")
  635. @ApiOperation(value = "家长注册")
  636. public R register(@Valid @RequestBody RegisterDto dto) {
  637. // 验证验证码
  638. if (!smsCtcc.captchaVerify(dto.getMobile(), dto.getSmsCode())) {
  639. return R.error("验证码不正确!");
  640. }
  641. // 赋值家长角色
  642. List<Long> roleIds = new ArrayList<>();
  643. roleIds.add(RoleEnum.PARENT.getCode());
  644. dto.setRoleIds(roleIds);
  645. return R.ok(userService.add(dto));
  646. }
  647. @PostMapping("/bind-student")
  648. @ApiOperation(value = "绑定学生")
  649. public R bindStudent(@Valid @RequestBody UserStudentBindDto dto) {
  650. User user = userService.getOne(Wrappers.<User>query().lambda()
  651. .eq(User::getName, dto.getName())
  652. .eq(User::getCredentialNumber, dto.getIdCard())
  653. .eq(User::getMobile, dto.getMobile())
  654. );
  655. UserStudentAddDto userStudentAddDto = new UserStudentAddDto();
  656. if (user == null) {
  657. return R.error("学生不存在!");
  658. }
  659. userStudentAddDto.setUserId(dto.getUserId());
  660. userStudentAddDto.setStudentId(user.getId());
  661. return R.ok(userStudentService.add(userStudentAddDto));
  662. }
  663. @GetMapping(value = "/validate-student")
  664. public RT<UserStudentInfoVo> getValidateStudent(UserStudentBindDto dto) {
  665. UserStudentInfoVo userStudentInfoVo = baseStudentSchoolRollService.selectJoinOne(UserStudentInfoVo.class,
  666. MPJWrappers.<BaseStudentSchoolRoll>lambdaJoin()
  667. .innerJoin(User.class, User::getId, BaseStudentSchoolRoll::getUserId)
  668. .leftJoin(BaseClass.class,BaseClass::getId,BaseStudentSchoolRoll::getClassId)
  669. .eq(User::getName, dto.getName())
  670. .eq(User::getCredentialNumber, dto.getIdCard())
  671. .select(User::getId, User::getName, User::getMobile, User::getCredentialNumber)
  672. .select(BaseClass::getTeacherId)
  673. );
  674. if (userStudentInfoVo == null) {
  675. return RT.error("学生不存在!");
  676. }
  677. if(!dto.getMobile().equals(userStudentInfoVo.getMobile())){
  678. return RT.error("该学生的手机号和当前输入的手机号不一致!");
  679. }
  680. List<WhitelistManagement> managementList = whitelistManagementService.list(
  681. new QueryWrapper<WhitelistManagement>().lambda()
  682. .eq(WhitelistManagement::getUserId, userStudentInfoVo.getId())
  683. );
  684. userStudentInfoVo.setWhitelistStatus(0);
  685. if(!managementList.isEmpty()){
  686. userStudentInfoVo.setWhitelistStatus(1);
  687. }
  688. return RT.ok(userStudentInfoVo);
  689. }
  690. @DeleteMapping("/unbind-student")
  691. @ApiOperation(value = "解绑学生")
  692. public R unBindStudent(@Valid @RequestBody UserStudentDeleteDto dto) {
  693. return R.ok(userStudentService.delete(dto));
  694. }
  695. @GetMapping("/student")
  696. @ApiOperation(value = "获取绑定学生")
  697. public R unBindStudent(@Valid @RequestParam Long id) {
  698. return R.ok(baseClassService.getStudents(id));
  699. }
  700. @GetMapping("/user-student")
  701. @ApiOperation(value = "获取绑定学生")
  702. public RT<List<UserStudentVo>> getBindStudent(@Valid @RequestParam Long id) {
  703. List<UserStudentVo> userStudentVoList = userStudentService.selectJoinList(UserStudentVo.class,
  704. MPJWrappers.<UserStudent>lambdaJoin()
  705. .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, UserStudent::getStudentId)
  706. .innerJoin(BaseStudentUser.class, BaseStudentUser::getId, UserStudent::getStudentId)
  707. .leftJoin(BaseClass.class, BaseClass::getId, BaseStudentSchoolRoll::getClassId)
  708. .leftJoin(XjrUser.class, XjrUser::getId, BaseClass::getTeacherId)
  709. .select(BaseStudentSchoolRoll::getClassId)
  710. .selectAs(XjrUser::getName, UserStudentVo::getTeacherName)
  711. .selectAs(XjrUser::getMobile, UserStudentVo::getTeacherMobile)
  712. .selectAs(XjrUser::getId, UserStudentVo::getTeacherId)
  713. .select(UserStudent::getStudentId,UserStudent::getStatus)
  714. .selectAs(BaseClass::getName, UserStudentVo::getClassName)
  715. .selectAs(BaseStudentUser::getName, UserStudentVo::getStudentName)
  716. .selectAs(BaseStudentUser::getAvatar, UserStudentVo::getAvatar)
  717. .eq(UserStudent::getUserId, id)
  718. );
  719. return RT.ok(userStudentVoList);
  720. }
  721. @PostMapping("/upload-sign")
  722. @ApiOperation(value = "上传签名")
  723. public RT<Boolean> uploadSign(@Valid @RequestBody UploadSignDto dto) {
  724. long loginIdAsLong = StpUtil.getLoginIdAsLong();
  725. User user = userService.getById(loginIdAsLong);
  726. user.setSignFolderId(dto.getFolderId());
  727. user.setSignPassword(BCrypt.hashpw(dto.getPassword(), BCrypt.gensalt()));
  728. return RT.ok(userService.updateById(user));
  729. }
  730. @GetMapping("/getSign")
  731. @ApiOperation(value = "获取登录者的签名url")
  732. public RT<String> getSign() {
  733. long loginIdAsLong = StpUtil.getLoginIdAsLong();
  734. User user = userService.getById(loginIdAsLong);
  735. if(user.getSignFolderId() == null){
  736. return RT.error("未上传签名");
  737. }
  738. List<File> list = fileService.list(Wrappers.lambdaQuery(File.class).eq(File::getFolderId, user.getSignFolderId()));
  739. if(list.isEmpty()){
  740. return RT.error("签名文件丢失");
  741. }
  742. return RT.ok(list.get(0).getFileUrl());
  743. }
  744. @GetMapping("/check-password")
  745. @ApiOperation(value = "验证登录者的密码")
  746. public RT<Boolean> checkSignpassword(@RequestParam String password) {
  747. long loginIdAsLong = StpUtil.getLoginIdAsLong();
  748. User user = userService.getById(loginIdAsLong);
  749. if (!BCrypt.checkpw(password, user.getPassword())) {
  750. return RT.error("密码填写错误!");
  751. }
  752. return RT.ok(true);
  753. }
  754. }