UserController.java 122 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465
  1. package jnpf.permission.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.hutool.core.collection.CollectionUtil;
  4. import cn.hutool.core.util.ObjectUtil;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.google.common.collect.ImmutableList;
  7. import io.swagger.v3.oas.annotations.Operation;
  8. import io.swagger.v3.oas.annotations.Parameter;
  9. import io.swagger.v3.oas.annotations.Parameters;
  10. import io.swagger.v3.oas.annotations.tags.Tag;
  11. import jakarta.validation.Valid;
  12. import jnpf.base.ActionResult;
  13. import jnpf.base.Page;
  14. import jnpf.base.Pagination;
  15. import jnpf.base.UserInfo;
  16. import jnpf.base.controller.SuperController;
  17. import jnpf.base.entity.DictionaryDataEntity;
  18. import jnpf.base.entity.SystemEntity;
  19. import jnpf.base.service.DictionaryDataService;
  20. import jnpf.base.service.SysconfigService;
  21. import jnpf.base.service.SystemService;
  22. import jnpf.base.util.ExcelTool;
  23. import jnpf.base.vo.DownloadVO;
  24. import jnpf.base.vo.ListVO;
  25. import jnpf.base.vo.PageListVO;
  26. import jnpf.base.vo.PaginationVO;
  27. import jnpf.config.ConfigValueUtil;
  28. import jnpf.constant.FileTypeConstant;
  29. import jnpf.constant.MsgCode;
  30. import jnpf.constant.PermissionConst;
  31. import jnpf.database.util.TenantDataSourceUtil;
  32. import jnpf.exception.DataException;
  33. import jnpf.flowable.enums.ExtraRuleEnum;
  34. import jnpf.message.service.SynThirdDingTalkService;
  35. import jnpf.message.service.SynThirdQyService;
  36. import jnpf.model.*;
  37. import jnpf.model.tenant.AdminInfoVO;
  38. import jnpf.model.tenant.TenantReSetPasswordForm;
  39. import jnpf.model.tenant.TenantVO;
  40. import jnpf.permission.constant.UserColumnMap;
  41. import jnpf.permission.entity.*;
  42. import jnpf.permission.model.check.CheckResult;
  43. import jnpf.permission.model.position.PosConModel;
  44. import jnpf.permission.model.position.PositionListVO;
  45. import jnpf.permission.model.position.PositionVo;
  46. import jnpf.permission.model.user.UserAuthForm;
  47. import jnpf.permission.model.user.UserIdListVo;
  48. import jnpf.permission.model.user.UserRelationIds;
  49. import jnpf.permission.model.user.WorkHandoverModel;
  50. import jnpf.permission.model.user.form.UserBatchForm;
  51. import jnpf.permission.model.user.form.UserCrForm;
  52. import jnpf.permission.model.user.form.UserResetPasswordForm;
  53. import jnpf.permission.model.user.form.UserUpForm;
  54. import jnpf.permission.model.user.mod.*;
  55. import jnpf.permission.model.user.page.PageUser;
  56. import jnpf.permission.model.user.page.PaginationUser;
  57. import jnpf.permission.model.user.page.UserPagination;
  58. import jnpf.permission.model.user.vo.*;
  59. import jnpf.permission.rest.PullUserUtil;
  60. import jnpf.permission.service.*;
  61. import jnpf.permission.util.AuthPermUtil;
  62. import jnpf.permission.util.PermissionUtil;
  63. import jnpf.service.AuthService;
  64. import jnpf.util.*;
  65. import jnpf.util.enums.DictionaryDataEnum;
  66. import jnpf.util.treeutil.SumTree;
  67. import jnpf.util.treeutil.newtreeutil.TreeDotUtils;
  68. import jnpf.workflow.service.TemplateApi;
  69. import lombok.extern.slf4j.Slf4j;
  70. import org.springframework.beans.factory.annotation.Autowired;
  71. import org.springframework.web.bind.annotation.*;
  72. import java.io.IOException;
  73. import java.util.*;
  74. import java.util.stream.Collectors;
  75. import static jnpf.util.Constants.ADMIN_KEY;
  76. /**
  77. * 用户管理
  78. *
  79. * @author JNPF开发平台组
  80. * @version V3.1.0
  81. * @copyright 引迈信息技术有限公司
  82. * @date 2019年9月26日 上午9:18
  83. */
  84. @Tag(name = "用户管理", description = "Users")
  85. @Slf4j
  86. @RestController
  87. @RequestMapping("/api/permission/Users")
  88. public class UserController extends SuperController<UserService, UserEntity> {
  89. @Autowired
  90. private CacheKeyUtil cacheKeyUtil;
  91. @Autowired
  92. private SynThirdQyService synThirdQyService;
  93. @Autowired
  94. private SynThirdDingTalkService synThirdDingTalkService;
  95. @Autowired
  96. private UserService userService;
  97. @Autowired
  98. private OrganizeService organizeService;
  99. @Autowired
  100. private RedisUtil redisUtil;
  101. @Autowired
  102. private UserRelationService userRelationService;
  103. @Autowired
  104. private RoleRelationService roleRelationService;
  105. @Autowired
  106. private RoleService roleService;
  107. @Autowired
  108. private PositionService positionService;
  109. @Autowired
  110. private GroupService groupService;
  111. @Autowired
  112. private TemplateApi templateApi;
  113. @Autowired
  114. private AuthService authService;
  115. @Autowired
  116. private DictionaryDataService dictionaryDataApi;
  117. @Autowired
  118. private ConfigValueUtil configValueUtil;
  119. @Autowired
  120. private SysconfigService sysconfigApi;
  121. @Autowired
  122. private AuthPermUtil authPermUtil;
  123. @Autowired
  124. private SystemService systemService;
  125. @Operation(summary = "获取用户列表")
  126. @GetMapping
  127. public ActionResult<PageListVO<UserListVO>> getList(UserPagination pagination) {
  128. List<UserEntity> userList = userService.getList(pagination);
  129. List<UserListVO> list = new ArrayList<>();
  130. List<DictionaryDataEntity> dataServiceList4 = dictionaryDataApi.getListByTypeDataCode(DictionaryDataEnum.SEX_TYPE.getDictionaryTypeId());
  131. Map<String, String> genderMap = dataServiceList4.stream().collect(Collectors.toMap(DictionaryDataEntity::getEnCode, DictionaryDataEntity::getFullName));
  132. Map<String, String> positionMap = positionService.getPosFullNameMap();
  133. //责任人(有岗位信息时添加属性)
  134. String dutyUser = "";
  135. if (StringUtil.isNotEmpty(pagination.getPositionId())) {
  136. PositionEntity info = positionService.getInfo(pagination.getPositionId());
  137. if (info != null) dutyUser = info.getDutyUser();
  138. }
  139. for (UserEntity userEntity : userList) {
  140. UserListVO userVO = JsonUtil.getJsonToBean(userEntity, UserListVO.class);
  141. userVO.setFullName(userVO.getRealName() + "/" + userVO.getAccount());
  142. userVO.setHandoverMark(userEntity.getHandoverMark() == null ? 0 : userEntity.getHandoverMark());
  143. userVO.setHeadIcon(UploaderUtil.uploaderImg(userVO.getHeadIcon()));
  144. // 时间小于当前时间则判断已解锁
  145. if (userVO.getEnabledMark() != null && userVO.getEnabledMark() != 0) {
  146. if (Objects.nonNull(userEntity.getUnlockTime()) && userEntity.getUnlockTime().getTime() > System.currentTimeMillis()) {
  147. userVO.setEnabledMark(2);
  148. } else if (Objects.nonNull(userEntity.getUnlockTime()) && userEntity.getUnlockTime().getTime() < System.currentTimeMillis()) {
  149. userVO.setEnabledMark(1);
  150. }
  151. }
  152. userVO.setGender(genderMap.get(userEntity.getGender()));
  153. StringJoiner positionJoiner = new StringJoiner(",");
  154. StringJoiner organizeJoiner = new StringJoiner(",");
  155. List<UserRelationEntity> allPostion = userRelationService.getListByObjectType(userEntity.getId(), PermissionConst.POSITION);
  156. if (CollectionUtil.isNotEmpty(allPostion)) {
  157. for (UserRelationEntity item : allPostion) {
  158. String posName = positionMap.get(item.getObjectId());
  159. if (posName != null) {
  160. positionJoiner.add(posName);
  161. organizeJoiner.add(posName.substring(0, posName.lastIndexOf("/")));
  162. }
  163. }
  164. }
  165. userVO.setPosition(positionJoiner.toString());
  166. userVO.setOrganize(organizeJoiner.toString());
  167. if (StringUtil.isNotEmpty(dutyUser) && dutyUser.equals(userEntity.getId())) {
  168. userVO.setIsDutyUser(1);
  169. }
  170. list.add(userVO);
  171. }
  172. PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
  173. return ActionResult.page(list, paginationVO);
  174. }
  175. @Operation(summary = "详情")
  176. @Parameters({
  177. @Parameter(name = "id", description = "用户id", required = true)
  178. })
  179. @SaCheckPermission("permission.user")
  180. @GetMapping("/{id}")
  181. public ActionResult<UserInfoVO> getInfo(@PathVariable("id") String id) throws DataException {
  182. UserEntity entity = userService.getInfo(id);
  183. if (entity == null) {
  184. return ActionResult.fail(MsgCode.FA001.get());
  185. }
  186. QueryWrapper<UserRelationEntity> roleQuery = new QueryWrapper<>();
  187. roleQuery.lambda().eq(UserRelationEntity::getUserId, id);
  188. roleQuery.lambda().eq(UserRelationEntity::getObjectType, PermissionConst.ROLE);
  189. List<String> roleIdList = new ArrayList<>();
  190. for (UserRelationEntity ure : userRelationService.list(roleQuery)) {
  191. roleIdList.add(ure.getObjectId());
  192. }
  193. entity.setHeadIcon(UploaderUtil.uploaderImg(entity.getHeadIcon()));
  194. // 得到组织树
  195. UserInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, UserInfoVO.class);
  196. vo.setRoleId(String.join(",", roleIdList));
  197. // 获取组织id数组
  198. QueryWrapper<UserRelationEntity> query = new QueryWrapper<>();
  199. query.lambda().eq(UserRelationEntity::getUserId, id);
  200. query.lambda().eq(UserRelationEntity::getObjectType, PermissionConst.ORGANIZE);
  201. List<String> organizeIds = new ArrayList<>();
  202. userRelationService.list(query).forEach(u -> {
  203. organizeIds.add(u.getObjectId());
  204. });
  205. // 岗位装配
  206. QueryWrapper<UserRelationEntity> positionQuery = new QueryWrapper<>();
  207. positionQuery.lambda().eq(UserRelationEntity::getUserId, id);
  208. positionQuery.lambda().eq(UserRelationEntity::getObjectType, PermissionConst.POSITION);
  209. String positionIds = "";
  210. for (UserRelationEntity ure : userRelationService.list(positionQuery)) {
  211. PositionEntity info = positionService.getInfo(ure.getObjectId());
  212. if (info != null) {
  213. positionIds = positionIds + "," + ure.getObjectId();
  214. }
  215. }
  216. if (!positionIds.isEmpty()) {
  217. vo.setPositionId(positionIds.substring(1));
  218. } else {
  219. vo.setPositionId(null);
  220. }
  221. // 设置分组id
  222. List<UserRelationEntity> listByObjectType = userRelationService.getListByObjectType(entity.getId(), PermissionConst.GROUP);
  223. StringBuilder groupId = new StringBuilder();
  224. listByObjectType.stream().forEach(t -> groupId.append("," + t.getObjectId()));
  225. if (groupId.length() > 0) {
  226. vo.setGroupId(groupId.toString().replaceFirst(",", ""));
  227. }
  228. vo.setOrganizeIdTree(PermissionUtil.getOrgIdsTree(organizeIds, 1, organizeService));
  229. return ActionResult.success(vo);
  230. }
  231. @Operation(summary = "新建用户")
  232. @Parameters({
  233. @Parameter(name = "userCrForm", description = "表单参数", required = true)
  234. })
  235. @SaCheckPermission("permission.user")
  236. @PostMapping
  237. public ActionResult<String> create(@RequestBody @Valid UserCrForm userCrForm) throws Exception {
  238. UserEntity entity = JsonUtil.getJsonToBean(userCrForm, UserEntity.class);
  239. if (userService.isExistByAccount(userCrForm.getAccount())) {
  240. return ActionResult.fail(MsgCode.EXIST001.get());
  241. }
  242. if (StringUtil.isEmpty(entity.getGender())) {
  243. return ActionResult.fail(MsgCode.PS020.get());
  244. }
  245. userService.create(entity);
  246. String catchKey = cacheKeyUtil.getAllUser();
  247. if (redisUtil.exists(catchKey)) {
  248. redisUtil.remove(catchKey);
  249. }
  250. BaseSystemInfo sysInfo = sysconfigApi.getSysInfo();
  251. entity.setPassword(sysInfo.getNewUserDefaultPassword());
  252. PullUserUtil.syncUser(entity, "create", UserProvider.getUser().getTenantId());
  253. return ActionResult.success(MsgCode.SU001.get());
  254. }
  255. @Operation(summary = "修改用户")
  256. @Parameters({
  257. @Parameter(name = "id", description = "主键值", required = true),
  258. @Parameter(name = "userUpForm", description = "表单参数", required = true)
  259. })
  260. @SaCheckPermission("permission.user")
  261. @PutMapping("/{id}")
  262. public ActionResult<String> update(@PathVariable("id") String id, @RequestBody @Valid UserUpForm userUpForm) throws Exception {
  263. UserEntity entity = JsonUtil.getJsonToBean(userUpForm, UserEntity.class);
  264. if (StringUtil.isEmpty(entity.getGender())) {
  265. return ActionResult.fail(MsgCode.PS020.get());
  266. }
  267. //将禁用的id加进数据
  268. UserEntity originUser = userService.getInfo(id);
  269. UserInfoVO infoVO = this.getInfo(id).getData();
  270. // 如果是管理员的话
  271. if ("1".equals(String.valueOf(originUser.getIsAdministrator()))) {
  272. UserInfo operatorUser = UserProvider.getUser();
  273. // 管理员可以修改自己,但是无法修改其他管理员
  274. if (operatorUser.getIsAdministrator()) {
  275. if (originUser.getEnabledMark() != 0 && entity.getEnabledMark() == 0) {
  276. return ActionResult.fail(MsgCode.PS021.get());
  277. }
  278. if (!ADMIN_KEY.equals(userService.getInfo(operatorUser.getUserId()).getAccount())) {
  279. if (!operatorUser.getUserId().equals(id)) {
  280. return ActionResult.fail(MsgCode.PS022.get());
  281. }
  282. }
  283. } else {
  284. return ActionResult.fail(MsgCode.PS023.get());
  285. }
  286. }
  287. if (!originUser.getAccount().equals(entity.getAccount())) {
  288. if (userService.isExistByAccount(entity.getAccount())) {
  289. return ActionResult.fail(MsgCode.EXIST001.get());
  290. }
  291. }
  292. // 如果账号被锁定
  293. if ("2".equals(String.valueOf(entity.getEnabledMark()))) {
  294. entity.setUnlockTime(null);
  295. entity.setLogErrorCount(0);
  296. }
  297. // 如果原来是锁定,现在不锁定,则置空错误次数
  298. if (originUser.getEnabledMark() == 2 && entity.getEnabledMark() == 1) {
  299. entity.setUnlockTime(null);
  300. entity.setLogErrorCount(0);
  301. }
  302. boolean flag = userService.update(id, entity);
  303. ThreadPoolExecutorUtil.getExecutor().execute(() -> {
  304. try {
  305. //修改用户之后判断是否需要同步到企业微信
  306. synThirdQyService.updateUserSysToQy(false, entity, "", 1);
  307. //修改用户之后判断是否需要同步到钉钉
  308. synThirdDingTalkService.updateUserSysToDing(false, entity, "", 1);
  309. } catch (Exception e) {
  310. log.error("修改用户之后同步失败到企业微信或钉钉失败,异常: {}", e.getMessage());
  311. }
  312. });
  313. if (!flag) {
  314. return ActionResult.fail(MsgCode.FA002.get());
  315. }
  316. // 踢出在线的用户
  317. if (Objects.equals(entity.getEnabledMark(), 0)) {
  318. userService.logoutUser(MsgCode.LOG208.get(), ImmutableList.of(entity.getId()));
  319. } else if (Objects.equals(entity.getEnabledMark(), 2)) {
  320. userService.logoutUser(MsgCode.LOG209.get(), ImmutableList.of(entity.getId()));
  321. }
  322. PullUserUtil.syncUser(entity, "update", UserProvider.getUser().getTenantId());
  323. return ActionResult.success(MsgCode.SU004.get());
  324. }
  325. @Operation(summary = "删除用户")
  326. @Parameters({
  327. @Parameter(name = "id", description = "主键值", required = true)
  328. })
  329. @SaCheckPermission("permission.user")
  330. @DeleteMapping("/{id}")
  331. public ActionResult delete(@PathVariable("id") String id) {
  332. UserEntity entity = userService.getInfo(id);
  333. if (entity != null) {
  334. if ("1".equals(String.valueOf(entity.getIsAdministrator()))) {
  335. return ActionResult.fail(MsgCode.PS026.get());
  336. }
  337. //判断是否是部门主管
  338. if (!(organizeService.getList(false).stream().filter(t -> id.equals(t.getManagerId())).count() == 0)) {
  339. return ActionResult.fail(MsgCode.PS027.get());
  340. }
  341. String tenantId = StringUtil.isEmpty(UserProvider.getUser().getTenantId()) ? "" : UserProvider.getUser().getTenantId();
  342. String catchKey = tenantId + "allUser";
  343. if (redisUtil.exists(catchKey)) {
  344. redisUtil.remove(catchKey);
  345. }
  346. //删除之前进行判断
  347. List<UserRelationEntity> relationEntities = userRelationService.getListByUserId(id, PermissionConst.ORGANIZE);
  348. SocialsSysConfig socialsConfig = sysconfigApi.getSocialsConfig();
  349. String dingDepartment = socialsConfig.getDingDepartment();
  350. String qyhDepartment = socialsConfig.getQyhDepartment();
  351. boolean dingChoice;
  352. boolean qyChoice;
  353. OrganizeEntity dingOrg = organizeService.getInfo(dingDepartment);
  354. OrganizeEntity qyQrg = organizeService.getInfo(qyhDepartment);
  355. if (ObjectUtil.isNotEmpty(dingOrg)) {
  356. dingChoice = relationEntities.stream().noneMatch(t -> dingOrg.getOrganizeIdTree().contains(t.getObjectId()));
  357. } else {
  358. dingChoice = true;
  359. }
  360. if (ObjectUtil.isNotEmpty(qyQrg)) {
  361. qyChoice = relationEntities.stream().noneMatch(t -> qyQrg.getOrganizeIdTree().contains(t.getObjectId()));
  362. } else {
  363. qyChoice = true;
  364. }
  365. userService.delete(entity);
  366. ThreadPoolExecutorUtil.getExecutor().execute(() -> {
  367. try {
  368. //删除用户之后判断是否需要同步到企业微信
  369. if (!qyChoice) {
  370. synThirdQyService.deleteUserSysToQy(false, id, "");
  371. }
  372. //删除用户之后判断是否需要同步到钉钉
  373. if (!dingChoice) {
  374. synThirdDingTalkService.deleteUserSysToDing(false, id, "");
  375. }
  376. } catch (Exception e) {
  377. log.error("删除用户之后同步失败到企业微信或钉钉失败,异常:" + e.getMessage());
  378. }
  379. });
  380. userService.logoutUser(MsgCode.LOG207.get(), ImmutableList.of(entity.getId()));
  381. PullUserUtil.syncUser(entity, "delete", UserProvider.getUser().getTenantId());
  382. return ActionResult.success(MsgCode.SU003.get());
  383. }
  384. return ActionResult.fail(MsgCode.FA003.get());
  385. }
  386. //++++++++++++++++++++++批量操作start+++++++++++++++++++++++++
  387. @Operation(summary = "批量删除")
  388. @Parameters({
  389. @Parameter(name = "idList", description = "用户id列表", required = true)
  390. })
  391. @SaCheckPermission("permission.user")
  392. @PostMapping("/BatchDelete")
  393. public ActionResult BatchDelete(@RequestBody UserBatchForm form) {
  394. List<UserEntity> listByUserIds = userService.getListByUserIds(form.getIds());
  395. List<String> userIdList = new ArrayList<>();
  396. if (CollectionUtil.isNotEmpty(listByUserIds)) {
  397. List<String> collect = listByUserIds.stream().filter(t ->
  398. !Objects.equals("1", t.getIsAdministrator())).map(UserEntity::getId).collect(Collectors.toList());
  399. userIdList.addAll(collect);
  400. } else {
  401. return ActionResult.fail(MsgCode.FA003.get());
  402. }
  403. if (CollectionUtil.isEmpty(userIdList)) {
  404. return ActionResult.fail(MsgCode.PS026.get());
  405. }
  406. if (redisUtil.exists(cacheKeyUtil.getAllUser())) {
  407. redisUtil.remove(cacheKeyUtil.getAllUser());
  408. }
  409. SocialsSysConfig socialsConfig = sysconfigApi.getSocialsConfig();
  410. String dingDepartment = socialsConfig.getDingDepartment();
  411. String qyhDepartment = socialsConfig.getQyhDepartment();
  412. OrganizeEntity dingOrg = organizeService.getInfo(dingDepartment);
  413. OrganizeEntity qyQrg = organizeService.getInfo(qyhDepartment);
  414. for (UserEntity userItem : listByUserIds) {
  415. if (userIdList.contains(userItem.getId())) {
  416. String id = userItem.getId();
  417. List<UserRelationEntity> relationEntities = userRelationService.getListByUserId(id, PermissionConst.ORGANIZE);
  418. boolean dingChoice;
  419. boolean qyChoice;
  420. if (ObjectUtil.isNotEmpty(dingOrg)) {
  421. dingChoice = relationEntities.stream().noneMatch(t -> dingOrg.getOrganizeIdTree().contains(t.getObjectId()));
  422. } else {
  423. dingChoice = true;
  424. }
  425. if (ObjectUtil.isNotEmpty(qyQrg)) {
  426. qyChoice = relationEntities.stream().noneMatch(t -> qyQrg.getOrganizeIdTree().contains(t.getObjectId()));
  427. } else {
  428. qyChoice = true;
  429. }
  430. ThreadPoolExecutorUtil.getExecutor().execute(() -> {
  431. try {
  432. //删除用户之后判断是否需要同步到企业微信
  433. if (!qyChoice) {
  434. synThirdQyService.deleteUserSysToQy(false, id, "");
  435. }
  436. //删除用户之后判断是否需要同步到钉钉
  437. if (!dingChoice) {
  438. synThirdDingTalkService.deleteUserSysToDing(false, id, "");
  439. }
  440. } catch (Exception e) {
  441. log.error("删除用户之后同步失败到企业微信或钉钉失败,异常:" + e.getMessage());
  442. }
  443. });
  444. PullUserUtil.syncUser(userItem, "delete", UserProvider.getUser().getTenantId());
  445. }
  446. }
  447. userService.batchDelete(userIdList);
  448. userService.logoutUser(MsgCode.LOG207.get(), userIdList);
  449. return ActionResult.success(MsgCode.SU003.get());
  450. }
  451. @Operation(summary = "批量更新状态:锁定、禁用、删除")
  452. @Parameters({
  453. @Parameter(name = "idList", description = "用户id列表", required = true),
  454. @Parameter(name = "enableMark", description = "用户id列表", required = true)
  455. })
  456. @SaCheckPermission("permission.user")
  457. @PostMapping("/BatchUpdateState")
  458. public ActionResult<String> BatchUpdateState(@RequestBody UserBatchForm form) {
  459. if (CollectionUtil.isNotEmpty(form.getIds())) {
  460. List<UserEntity> listByUserIds = userService.getListByUserIds(form.getIds());
  461. if (CollectionUtil.isNotEmpty(listByUserIds)) {
  462. try {
  463. for (UserEntity entity : listByUserIds) {
  464. if (Objects.equals(entity.getIsAdministrator(), 1)) {
  465. continue;
  466. }
  467. entity.setEnabledMark(form.getEnabledMark());
  468. userService.update(entity.getId(), entity);
  469. //禁用移除在线用户
  470. if (Objects.equals(form.getEnabledMark(), 0)) {
  471. userService.logoutUser(MsgCode.LOG208.get(), ImmutableList.of(entity.getId()));
  472. } else if (Objects.equals(form.getEnabledMark(), 2)) {
  473. userService.logoutUser(MsgCode.LOG209.get(), ImmutableList.of(entity.getId()));
  474. }
  475. }
  476. } catch (Exception e) {
  477. e.printStackTrace();
  478. }
  479. return ActionResult.success(MsgCode.SU005.get());
  480. }
  481. }
  482. return ActionResult.success(MsgCode.FA001.get());
  483. }
  484. //++++++++++++++++++++++批量操作end+++++++++++++++++++++++++
  485. /**
  486. * 获取用户列表
  487. *
  488. * @return ignore
  489. */
  490. @Operation(summary = "获取所有用户列表")
  491. @GetMapping("/All")
  492. public ActionResult<ListVO<UserAllVO>> getAllUsers(PaginationUser pagination) {
  493. List<UserEntity> list = userService.getList(pagination, null, false, false, null, null);
  494. List<UserAllVO> user = JsonUtil.getJsonToList(list, UserAllVO.class);
  495. ListVO<UserAllVO> vo = new ListVO<>();
  496. vo.setList(user);
  497. return ActionResult.success(vo);
  498. }
  499. /**
  500. * IM通讯获取用户接口
  501. *
  502. * @param pagination 分页参数
  503. * @return ignore
  504. */
  505. @Operation(summary = "IM通讯获取用户")
  506. @GetMapping("/ImUser")
  507. public ActionResult<PageListVO<ImUserListVo>> getAllImUserUsers(Pagination pagination) {
  508. PageUser pageUser = JsonUtil.getJsonToBean(pagination, PageUser.class);
  509. List<UserEntity> data = userService.getList(pageUser, true);
  510. List<ImUserListVo> list = new ArrayList<>();
  511. Map<String, OrganizeEntity> orgMaps = organizeService.getOrganizeName(data.stream().map(t -> t.getOrganizeId()).collect(Collectors.toList()), null, false, null);
  512. for (UserEntity entity : data) {
  513. ImUserListVo user = JsonUtil.getJsonToBean(entity, ImUserListVo.class);
  514. OrganizeEntity organize = orgMaps.get(entity.getOrganizeId());
  515. user.setDepartment(organize != null ? organize.getFullName() : "");
  516. user.setHeadIcon(UploaderUtil.uploaderImg(entity.getHeadIcon()));
  517. list.add(user);
  518. }
  519. PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
  520. return ActionResult.page(list, paginationVO);
  521. }
  522. /**
  523. * 获取用户下拉框列表
  524. *
  525. * @return ignore
  526. */
  527. @Operation(summary = "获取用户下拉框列表")
  528. @GetMapping("/Selector")
  529. public ActionResult<ListVO<UserSelectorVO>> selector() {
  530. Map<String, OrganizeEntity> orgMaps = organizeService.getOrgMaps(null, true, null);
  531. List<OrganizeEntity> organizeData = new ArrayList<>(orgMaps.values());
  532. List<UserEntity> userData = userService.getList(true);
  533. List<UserSelectorModel> treeList = JsonUtil.getJsonToList(organizeData, UserSelectorModel.class);
  534. for (UserSelectorModel entity1 : treeList) {
  535. if ("department".equals(entity1.getType())) {
  536. entity1.setIcon(PermissionConst.DEPARTMENT_ICON);
  537. } else if ("company".equals(entity1.getType())) {
  538. entity1.setIcon(PermissionConst.COMPANY_ICON);
  539. }
  540. }
  541. for (UserEntity entity : userData) {
  542. UserSelectorModel treeModel = new UserSelectorModel();
  543. treeModel.setId(entity.getId());
  544. treeModel.setParentId(entity.getOrganizeId());
  545. treeModel.setFullName(entity.getRealName() + "/" + entity.getAccount());
  546. treeModel.setType("user");
  547. treeModel.setIcon(PermissionConst.USER_ICON);
  548. treeList.add(treeModel);
  549. }
  550. List<SumTree<UserSelectorModel>> trees = TreeDotUtils.convertListToTreeDot(treeList);
  551. List<UserSelectorVO> listvo = JsonUtil.getJsonToList(trees, UserSelectorVO.class);
  552. List<OrganizeEntity> entities = organizeData.stream().filter(
  553. t -> "-1".equals(t.getParentId())
  554. ).collect(Collectors.toList());
  555. Iterator<UserSelectorVO> iterator = listvo.iterator();
  556. while (iterator.hasNext()) {
  557. UserSelectorVO userSelectorVO = iterator.next();
  558. for (OrganizeEntity entity : entities) {
  559. if (entity.getId().equals(userSelectorVO.getParentId())) {
  560. iterator.remove();//使用迭代器的删除方法删除
  561. }
  562. }
  563. }
  564. ListVO<UserSelectorVO> vo = new ListVO<>();
  565. vo.setList(listvo);
  566. return ActionResult.success(vo);
  567. }
  568. /**
  569. * 通过部门、岗位、用户、角色、分组id获取用户列表
  570. *
  571. * @param userConditionModel 用户选择模型
  572. * @return
  573. */
  574. @Operation(summary = "通过部门、岗位、用户、角色、分组id获取用户列表")
  575. @Parameters({
  576. @Parameter(name = "userConditionModel", description = "用户选择模型", required = true)
  577. })
  578. @PostMapping("/UserCondition")
  579. public ActionResult userCondition(@RequestBody UserConditionModel userConditionModel) {
  580. List<String> list = new ArrayList<>(16);
  581. if (userConditionModel.getDepartIds() != null) {
  582. list.addAll(userConditionModel.getDepartIds());
  583. }
  584. if (userConditionModel.getRoleIds() != null) {
  585. list.addAll(userConditionModel.getRoleIds());
  586. }
  587. if (userConditionModel.getPositionIds() != null) {
  588. list.addAll(userConditionModel.getPositionIds());
  589. }
  590. if (userConditionModel.getGroupIds() != null) {
  591. list.addAll(userConditionModel.getGroupIds());
  592. }
  593. if (list.size() == 0) {
  594. list = userRelationService.getListByObjectType(userConditionModel.getType()).stream().map(UserRelationEntity::getObjectId).collect(Collectors.toList());
  595. if (PermissionConst.GROUP.equals(userConditionModel.getType())) {
  596. List<GroupEntity> groupList = groupService.getListByIds(list);
  597. list = groupList.stream().map(GroupEntity::getId).collect(Collectors.toList());
  598. }
  599. if (PermissionConst.ORGANIZE.equals(userConditionModel.getType())) {
  600. List<OrganizeEntity> orgList = organizeService.getOrgEntityList(list, true);
  601. list = orgList.stream().map(OrganizeEntity::getId).collect(Collectors.toList());
  602. }
  603. if (PermissionConst.ROLE.equals(userConditionModel.getType())) {
  604. List<RoleEntity> roleList = roleService.getListByIds(list, null, false);
  605. list = roleList.stream().filter(t -> t.getEnabledMark() == 1).map(RoleEntity::getId).collect(Collectors.toList());
  606. }
  607. if (PermissionConst.POSITION.equals(userConditionModel.getType())) {
  608. List<PositionEntity> positionList = positionService.getPosList(list);
  609. list = positionList.stream().filter(t -> t.getEnabledMark() == 1).map(PositionEntity::getId).collect(Collectors.toList());
  610. }
  611. }
  612. List<String> collect = userRelationService.getListByObjectIdAll(list).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
  613. if (userConditionModel.getUserIds() != null) {
  614. collect.addAll(userConditionModel.getUserIds());
  615. }
  616. collect = collect.stream().distinct().collect(Collectors.toList());
  617. List<UserEntity> userName = userService.getUserName(collect, userConditionModel.getPagination());
  618. List<UserIdListVo> jsonToList = JsonUtil.getJsonToList(userName, UserIdListVo.class);
  619. Map<String, String> orgIdNameMaps = organizeService.getInfoList();
  620. jsonToList.forEach(t -> {
  621. t.setHeadIcon(UploaderUtil.uploaderImg(t.getHeadIcon()));
  622. t.setFullName(t.getRealName() + "/" + t.getAccount());
  623. List<UserRelationEntity> listByUserId = userRelationService.getListByUserId(t.getId(), PermissionConst.ORGANIZE);
  624. List<String> orgId = listByUserId.stream().map(UserRelationEntity::getObjectId).collect(Collectors.toList());
  625. List<OrganizeEntity> organizeName = new ArrayList<>(organizeService.getOrganizeName(orgId, null, false, null).values());
  626. StringBuilder stringBuilder = new StringBuilder();
  627. organizeName.forEach(org -> {
  628. if (StringUtil.isNotEmpty(org.getOrganizeIdTree())) {
  629. String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, org.getOrganizeIdTree(), "/");
  630. stringBuilder.append(",");
  631. stringBuilder.append(fullNameByOrgIdTree);
  632. }
  633. });
  634. if (stringBuilder.length() > 0) {
  635. t.setOrganize(stringBuilder.toString().replaceFirst(",", ""));
  636. }
  637. });
  638. PaginationVO paginationVO = JsonUtil.getJsonToBean(userConditionModel.getPagination(), PaginationVO.class);
  639. return ActionResult.page(jsonToList, paginationVO);
  640. }
  641. /**
  642. * 获取用户下拉框列表
  643. *
  644. * @param organizeIdForm 组织id
  645. * @param pagination 分页模型
  646. * @return
  647. */
  648. @Operation(summary = "获取用户下拉框列表")
  649. @Parameters({
  650. @Parameter(name = "organizeId", description = "组织id", required = true),
  651. @Parameter(name = "pagination", description = "分页模型", required = true)
  652. })
  653. @PostMapping("/ImUser/Selector/{organizeId}")
  654. public ActionResult<?> imUserSelector(@PathVariable("organizeId") String organizeIdForm, @RequestBody Pagination pagination) {
  655. String organizeId = XSSEscape.escape(organizeIdForm);
  656. List<UserSelectorVO> jsonToList = new ArrayList<>();
  657. Map<String, String> orgIdNameMaps = organizeService.getInfoList();
  658. Map<String, OrganizeEntity> orgMaps = organizeService.getOrgMaps(null, true, null);
  659. //判断是否搜索关键字
  660. if (StringUtil.isNotEmpty(pagination.getKeyword())) {
  661. //通过关键字查询
  662. PageUser pageUser = JsonUtil.getJsonToBean(pagination, PageUser.class);
  663. List<UserEntity> list = userService.getList(pageUser, false);
  664. //遍历用户给要返回的值插入值
  665. for (UserEntity entity : list) {
  666. UserSelectorVO vo = JsonUtil.getJsonToBean(entity, UserSelectorVO.class);
  667. vo.setParentId(entity.getOrganizeId());
  668. vo.setFullName(entity.getRealName() + "/" + entity.getAccount());
  669. vo.setType("user");
  670. vo.setIcon(PermissionConst.USER_ICON);
  671. vo.setHeadIcon(UploaderUtil.uploaderImg(vo.getHeadIcon()));
  672. List<UserRelationEntity> listByUserId = userRelationService.getListByUserId(entity.getId()).stream().filter(t -> t != null && PermissionConst.ORGANIZE.equals(t.getObjectType())).collect(Collectors.toList());
  673. StringJoiner stringJoiner = new StringJoiner(",");
  674. listByUserId.forEach(t -> {
  675. OrganizeEntity organizeEntity = orgMaps.get(t.getObjectId());
  676. if (organizeEntity != null) {
  677. String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/");
  678. if (StringUtil.isNotEmpty(fullNameByOrgIdTree)) {
  679. stringJoiner.add(fullNameByOrgIdTree);
  680. }
  681. }
  682. });
  683. vo.setOrganize(stringJoiner.toString());
  684. vo.setHasChildren(false);
  685. vo.setIsLeaf(true);
  686. jsonToList.add(vo);
  687. }
  688. PaginationVO jsonToBean = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
  689. return ActionResult.page(jsonToList, jsonToBean);
  690. }
  691. //获取所有组织
  692. List<OrganizeEntity> collect = new ArrayList<>(orgMaps.values());
  693. //判断时候传入组织id
  694. //如果传入组织id,则取出对应的子集
  695. if (!"0".equals(organizeId)) {
  696. //通过组织查询部门及人员
  697. //单个组织
  698. OrganizeEntity organizeEntity = orgMaps.get(organizeId);
  699. if (organizeEntity != null) {
  700. //取出组织下的部门
  701. List<OrganizeEntity> collect1 = collect.stream().filter(t -> t.getParentId().equals(organizeEntity.getId())).collect(Collectors.toList());
  702. for (OrganizeEntity entitys : collect1) {
  703. UserSelectorVO vo = JsonUtil.getJsonToBean(entitys, UserSelectorVO.class);
  704. if ("department".equals(entitys.getCategory())) {
  705. vo.setIcon(PermissionConst.DEPARTMENT_ICON);
  706. } else if ("company".equals(entitys.getCategory())) {
  707. vo.setIcon(PermissionConst.COMPANY_ICON);
  708. }
  709. vo.setOrganize(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, entitys.getOrganizeIdTree(), "/"));
  710. // 判断组织下是否有人
  711. jsonToList.add(vo);
  712. vo.setHasChildren(true);
  713. vo.setIsLeaf(false);
  714. }
  715. //取出组织下的人员
  716. List<UserEntity> entityList = userService.getListByOrganizeId(organizeId, null);
  717. for (UserEntity entity : entityList) {
  718. if ("0".equals(String.valueOf(entity.getEnabledMark()))) {
  719. continue;
  720. }
  721. UserSelectorVO vo = JsonUtil.getJsonToBean(entity, UserSelectorVO.class);
  722. vo.setParentId(organizeId);
  723. vo.setFullName(entity.getRealName() + "/" + entity.getAccount());
  724. vo.setType("user");
  725. vo.setIcon(PermissionConst.USER_ICON);
  726. List<UserRelationEntity> listByUserId = userRelationService.getListByUserId(entity.getId()).stream().filter(t -> t != null && PermissionConst.ORGANIZE.equals(t.getObjectType())).collect(Collectors.toList());
  727. StringBuilder stringBuilder = new StringBuilder();
  728. listByUserId.forEach(t -> {
  729. OrganizeEntity organizeEntity1 = orgMaps.get(t.getObjectId());
  730. if (organizeEntity1 != null) {
  731. String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity1.getOrganizeIdTree(), "/");
  732. if (StringUtil.isNotEmpty(fullNameByOrgIdTree)) {
  733. stringBuilder.append("," + fullNameByOrgIdTree);
  734. }
  735. }
  736. });
  737. if (stringBuilder.length() > 0) {
  738. vo.setOrganize(stringBuilder.toString().replaceFirst(",", ""));
  739. }
  740. vo.setHeadIcon(UploaderUtil.uploaderImg(vo.getHeadIcon()));
  741. vo.setHasChildren(false);
  742. vo.setIsLeaf(true);
  743. jsonToList.add(vo);
  744. }
  745. }
  746. ListVO<UserSelectorVO> vo = new ListVO<>();
  747. vo.setList(jsonToList);
  748. return ActionResult.success(vo);
  749. }
  750. //如果没有组织id,则取出所有组织
  751. jsonToList = JsonUtil.getJsonToList(collect.stream().filter(t -> "-1".equals(t.getParentId())).collect(Collectors.toList()), UserSelectorVO.class);
  752. //添加图标
  753. for (UserSelectorVO userSelectorVO : jsonToList) {
  754. userSelectorVO.setIcon(PermissionConst.COMPANY_ICON);
  755. userSelectorVO.setHasChildren(true);
  756. userSelectorVO.setIsLeaf(false);
  757. userSelectorVO.setOrganize(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, orgMaps.get(userSelectorVO.getId()).getOrganizeIdTree(), "/"));
  758. }
  759. ListVO<UserSelectorVO> vo = new ListVO<>();
  760. vo.setList(jsonToList);
  761. return ActionResult.success(vo);
  762. }
  763. /**
  764. * 获取用户下拉框列表
  765. *
  766. * @param organizeId 组织id
  767. * @param page 关键字
  768. * @return
  769. */
  770. @Operation(summary = "获取用户下拉框列表")
  771. @Parameters({
  772. @Parameter(name = "organizeId", description = "组织id", required = true),
  773. @Parameter(name = "page", description = "关键字", required = true)
  774. })
  775. @SaCheckPermission("permission.grade")
  776. @PostMapping("/GetListByAuthorize/{organizeId}")
  777. public ActionResult<ListVO<UserByRoleVO>> getListByAuthorize(@PathVariable("organizeId") String organizeId, @RequestBody Page page) {
  778. List<UserByRoleVO> jsonToList = userService.getListByAuthorize(organizeId, page);
  779. ListVO listVO = new ListVO();
  780. listVO.setList(jsonToList);
  781. return ActionResult.success(listVO);
  782. }
  783. @Operation(summary = "个人权限")
  784. @Parameters({
  785. @Parameter(name = "id", description = "主键值", required = true),
  786. })
  787. @GetMapping("/Authorize")
  788. public ActionResult<UserAuthorizeVO> getAuthorize(UserAuthForm param) {
  789. return ActionResult.success(authPermUtil.getUserAuth(param));
  790. }
  791. @Operation(summary = "角色岗位权限列表")
  792. @GetMapping("/getAllPermission")
  793. public ActionResult<List<PositionVo>> getAllPermission(@RequestParam(value = "userId", required = false) String userId) {
  794. if (StringUtil.isEmpty(userId)) {
  795. userId = UserProvider.getUser().getUserId();
  796. }
  797. List<PositionVo> listRes = new ArrayList<>();
  798. listRes.add(new PositionVo("all", "全部权限"));
  799. //添加岗位
  800. List<String> posIds = userRelationService.getListByUserId(userId, PermissionConst.POSITION).stream().map(u -> u.getObjectId()).collect(Collectors.toList());
  801. if (CollectionUtil.isNotEmpty(posIds)) {
  802. PositionVo pv = new PositionVo(PermissionConst.POSITION, "所属岗位");
  803. pv.setHasChildren(true);
  804. List<PositionVo> child = new ArrayList<>();
  805. Map<String, Object> allOrgsTreeName = organizeService.getAllOrgsTreeName();
  806. List<PositionEntity> rList = positionService.getListByIds(posIds);
  807. for (PositionEntity item : rList) {
  808. PositionVo vo = JsonUtil.getJsonToBean(item, PositionVo.class);
  809. vo.setFullName(allOrgsTreeName.get(item.getOrganizeId()) + "/" + item.getFullName());
  810. vo.setType(PermissionConst.POSITION);
  811. child.add(vo);
  812. }
  813. pv.setChildren(child);
  814. listRes.add(pv);
  815. }
  816. //添加角色
  817. List<String> roleIds = roleRelationService.getListByObjectId(userId, PermissionConst.USER)
  818. .stream().map(RoleRelationEntity::getRoleId).collect(Collectors.toList());
  819. if (CollectionUtil.isNotEmpty(roleIds)) {
  820. PositionVo pv = new PositionVo(PermissionConst.ROLE, "所属角色");
  821. pv.setHasChildren(true);
  822. List<PositionVo> child = new ArrayList<>();
  823. List<RoleEntity> rList = roleService.getListByIds(roleIds);
  824. for (RoleEntity item : rList) {
  825. PositionVo vo = JsonUtil.getJsonToBean(item, PositionVo.class);
  826. vo.setType(PermissionConst.ROLE);
  827. child.add(vo);
  828. }
  829. pv.setChildren(child);
  830. listRes.add(pv);
  831. }
  832. return ActionResult.success(listRes);
  833. }
  834. @Operation(summary = "用户获取岗位")
  835. @Parameters({
  836. @Parameter(name = "id", description = "主键值", required = true),
  837. })
  838. @SaCheckPermission("permission.user")
  839. @GetMapping("/{id}/GetPosition")
  840. public ActionResult<List<PositionListVO>> GetPosition(@PathVariable("id") String id) {
  841. UserEntity entity = userService.getInfo(id);
  842. List<PositionListVO> list = new ArrayList<>();
  843. if (entity != null) {
  844. List<UserRelationEntity> relationList = userRelationService.getListByUserId(id, PermissionConst.POSITION);
  845. Map<String, Object> allOrgsTreeName = organizeService.getAllOrgsTreeName();
  846. List<PositionEntity> positionList = positionService.getListByIds(relationList.stream().map(UserRelationEntity::getObjectId).collect(Collectors.toList()));
  847. for (PositionEntity item : positionList) {
  848. PositionListVO vo = JsonUtil.getJsonToBean(item, PositionListVO.class);
  849. vo.setOrgNameTree(allOrgsTreeName.get(item.getOrganizeId()) + "/" + item.getFullName());
  850. list.add(vo);
  851. }
  852. }
  853. return ActionResult.success(list);
  854. }
  855. @Operation(summary = "同岗位用户列表")
  856. @Parameters({
  857. @Parameter(name = "id", description = "主键值", required = true),
  858. })
  859. @SaCheckPermission("permission.user")
  860. @GetMapping("/{id}/SelectorByUserPosId")
  861. public ActionResult<PageListVO<UserListVO>> SelectorByUserPosId(@PathVariable("id") String id, Pagination pagination) {
  862. UserEntity entity = userService.getInfo(id);
  863. PageUser pageUser = JsonUtil.getJsonToBean(pagination, PageUser.class);
  864. List<UserListVO> list = new ArrayList<>();
  865. if (entity != null) {
  866. List<UserRelationEntity> relationList = userRelationService.getListByUserId(id, PermissionConst.POSITION);
  867. List<String> posIds = relationList.stream().map(UserRelationEntity::getObjectId).collect(Collectors.toList());
  868. List<String> userIds = userRelationService.getListByObjectIdAll(posIds).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
  869. if (CollectionUtil.isNotEmpty(userIds)) {
  870. pageUser.setIdList(userIds);
  871. List<UserEntity> userList = userService.getList(pageUser, true);
  872. for (UserEntity item : userList) {
  873. UserListVO vo = JsonUtil.getJsonToBean(item, UserListVO.class);
  874. vo.setFullName(item.getRealName() + "/" + item.getAccount());
  875. vo.setHeadIcon(UploaderUtil.uploaderImg(item.getHeadIcon()));
  876. list.add(vo);
  877. }
  878. }
  879. }
  880. PaginationVO paginationVO = JsonUtil.getJsonToBean(pageUser, PaginationVO.class);
  881. return ActionResult.page(list, paginationVO);
  882. }
  883. @Operation(summary = "用户调整岗位")
  884. @Parameters({
  885. @Parameter(name = "id", description = "用户主键值", required = true)
  886. })
  887. @SaCheckPermission("permission.user")
  888. @PostMapping("/{id}/SetPosition")
  889. public ActionResult setPosition(@PathVariable("id") String id, @RequestBody UserBatchForm form) {
  890. UserEntity entity = userService.getInfo(id);
  891. if (entity == null) {
  892. return ActionResult.fail(MsgCode.FA001.get());
  893. }
  894. if (Objects.equals(entity.getIsAdministrator(), 1)) {
  895. return ActionResult.success(MsgCode.PS023.get());
  896. }
  897. List<String> posIds = form.getIds();
  898. List<UserRelationEntity> relationList = userRelationService.getListByUserId(id, PermissionConst.POSITION);
  899. //直接打开不编辑保存不执行代码
  900. if (!posIds.isEmpty() && posIds.equals(relationList.stream().map(UserRelationEntity::getObjectId).collect(Collectors.toList()))) {
  901. return ActionResult.success(MsgCode.SU023.get());
  902. }
  903. List<PositionEntity> posList = positionService.getListByIds(posIds);
  904. //判断约束 -- 逐一判断,能成功的就添加res
  905. List<String> res = new ArrayList<>();
  906. Set<String> huchi = new HashSet<>();
  907. Set<String> xianjue = new HashSet<>();
  908. List<String> errList1 = new ArrayList<>();
  909. filterPos(posIds, posList, errList1, huchi, res, xianjue);
  910. //先决第一个判断不存在,再次判断后续有没有添加上先决的
  911. if (CollectionUtil.isNotEmpty(xianjue)) {
  912. filterXianJuePos(new ArrayList<>(xianjue), posList, errList1, res);
  913. }
  914. //只有出现约束异常就直接修改失败
  915. if (CollectionUtil.isNotEmpty(errList1)) {
  916. return ActionResult.fail(MsgCode.FA055.get(MsgCode.PS004.get()));
  917. }
  918. List<UserRelationEntity> orgList = userRelationService.getListByUserId(id, PermissionConst.ORGANIZE);
  919. //移除全部岗位、组织和用户得关系
  920. List<UserRelationEntity> deleteAll = new ArrayList<>();
  921. deleteAll.addAll(relationList);
  922. deleteAll.addAll(orgList);
  923. //删除之前进行判断
  924. SocialsSysConfig socialsConfig = sysconfigApi.getSocialsConfig();
  925. String dingDepartment = socialsConfig.getDingDepartment();
  926. String qyhDepartment = socialsConfig.getQyhDepartment();
  927. boolean dingChoice;
  928. boolean qyChoice;
  929. OrganizeEntity dingOrg = organizeService.getInfo(dingDepartment);
  930. OrganizeEntity qyQrg = organizeService.getInfo(qyhDepartment);
  931. if (ObjectUtil.isNotEmpty(dingOrg)) {
  932. dingChoice = deleteAll.stream().noneMatch(t -> dingOrg.getOrganizeIdTree().contains(t.getObjectId()));
  933. } else {
  934. dingChoice = true;
  935. }
  936. if (ObjectUtil.isNotEmpty(qyQrg)) {
  937. qyChoice = deleteAll.stream().noneMatch(t -> qyQrg.getOrganizeIdTree().contains(t.getObjectId()));
  938. } else {
  939. qyChoice = true;
  940. }
  941. ThreadPoolExecutorUtil.getExecutor().execute(() -> {
  942. try {
  943. //获取公司关联
  944. List<String> collect = deleteAll.stream()
  945. .filter(t -> t.getObjectType().equals(PermissionConst.ORGANIZE))
  946. .map(UserRelationEntity::getObjectId).collect(Collectors.toList());
  947. if (!dingChoice) {
  948. synThirdDingTalkService.deleteUserSysToDing(false, entity, "", collect);
  949. }
  950. if (!qyChoice) {
  951. synThirdQyService.deleteUserSysToQy(false, entity, "", collect);
  952. }
  953. } catch (Exception e) {
  954. log.error("创建组织后同步失败到钉钉失败,异常:{}", e.getMessage());
  955. }
  956. });
  957. for (UserRelationEntity relationEntity : deleteAll) {
  958. userRelationService.removeById(relationEntity);
  959. }
  960. List<UserRelationEntity> addAll = new ArrayList<>();
  961. if (CollectionUtil.isNotEmpty(res)) {
  962. for (String positionId : res) {
  963. PositionEntity info = posList.stream().filter(t -> t.getId().equals(positionId)).findFirst().orElse(null);
  964. UserRelationEntity userRelation = new UserRelationEntity();
  965. userRelation.setObjectId(positionId);
  966. userRelation.setUserId(id);
  967. userRelation.setObjectType(PermissionConst.POSITION);
  968. addAll.add(userRelation);
  969. //岗位添加组织关系方便使用
  970. UserRelationEntity userOrgRelation = new UserRelationEntity();
  971. userOrgRelation.setObjectId(info.getOrganizeId());
  972. userOrgRelation.setUserId(id);
  973. userOrgRelation.setObjectType(PermissionConst.ORGANIZE);
  974. addAll.add(userOrgRelation);
  975. }
  976. userRelationService.save(addAll);
  977. ThreadPoolExecutorUtil.getExecutor().execute(() -> {
  978. try {
  979. //获取公司关联
  980. List<String> collect = addAll.stream()
  981. .filter(t -> t.getObjectType().equals(PermissionConst.ORGANIZE))
  982. .map(UserRelationEntity::getObjectId).collect(Collectors.toList());
  983. synThirdQyService.createUserSysToQy(false, entity, "", collect);
  984. synThirdDingTalkService.createUserSysToDing(false, entity, "", collect);
  985. } catch (Exception e) {
  986. log.error("创建组织后同步失败到企业微信或钉钉失败,异常:{}", e.getMessage());
  987. }
  988. });
  989. userService.delCurUser(MsgCode.PS010.get(), Collections.singletonList(id));
  990. }
  991. return ActionResult.success(MsgCode.SU023.get());
  992. }
  993. private void filterPos(List<String> posIds, List<PositionEntity> posList, List<String> errList1, Set<String> huchi, List<String> res, Set<String> xianjue) {
  994. for (String positionId : posIds) {
  995. List<String> errList2 = new ArrayList<>();
  996. PositionEntity info = posList.stream().filter(t -> t.getId().equals(positionId)).findFirst().orElse(null);
  997. List<String> userIds = userRelationService.getListByObjectId(positionId, PermissionConst.POSITION)
  998. .stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
  999. PosConModel posConModel = new PosConModel();
  1000. if (Objects.equals(info.getIsCondition(), 1)) {
  1001. posConModel = JsonUtil.getJsonToBean(info.getConditionJson(), PosConModel.class);
  1002. posConModel.init();
  1003. }
  1004. //超出权限基数的截取
  1005. if (posConModel.getNumFlag() && posConModel.getUserNum() < (1 + userIds.size())) {
  1006. errList2.add(MsgCode.SYS135.get(MsgCode.PS004.get()));
  1007. }
  1008. //在已有岗位的互斥信息里
  1009. if (huchi.contains(positionId)) {
  1010. errList2.add(MsgCode.SYS137.get(MsgCode.PS004.get()));
  1011. }
  1012. //当前的岗位互斥信息-存在互斥岗位
  1013. List<String> mutualExclusion = posConModel.getMutualExclusion();
  1014. if (posConModel.getMutualExclusionFlag()) {
  1015. //互斥
  1016. List<String> collect = res.stream().filter(t -> mutualExclusion.contains(t)).collect(Collectors.toList());
  1017. if (CollectionUtil.isNotEmpty(collect)) {
  1018. errList2.add(MsgCode.SYS137.get(MsgCode.PS004.get()));
  1019. }
  1020. }
  1021. if (posConModel.getPrerequisiteFlag()) {
  1022. //先决
  1023. xianjue.add(positionId);
  1024. }
  1025. if (errList2.size() == 0) {
  1026. res.add(positionId);
  1027. if (CollectionUtil.isNotEmpty(mutualExclusion)) {
  1028. huchi.addAll(mutualExclusion);
  1029. }
  1030. } else {
  1031. errList1.addAll(errList2);
  1032. }
  1033. }
  1034. }
  1035. private void filterXianJuePos(List<String> posIds, List<PositionEntity> posList, List<String> errList1, List<String> res) {
  1036. for (String positionId : posIds) {
  1037. List<String> errList2 = new ArrayList<>();
  1038. PositionEntity info = posList.stream().filter(t -> t.getId().equals(positionId)).findFirst().orElse(null);
  1039. PosConModel posConModel = new PosConModel();
  1040. if (Objects.equals(info.getIsCondition(), 1)) {
  1041. posConModel = JsonUtil.getJsonToBean(info.getConditionJson(), PosConModel.class);
  1042. posConModel.init();
  1043. }
  1044. if (posConModel.getPrerequisiteFlag() && !res.containsAll(posConModel.getPrerequisite())) {
  1045. //先决
  1046. errList2.add(MsgCode.SYS138.get(MsgCode.PS004.get()));
  1047. }
  1048. if (errList2.size() == 0) {
  1049. res.add(positionId);
  1050. } else {
  1051. errList1.addAll(errList2);
  1052. }
  1053. }
  1054. }
  1055. @Operation(summary = "批量调整岗位")
  1056. @SaCheckPermission("permission.user")
  1057. @PostMapping("/SetPositionBatch")
  1058. public ActionResult setPositionBatch(@RequestBody UserBatchForm form) {
  1059. List<UserEntity> userList = userService.getListByUserIds(form.getUserIds());
  1060. List<String> posIds = form.getIds();
  1061. List<PositionEntity> positionList = positionService.getListByIds(posIds);
  1062. if (CollectionUtil.isEmpty(userList)) {
  1063. return ActionResult.fail(MsgCode.FA001.get());
  1064. }
  1065. SocialsSysConfig socialsConfig = sysconfigApi.getSocialsConfig();
  1066. String dingDepartment = socialsConfig.getDingDepartment();
  1067. String qyhDepartment = socialsConfig.getQyhDepartment();
  1068. OrganizeEntity dingOrg = organizeService.getInfo(dingDepartment);
  1069. OrganizeEntity qyQrg = organizeService.getInfo(qyhDepartment);
  1070. List<String> userIds = userList.stream().filter(t -> !Objects.equals(t.getIsAdministrator(), 1)).map(UserEntity::getId).collect(Collectors.toList());
  1071. //再加
  1072. List<String> addUserIds = new ArrayList<>();
  1073. List<String> skipUserIds = new ArrayList<>();
  1074. for (String userId : userIds) {
  1075. List<UserRelationEntity> relationList = userRelationService.getListByObjectType(userId, null);
  1076. //直接打开不编辑保存不执行代码
  1077. if (posIds.size() > 0 && posIds.equals(relationList.stream().filter(t -> PermissionConst.POSITION.equals(t.getObjectType()))
  1078. .map(UserRelationEntity::getObjectId).collect(Collectors.toList()))) {
  1079. skipUserIds.add(userId);
  1080. continue;
  1081. }
  1082. //判断约束
  1083. List<String> res = new ArrayList<>();
  1084. Set<String> huchi = new HashSet<>();
  1085. Set<String> xianjue = new HashSet<>();
  1086. List<String> errList1 = new ArrayList<>();
  1087. filterPos(posIds, positionList, errList1, huchi, res, xianjue);
  1088. //先决第一个判断不存在,再次判断后续有没有添加上先决的
  1089. if (CollectionUtil.isNotEmpty(xianjue)) {
  1090. filterXianJuePos(new ArrayList<>(xianjue), positionList, errList1, res);
  1091. }
  1092. //岗位有约束异常就不添加
  1093. if (CollectionUtil.isNotEmpty(errList1)) {
  1094. continue;
  1095. }
  1096. addUserIds.add(userId);
  1097. List<UserRelationEntity> addAll = new ArrayList<>();
  1098. for (String positionId : posIds) {
  1099. PositionEntity info = positionList.stream().filter(t -> t.getId().equals(positionId)).findFirst().orElse(null);
  1100. UserRelationEntity userRelation = new UserRelationEntity();
  1101. userRelation.setObjectId(info.getId());
  1102. userRelation.setUserId(userId);
  1103. userRelation.setObjectType(PermissionConst.POSITION);
  1104. addAll.add(userRelation);
  1105. //岗位添加组织关系方便使用
  1106. UserRelationEntity userOrgRelation = new UserRelationEntity();
  1107. userOrgRelation.setObjectId(info.getOrganizeId());
  1108. userOrgRelation.setUserId(userId);
  1109. userOrgRelation.setObjectType(PermissionConst.ORGANIZE);
  1110. addAll.add(userOrgRelation);
  1111. }
  1112. //先删
  1113. List<UserRelationEntity> deleteList = relationList.stream().filter(t -> PermissionConst.POSITION.equals(t.getObjectType())
  1114. || PermissionConst.ORGANIZE.equals(t.getObjectType())).collect(Collectors.toList());
  1115. //删除之前进行判断
  1116. boolean dingChoice;
  1117. boolean qyChoice;
  1118. if (ObjectUtil.isNotEmpty(dingOrg)) {
  1119. dingChoice = deleteList.stream().noneMatch(t -> dingOrg.getOrganizeIdTree().contains(t.getObjectId()));
  1120. } else {
  1121. dingChoice = true;
  1122. }
  1123. if (ObjectUtil.isNotEmpty(qyQrg)) {
  1124. qyChoice = deleteList.stream().noneMatch(t -> qyQrg.getOrganizeIdTree().contains(t.getObjectId()));
  1125. } else {
  1126. qyChoice = true;
  1127. }
  1128. for (UserRelationEntity relationEntity : deleteList) {
  1129. userRelationService.removeById(relationEntity);
  1130. }
  1131. try {
  1132. List<String> collect = deleteList.stream()
  1133. .map(UserRelationEntity::getUserId)
  1134. .collect(Collectors.toList());
  1135. if (!qyChoice) {
  1136. synThirdQyService.deleteUserSysToQy(false, collect, "", "");
  1137. }
  1138. if (!dingChoice) {
  1139. synThirdDingTalkService.deleteUserSysToDing(false, collect, "", "");
  1140. }
  1141. } catch (Exception e) {
  1142. log.error(e.getMessage());
  1143. }
  1144. userRelationService.save(addAll);
  1145. try {
  1146. Map<String, List<UserRelationEntity>> collect = addAll
  1147. .stream()
  1148. .filter(t -> t.getObjectType().equals(PermissionConst.POSITION))
  1149. .collect(Collectors.groupingBy(UserRelationEntity::getObjectId));
  1150. for (String string : collect.keySet()) {
  1151. PositionEntity info = positionService.getInfo(string);
  1152. List<UserRelationEntity> userRelationEntities = collect.get(string);
  1153. List<String> userEntityIds = userRelationEntities.stream().map(UserRelationEntity::getUserId)
  1154. .collect(Collectors.toList());
  1155. List<UserEntity> userEntities = userService.getUserList(userEntityIds)
  1156. .stream().peek(t -> t.setOrganizeId(info.getOrganizeId()))
  1157. .collect(Collectors.toList());
  1158. synThirdQyService.createUserSysToQy(false, userEntities, "", info.getId());
  1159. synThirdDingTalkService.createUserSysToDing(false, userEntities, "", info.getId());
  1160. }
  1161. } catch (Exception e) {
  1162. log.error(e.getMessage());
  1163. }
  1164. }
  1165. if (CollectionUtil.isNotEmpty(addUserIds)) {
  1166. userService.delCurUser(MsgCode.PS010.get(), addUserIds);
  1167. }
  1168. if (addUserIds.size() == 0 && skipUserIds.size() == 0) {
  1169. return ActionResult.fail(MsgCode.FA054.get());
  1170. } else if (addUserIds.size() > 0 && addUserIds.size() != userIds.size()) {
  1171. return ActionResult.success(MsgCode.SU024.get());
  1172. }
  1173. return ActionResult.success(MsgCode.SU023.get());
  1174. }
  1175. @Operation(summary = "修改用户密码")
  1176. @Parameters({
  1177. @Parameter(name = "id", description = "主键值", required = true),
  1178. @Parameter(name = "userResetPasswordForm", description = "修改密码模型", required = true)
  1179. })
  1180. @SaCheckPermission("permission.user")
  1181. @PostMapping("/{id}/Actions/ResetPassword")
  1182. public ActionResult<String> modifyPassword(@PathVariable("id") String id, @RequestBody @Valid UserResetPasswordForm userResetPasswordForm) {
  1183. UserEntity entity = userService.getInfo(id);
  1184. if (entity != null) {
  1185. entity.setPassword(userResetPasswordForm.getUserPassword());
  1186. userService.updatePassword(entity);
  1187. userService.logoutUser(MsgCode.PS011.get(), ImmutableList.of(entity.getId()));
  1188. entity.setPassword(userResetPasswordForm.getUserPassword());
  1189. PullUserUtil.syncUser(entity, "modifyPassword", UserProvider.getUser().getTenantId());
  1190. return ActionResult.success(MsgCode.SU005.get());
  1191. }
  1192. return ActionResult.success(MsgCode.FA001.get());
  1193. }
  1194. /**
  1195. * 更新用户状态
  1196. *
  1197. * @param id 主键值
  1198. * @return ignore
  1199. */
  1200. @Operation(summary = "更新用户状态")
  1201. @Parameters({
  1202. @Parameter(name = "id", description = "主键值", required = true)
  1203. })
  1204. @SaCheckPermission("permission.user")
  1205. @PutMapping("/{id}/Actions/State")
  1206. public ActionResult<String> disable(@PathVariable("id") String id) throws Exception {
  1207. UserEntity entity = userService.getInfo(id);
  1208. if (entity != null) {
  1209. if ("1".equals(String.valueOf(entity.getIsAdministrator()))) {
  1210. return ActionResult.fail(MsgCode.PS029.get());
  1211. }
  1212. if (entity.getEnabledMark() != null) {
  1213. if ("1".equals(String.valueOf(entity.getEnabledMark()))) {
  1214. entity.setEnabledMark(0);
  1215. userService.delCurUser(null, ImmutableList.of(entity.getId()));
  1216. userService.update(id, entity);
  1217. } else {
  1218. entity.setEnabledMark(1);
  1219. userService.update(id, entity);
  1220. }
  1221. } else {
  1222. entity.setEnabledMark(1);
  1223. userService.update(id, entity);
  1224. }
  1225. return ActionResult.success(MsgCode.SU005.get());
  1226. }
  1227. return ActionResult.success(MsgCode.FA001.get());
  1228. }
  1229. /**
  1230. * 解除锁定
  1231. *
  1232. * @param id 主键值
  1233. * @return ignore
  1234. */
  1235. @Operation(summary = "解除锁定")
  1236. @Parameters({
  1237. @Parameter(name = "id", description = "主键值", required = true)
  1238. })
  1239. @SaCheckPermission("permission.user")
  1240. @PutMapping("/{id}/Actions/unlock")
  1241. public ActionResult<String> unlock(@PathVariable("id") String id) throws Exception {
  1242. UserEntity entity = userService.getInfo(id);
  1243. if (entity != null) {
  1244. // 状态变成正常
  1245. entity.setEnabledMark(1);
  1246. entity.setUnlockTime(null);
  1247. entity.setLogErrorCount(0);
  1248. entity.setId(id);
  1249. userService.updateById(entity);
  1250. return ActionResult.success(MsgCode.SU005.get());
  1251. }
  1252. return ActionResult.success(MsgCode.FA001.get());
  1253. }
  1254. /**
  1255. * 获取用户基本信息
  1256. *
  1257. * @param userIdModel 用户id
  1258. * @return ignore
  1259. */
  1260. @Operation(summary = "获取用户基本信息")
  1261. @Parameters({
  1262. @Parameter(name = "userIdModel", description = "用户id", required = true)
  1263. })
  1264. @PostMapping("/getUserList")
  1265. public ActionResult<ListVO<UserIdListVo>> getUserList(@RequestBody UserIdModel userIdModel) {
  1266. List<UserEntity> userName = userService.getUserName(userIdModel.getIds(), true);
  1267. List<UserIdListVo> list = JsonUtil.getJsonToList(userName, UserIdListVo.class);
  1268. List<UserRelationEntity> listByUserIds = userRelationService.getRelationByUserIds(list.stream().map(UserIdListVo::getId).collect(Collectors.toList()));
  1269. Map<String, String> orgIdNameMaps = organizeService.getInfoList();
  1270. for (UserIdListVo entity : list) {
  1271. if (entity == null) {
  1272. break;
  1273. }
  1274. entity.setFullName(entity.getRealName() + "/" + entity.getAccount());
  1275. List<UserRelationEntity> listByUserId = listByUserIds.stream().filter(t -> t.getUserId().equals(entity.getId())).collect(Collectors.toList());
  1276. StringBuilder stringBuilder = new StringBuilder();
  1277. List<OrganizeEntity> orgEntityList = organizeService.getOrgEntityList(listByUserId.stream().map(UserRelationEntity::getObjectId).collect(Collectors.toList()), false);
  1278. listByUserId.forEach(t -> {
  1279. OrganizeEntity organizeEntity = orgEntityList.stream().filter(org -> org.getId().equals(t.getObjectId())).findFirst().orElse(null);
  1280. if (organizeEntity != null) {
  1281. String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/");
  1282. if (StringUtil.isNotEmpty(fullNameByOrgIdTree)) {
  1283. stringBuilder.append("," + fullNameByOrgIdTree);
  1284. }
  1285. }
  1286. });
  1287. if (stringBuilder.length() > 0) {
  1288. entity.setOrganize(stringBuilder.toString().replaceFirst(",", ""));
  1289. }
  1290. entity.setHeadIcon(UploaderUtil.uploaderImg(entity.getHeadIcon()));
  1291. }
  1292. ListVO<UserIdListVo> listVO = new ListVO<>();
  1293. listVO.setList(list);
  1294. return ActionResult.success(listVO);
  1295. }
  1296. /**
  1297. * 获取选中组织、岗位、角色、用户基本信息
  1298. *
  1299. * @param userIdModel 用户id
  1300. * @return ignore
  1301. */
  1302. @Operation(summary = "获取选中组织、岗位、角色、用户基本信息")
  1303. @Parameters({
  1304. @Parameter(name = "userIdModel", description = "用户id", required = true)
  1305. })
  1306. @PostMapping("/getSelectedList")
  1307. public ActionResult<ListVO<BaseInfoVo>> getSelectedList(@RequestBody UserIdModel userIdModel) {
  1308. List<String> ids = userIdModel.getIds();
  1309. List<BaseInfoVo> list = userService.selectedByIds(ids);
  1310. ListVO<BaseInfoVo> listVO = new ListVO<>();
  1311. listVO.setList(list);
  1312. return ActionResult.success(listVO);
  1313. }
  1314. /**
  1315. * 获取用户基本信息
  1316. *
  1317. * @param userIdModel 用户id
  1318. * @return ignore
  1319. */
  1320. @Operation(summary = "获取选中用户基本信息")
  1321. @Parameters({
  1322. @Parameter(name = "userIdModel", description = "用户id", required = true)
  1323. })
  1324. @PostMapping("/getSelectedUserList")
  1325. public ActionResult<PageListVO<BaseInfoVo>> getSelectedUserList(@RequestBody UserIdModelByPage userIdModel) {
  1326. List<BaseInfoVo> jsonToList = userService.getObjList(userIdModel.getIds(), userIdModel);
  1327. PaginationVO paginationVO = JsonUtil.getJsonToBean(userIdModel, PaginationVO.class);
  1328. return ActionResult.page(jsonToList, paginationVO);
  1329. }
  1330. /**
  1331. * 获取组织下的人员
  1332. *
  1333. * @param page 页面信息
  1334. * @return ignore
  1335. */
  1336. @Operation(summary = "获取组织下的人员")
  1337. @GetMapping("/getOrganization")
  1338. public ActionResult<List<UserIdListVo>> getOrganization(PageUser page) {
  1339. String departmentId = page.getOrganizeId();
  1340. // 判断是否获取当前组织下的人员
  1341. if ("0".equals(departmentId)) {
  1342. departmentId = UserProvider.getUser().getDepartmentId();
  1343. // 为空则取组织id
  1344. if (StringUtil.isEmpty(departmentId)) {
  1345. departmentId = UserProvider.getUser().getOrganizeId();
  1346. }
  1347. }
  1348. Map<String, OrganizeEntity> orgMaps = organizeService.getOrgMaps(null, true, null);
  1349. List<UserEntity> list = userService.getListByOrganizeId(departmentId, page.getKeyword());
  1350. List<UserIdListVo> jsonToList = JsonUtil.getJsonToList(list, UserIdListVo.class);
  1351. Map<String, String> orgIdNameMaps = organizeService.getInfoList();
  1352. List<UserRelationEntity> listByObjectType = userRelationService.getListByObjectType(PermissionConst.ORGANIZE);
  1353. jsonToList.forEach(t -> {
  1354. t.setRealName(t.getRealName() + "/" + t.getAccount());
  1355. t.setFullName(t.getRealName());
  1356. List<String> collect = listByObjectType.stream().filter(userRelationEntity -> userRelationEntity.getUserId().equals(t.getId())).map(UserRelationEntity::getObjectId).collect(Collectors.toList());
  1357. StringJoiner stringJoiner = new StringJoiner(",");
  1358. collect.forEach(objectId -> {
  1359. OrganizeEntity organizeEntity = orgMaps.get(objectId);
  1360. if (organizeEntity != null) {
  1361. String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/");
  1362. if (StringUtil.isNotEmpty(fullNameByOrgIdTree)) {
  1363. stringJoiner.add(fullNameByOrgIdTree);
  1364. }
  1365. }
  1366. });
  1367. t.setOrganize(stringJoiner.toString());
  1368. t.setHeadIcon(UploaderUtil.uploaderImg(t.getHeadIcon()));
  1369. });
  1370. return ActionResult.success(jsonToList);
  1371. }
  1372. /**
  1373. * 获取人员,委托选人接口
  1374. *
  1375. * @param type 范围类型
  1376. * @param pagination 参数
  1377. */
  1378. @Operation(summary = "获取人员")
  1379. @GetMapping("/ReceiveUserList")
  1380. public ActionResult receiveUserList(@RequestParam("type") Integer type, Pagination pagination) {
  1381. UserInfo userInfo = UserProvider.getUser();
  1382. UserEntity user = userService.getInfo(userInfo.getUserId());
  1383. List<String> userId = new ArrayList<>();
  1384. List<Integer> ruleList = ImmutableList.of(ExtraRuleEnum.organize.getCode(), ExtraRuleEnum.position.getCode(),
  1385. ExtraRuleEnum.department.getCode());
  1386. boolean isDepartmeng = false;
  1387. if (ruleList.contains(type)) {
  1388. List<String> positionList = new ArrayList<>();
  1389. List<String> organizeList = new ArrayList<>();
  1390. List<UserRelationEntity> userPositionList = userRelationService.getListByUserIdAll(ImmutableList.of(user.getId())).stream()
  1391. .filter(t -> PermissionConst.POSITION.equals(t.getObjectType())).collect(Collectors.toList());
  1392. for (UserRelationEntity relation : userPositionList) {
  1393. PositionEntity positionInfo = positionService.getInfo(relation.getObjectId());
  1394. if (positionInfo != null) {
  1395. positionList.add(positionInfo.getId());
  1396. OrganizeEntity organizeInfo = organizeService.getInfo(positionInfo.getOrganizeId());
  1397. if (organizeInfo != null) {
  1398. organizeList.add(organizeInfo.getId());
  1399. }
  1400. }
  1401. }
  1402. switch (ExtraRuleEnum.getByCode(type)) {
  1403. case organize:
  1404. // 委托范围为同一部门,但委托人的所属组织是公司,无需选人
  1405. for (String organizeId : organizeList) {
  1406. OrganizeEntity organizeInfo = organizeService.getInfo(organizeId);
  1407. if (null != organizeInfo && Objects.equals(organizeInfo.getCategory(), PermissionConst.DEPARTMENT)) {
  1408. userId.addAll(userRelationService.getListByObjectIdAll(ImmutableList.of(organizeId)).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList()));
  1409. }
  1410. }
  1411. break;
  1412. case position:
  1413. for (String positionId : positionList) {
  1414. userId.addAll(userRelationService.getListByObjectIdAll(ImmutableList.of(positionId)).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList()));
  1415. }
  1416. break;
  1417. case department:
  1418. List<String> categoryList = ImmutableList.of("agency", "office");
  1419. int num = 0;
  1420. for (String organizeId : organizeList) {
  1421. OrganizeEntity organizeInfo = organizeService.getInfo(organizeId);
  1422. if (organizeInfo == null || categoryList.contains(organizeInfo.getCategory())) {
  1423. continue;
  1424. }
  1425. List<String> orgList = organizeService.getDepartmentAll(organizeId).stream().map(OrganizeEntity::getId).collect(Collectors.toList());
  1426. List<String> departmentAll = positionService.getListByOrgIds(orgList).stream().map(PositionEntity::getId).collect(Collectors.toList());
  1427. for (String id : departmentAll) {
  1428. userId.addAll(userRelationService.getListByObjectIdAll(ImmutableList.of(id)).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList()));
  1429. }
  1430. num++;
  1431. }
  1432. isDepartmeng = num == 0;
  1433. break;
  1434. }
  1435. }
  1436. List<UserEntity> list = isDepartmeng ? userService.getUserPage(pagination) : userService.getUserName(userId, pagination);
  1437. List<UserIdListVo> jsonToList = JsonUtil.getJsonToList(list, UserIdListVo.class);
  1438. if (!jsonToList.isEmpty()) {
  1439. List<String> userIdList = list.stream().map(UserEntity::getId).collect(Collectors.toList());
  1440. List<UserRelationEntity> userRelationList = userRelationService.getRelationByUserIds(userIdList);
  1441. Map<String, List<UserRelationEntity>> userMap = userRelationList.stream()
  1442. .filter(t -> PermissionConst.POSITION.equals(t.getObjectType())).collect(Collectors.groupingBy(UserRelationEntity::getUserId));
  1443. jsonToList.forEach(t -> {
  1444. t.setRealName(t.getRealName() + "/" + t.getAccount());
  1445. t.setFullName(t.getRealName());
  1446. t.setHeadIcon(UploaderUtil.uploaderImg(t.getHeadIcon()));
  1447. List<UserRelationEntity> listByUserId = userMap.get(user.getId()) != null ? userMap.get(user.getId()) : new ArrayList<>();
  1448. StringJoiner joiner = new StringJoiner(",");
  1449. for (UserRelationEntity relation : listByUserId) {
  1450. StringJoiner name = new StringJoiner("/");
  1451. PositionEntity position = positionService.getInfo(relation.getObjectId());
  1452. if (position != null) {
  1453. OrganizeEntity organize = organizeService.getInfo(position.getOrganizeId());
  1454. if (organize != null) {
  1455. List<String> organizeIdTree = new ArrayList<>(Arrays.asList(organize.getOrganizeIdTree().split(",")));
  1456. List<OrganizeEntity> organizeList = organizeService.getOrganizeName(organizeIdTree);
  1457. for (String organizeId : organizeIdTree) {
  1458. OrganizeEntity entity = organizeList.stream().filter(e -> Objects.equals(e.getId(), organizeId)).findFirst().orElse(null);
  1459. if (entity != null) {
  1460. name.add(entity.getFullName());
  1461. }
  1462. }
  1463. }
  1464. List<String> positionIdTree = new ArrayList<>(Arrays.asList(position.getPositionIdTree().split(",")));
  1465. List<PositionEntity> positionList = positionService.getPosList(positionIdTree);
  1466. for (String positionId : positionIdTree) {
  1467. PositionEntity entity = positionList.stream().filter(e -> Objects.equals(e.getId(), positionId)).findFirst().orElse(null);
  1468. if (entity != null) {
  1469. name.add(entity.getFullName());
  1470. }
  1471. }
  1472. }
  1473. joiner.add(name.toString());
  1474. t.setOrganize(joiner.toString());
  1475. }
  1476. });
  1477. }
  1478. PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
  1479. return ActionResult.page(jsonToList, paginationVO);
  1480. }
  1481. /**
  1482. * 获取岗位人员
  1483. *
  1484. * @param page 页面信息
  1485. * @return ignore
  1486. */
  1487. @Operation(summary = "获取岗位人员")
  1488. @GetMapping("/GetUsersByPositionId")
  1489. public ActionResult<List<UserByRoleVO>> getUsersByPositionId(UsersByPositionModel page) {
  1490. List<UserByRoleVO> list = new ArrayList<>(1);
  1491. String keyword = page.getKeyword();
  1492. // 岗位id
  1493. String positionId = page.getPositionId();
  1494. // 得到关联的组织id
  1495. PositionEntity positionEntity = positionService.getInfo(positionId);
  1496. if (positionEntity != null) {
  1497. UserByRoleVO vo = new UserByRoleVO();
  1498. String organizeId = positionEntity.getOrganizeId();
  1499. // 得到组织信息
  1500. OrganizeEntity organizeEntity = organizeService.getInfo(organizeId);
  1501. if (Objects.nonNull(organizeEntity)) {
  1502. vo.setId(organizeEntity.getId());
  1503. vo.setType(organizeEntity.getCategory());
  1504. if ("department".equals(organizeEntity.getCategory())) {
  1505. vo.setIcon(PermissionConst.DEPARTMENT_ICON);
  1506. } else {
  1507. vo.setIcon(PermissionConst.COMPANY_ICON);
  1508. }
  1509. vo.setEnabledMark(organizeEntity.getEnabledMark());
  1510. Map<String, String> orgIdNameMaps = organizeService.getInfoList();
  1511. // 组装组织名称
  1512. String orgName = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/");
  1513. vo.setFullName(orgName);
  1514. // 赋予子集
  1515. List<UserByRoleVO> userByRoleVOS = new ArrayList<>(16);
  1516. List<UserEntity> lists = userService.getListByOrganizeId(organizeEntity.getId(), keyword);
  1517. if (lists.size() > 0) {
  1518. vo.setHasChildren(true);
  1519. vo.setIsLeaf(false);
  1520. lists.stream().forEach(t -> {
  1521. UserByRoleVO userByRoleVO = new UserByRoleVO();
  1522. userByRoleVO.setParentId(organizeEntity.getId());
  1523. userByRoleVO.setId(t.getId());
  1524. userByRoleVO.setFullName(t.getRealName() + "/" + t.getAccount());
  1525. userByRoleVO.setEnabledMark(t.getEnabledMark());
  1526. userByRoleVO.setHeadIcon(UploaderUtil.uploaderImg(t.getHeadIcon()));
  1527. userByRoleVO.setOrganize(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/"));
  1528. userByRoleVO.setIsLeaf(true);
  1529. userByRoleVO.setHasChildren(false);
  1530. userByRoleVO.setIcon(PermissionConst.USER_ICON);
  1531. userByRoleVO.setType("user");
  1532. userByRoleVOS.add(userByRoleVO);
  1533. });
  1534. vo.setChildren(userByRoleVOS);
  1535. } else {
  1536. vo.setHasChildren(false);
  1537. vo.setIsLeaf(true);
  1538. vo.setChildren(new ArrayList<>());
  1539. }
  1540. list.add(vo);
  1541. }
  1542. }
  1543. return ActionResult.success(list);
  1544. }
  1545. /**
  1546. * 获取我的下属(不取子集)
  1547. *
  1548. * @param page 页面信息
  1549. * @return ignore
  1550. */
  1551. @Operation(summary = "获取我的下属(不取子集)")
  1552. @Parameters({
  1553. @Parameter(name = "page", description = "关键字", required = true)
  1554. })
  1555. @PostMapping("/getSubordinates")
  1556. public ActionResult<List<UserIdListVo>> getSubordinates(@RequestBody Page page) {
  1557. Map<String, OrganizeEntity> orgMaps = organizeService.getOrgMaps(null, false, null);
  1558. List<UserEntity> list = userService.getListByManagerId(UserProvider.getUser().getUserId(), page.getKeyword());
  1559. List<UserIdListVo> jsonToList = JsonUtil.getJsonToList(list, UserIdListVo.class);
  1560. Map<String, String> orgIdNameMaps = organizeService.getInfoList();
  1561. jsonToList.forEach(t -> {
  1562. t.setRealName(t.getRealName() + "/" + t.getAccount());
  1563. t.setFullName(t.getRealName());
  1564. List<UserRelationEntity> listByUserId = userRelationService.getListByUserId(t.getId()).stream().filter(ur -> PermissionConst.ORGANIZE.equals(ur.getObjectType())).collect(Collectors.toList());
  1565. StringJoiner stringJoiner = new StringJoiner(",");
  1566. listByUserId.forEach(tt -> {
  1567. OrganizeEntity organizeEntity = orgMaps.get(tt.getObjectId());
  1568. if (organizeEntity != null) {
  1569. String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/");
  1570. if (StringUtil.isNotEmpty(fullNameByOrgIdTree)) {
  1571. stringJoiner.add(fullNameByOrgIdTree);
  1572. }
  1573. }
  1574. });
  1575. t.setOrganize(stringJoiner.toString());
  1576. t.setHeadIcon(UploaderUtil.uploaderImg(t.getHeadIcon()));
  1577. });
  1578. return ActionResult.success(jsonToList);
  1579. }
  1580. /**
  1581. * 根据角色ID获取所属组织的所有成员
  1582. *
  1583. * @param pagination 分页模型
  1584. * @return
  1585. */
  1586. @Operation(summary = "根据角色ID获取所有成员")
  1587. @SaCheckPermission("permission.role")
  1588. @GetMapping("/getUsersByRoleId")
  1589. public ActionResult getUsersByRoleId(PaginationUser pagination) {
  1590. List<UserEntity> userList = new ArrayList<>();
  1591. if (roleService.getInfo(pagination.getRoleId()).getGlobalMark() == 1) {
  1592. userList.addAll(userService.getList(pagination, null, false, false, null, null));
  1593. } else {
  1594. // 根据roleId获取所有组织
  1595. userService.getListByRoleId(pagination.getRoleId()).forEach(u -> {
  1596. userList.add(userService.getInfo(u.getId()));
  1597. });
  1598. }
  1599. // 去重
  1600. List<UserEntity> afterUserList = userList.stream().distinct().collect(Collectors.toList());
  1601. if (StringUtil.isNotEmpty(pagination.getKeyword())) {
  1602. afterUserList = afterUserList.stream().filter(t -> t.getRealName().contains(pagination.getKeyword()) || t.getAccount().contains(pagination.getKeyword())).collect(Collectors.toList());
  1603. }
  1604. PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
  1605. return ActionResult.page(afterUserList, paginationVO);
  1606. }
  1607. /**
  1608. * 获取默认当前值用户ID
  1609. *
  1610. * @param userConditionModel 参数
  1611. * @return 执行结构
  1612. * @throws DataException ignore
  1613. */
  1614. @Operation(summary = "获取默认当前值用户ID")
  1615. @Parameters({
  1616. @Parameter(name = "userConditionModel", description = "参数", required = true)
  1617. })
  1618. @PostMapping("/getDefaultCurrentValueUserId")
  1619. public ActionResult<?> getDefaultCurrentValueUserId(@RequestBody UserConditionModel userConditionModel) throws DataException {
  1620. String userId = userService.getDefaultCurrentValueUserId(userConditionModel);
  1621. Map<String, Object> dataMap = new HashMap<String, Object>();
  1622. dataMap.put("userId", userId);
  1623. return ActionResult.success(MsgCode.SU022.get(), dataMap);
  1624. }
  1625. /**
  1626. * 工作交接
  1627. *
  1628. * @param workHandoverModel 模型
  1629. * @return 执行结构
  1630. */
  1631. @Operation(summary = "工作交接")
  1632. @SaCheckPermission("permission.user")
  1633. @Parameters({
  1634. @Parameter(name = "workHandoverModel", description = "模型", required = true)
  1635. })
  1636. @PostMapping("/workHandover")
  1637. public ActionResult<?> workHandover(@RequestBody @Valid WorkHandoverModel workHandoverModel) {
  1638. if (CollectionUtil.isEmpty(workHandoverModel.getAppList())
  1639. && CollectionUtil.isEmpty(workHandoverModel.getFlowList())
  1640. && CollectionUtil.isEmpty(workHandoverModel.getFlowTaskList())) {
  1641. return ActionResult.fail(MsgCode.PS042.get());
  1642. }
  1643. // 开始交接就禁用用户
  1644. UserEntity entity = userService.getInfo(workHandoverModel.getFromId());
  1645. if (StringUtil.isEmpty(workHandoverModel.getHandoverUser())) {
  1646. return ActionResult.fail(MsgCode.PS043.get());
  1647. }
  1648. if (StringUtil.isEmpty(workHandoverModel.getAppHandoverUser())) {
  1649. return ActionResult.fail(MsgCode.PS044.get());
  1650. }
  1651. UserEntity entitys = userService.getInfo(workHandoverModel.getHandoverUser());
  1652. if (entity == null || entitys == null) {
  1653. return ActionResult.fail(MsgCode.FA001.get());
  1654. }
  1655. if (workHandoverModel.getFromId().equals(workHandoverModel.getHandoverUser()) || workHandoverModel.getFromId().equals(workHandoverModel.getAppHandoverUser())) {
  1656. return ActionResult.fail(MsgCode.PS035.get());
  1657. }
  1658. if (ADMIN_KEY.equals(entitys.getAccount())) {
  1659. return ActionResult.fail(MsgCode.PS034.get());
  1660. }
  1661. try {
  1662. boolean flag = templateApi.flowWork(workHandoverModel);
  1663. if (!flag) {
  1664. return ActionResult.fail(MsgCode.FA101.get());
  1665. }
  1666. systemService.workHandover(workHandoverModel);
  1667. entity.setHandoverMark(1);
  1668. return ActionResult.success(MsgCode.PS033.get());
  1669. } finally {
  1670. userService.updateById(entity);
  1671. }
  1672. }
  1673. /**
  1674. * 获取用户工作详情
  1675. *
  1676. * @return 执行结构
  1677. */
  1678. @Operation(summary = "获取用户工作详情")
  1679. @SaCheckPermission("permission.user")
  1680. @Parameters({
  1681. @Parameter(name = "userId", description = "主键", required = true)
  1682. })
  1683. @GetMapping("/getWorkByUser")
  1684. public ActionResult<WorkHandoverVo> getWorkByUser(@RequestParam("fromId") String fromId) {
  1685. FlowWorkListVO flowWorkListVO = templateApi.flowWork(fromId);
  1686. if (flowWorkListVO == null) {
  1687. log.error("用户:" + fromId + ",待办事宜及负责流程获取失败");
  1688. flowWorkListVO = new FlowWorkListVO();
  1689. }
  1690. List<SystemEntity> authListByUser = systemService.getAuthListByUser(fromId, false);
  1691. // authListByUser = authListByUser.stream().filter(t -> !Objects.equals(t.getIsMain(), 1) && (fromId.equals(t.getUserId())
  1692. // || (StringUtil.isNotEmpty(t.getAuthorizeId()) && t.getAuthorizeId().contains(fromId)))).collect(Collectors.toList());
  1693. List<FlowWorkModel> sysList = JsonUtil.getJsonToList(authListByUser, FlowWorkModel.class);
  1694. Boolean isAppShow = CollectionUtil.isNotEmpty(sysList) ? true : false;
  1695. WorkHandoverVo workHandoverVo = new WorkHandoverVo(flowWorkListVO.getFlow(), flowWorkListVO.getFlowTask(), sysList, isAppShow);
  1696. return ActionResult.success(workHandoverVo);
  1697. }
  1698. // ----------------------------- 多租户调用
  1699. /**
  1700. * 重置管理员密码
  1701. *
  1702. * @param userResetPasswordForm 修改密码模型
  1703. * @return ignore
  1704. */
  1705. @Operation(summary = "重置管理员密码")
  1706. @Parameters({
  1707. @Parameter(name = "userResetPasswordForm", description = "修改密码模型", required = true)
  1708. })
  1709. @PutMapping("/Tenant/ResetPassword")
  1710. @NoDataSourceBind
  1711. public ActionResult<String> resetPassword(@RequestBody @Valid TenantReSetPasswordForm userResetPasswordForm) {
  1712. if (configValueUtil.isMultiTenancy()) {
  1713. TenantDataSourceUtil.switchTenant(userResetPasswordForm.getTenantId());
  1714. }
  1715. UserEntity entity = userService.getUserByAccount(ADMIN_KEY);
  1716. if (entity != null) {
  1717. entity.setPassword(userResetPasswordForm.getUserPassword());
  1718. userService.updatePassword(entity);
  1719. userService.logoutUser(MsgCode.PS011.get(), ImmutableList.of(entity.getId()));
  1720. entity.setPassword(userResetPasswordForm.getUserPassword());
  1721. PullUserUtil.syncUser(entity, "modifyPassword", userResetPasswordForm.getTenantId());
  1722. return ActionResult.success(MsgCode.SU005.get());
  1723. }
  1724. return ActionResult.fail(MsgCode.FA001.get());
  1725. }
  1726. /**
  1727. * 获取用户信息
  1728. *
  1729. * @param tenantId 租户号
  1730. * @return ignore
  1731. */
  1732. @Operation(summary = "获取用户信息")
  1733. @Parameters({
  1734. @Parameter(name = "tenantId", description = "租户号", required = true)
  1735. })
  1736. @NoDataSourceBind
  1737. @GetMapping("/Tenant/AdminInfo")
  1738. public AdminInfoVO adminInfo(@RequestParam("tenantId") String tenantId) throws DataException {
  1739. if (configValueUtil.isMultiTenancy()) {
  1740. TenantDataSourceUtil.switchTenant(tenantId);
  1741. }
  1742. UserEntity entity = userService.getUserByAccount(ADMIN_KEY);
  1743. AdminInfoVO adminInfoVO = JsonUtil.getJsonToBean(entity, AdminInfoVO.class);
  1744. return adminInfoVO;
  1745. }
  1746. /**
  1747. * 修改管理员信息
  1748. *
  1749. * @param adminInfoVO 模型
  1750. * @return ignore
  1751. */
  1752. @Operation(summary = "修改管理员信息")
  1753. @Parameters({
  1754. @Parameter(name = "adminInfoVO", description = "模型", required = true)
  1755. })
  1756. @NoDataSourceBind
  1757. @PutMapping("/Tenant/UpdateAdminInfo")
  1758. public ActionResult adminInfo(@RequestBody AdminInfoVO adminInfoVO) throws DataException {
  1759. if (configValueUtil.isMultiTenancy()) {
  1760. TenantDataSourceUtil.switchTenant(adminInfoVO.getTenantId());
  1761. }
  1762. UserEntity entity = userService.getUserByAccount(ADMIN_KEY);
  1763. if (entity == null) {
  1764. return ActionResult.fail(MsgCode.FA001.get());
  1765. }
  1766. entity.setRealName(adminInfoVO.getRealName());
  1767. entity.setMobilePhone(adminInfoVO.getMobilePhone());
  1768. entity.setEmail(adminInfoVO.getEmail());
  1769. userService.updateById(entity);
  1770. ThreadPoolExecutorUtil.getExecutor().execute(() -> {
  1771. try {
  1772. //修改用户之后判断是否需要同步到企业微信
  1773. synThirdQyService.updateUserSysToQy(false, entity, "", "");
  1774. //修改用户之后判断是否需要同步到钉钉
  1775. synThirdDingTalkService.updateUserSysToDing(false, entity, "");
  1776. } catch (Exception e) {
  1777. log.error("修改用户之后同步失败到企业微信或钉钉失败,异常:{}", e.getMessage());
  1778. }
  1779. });
  1780. // 删除在线的用户
  1781. PullUserUtil.syncUser(entity, "update", adminInfoVO.getTenantId());
  1782. return ActionResult.success(MsgCode.SU004.get());
  1783. }
  1784. /**
  1785. * 移除租户账号在线用户
  1786. *
  1787. * @param tenantId 租户号
  1788. * @return ignore
  1789. */
  1790. @Operation(summary = "移除租户账号在线用户")
  1791. @Parameters({
  1792. @Parameter(name = "tenantId", description = "租户号", required = true)
  1793. })
  1794. @NoDataSourceBind
  1795. @GetMapping("/Tenant/RemoveOnlineByTenantId")
  1796. public void removeOnlineByTenantId(@RequestParam("tenantId") String tenantId) throws DataException {
  1797. List<String> tokenList = new ArrayList<>();
  1798. List<String> tokens = UserProvider.getLoginUserListToken();
  1799. tokens.forEach(token -> {
  1800. UserInfo userInfo = UserProvider.getUser(token);
  1801. if (tenantId.equals(userInfo.getTenantId())) {
  1802. tokenList.add(token);
  1803. }
  1804. });
  1805. authService.kickoutByToken(tokenList.toArray(new String[0]));
  1806. }
  1807. //--------------------以下导入导出-----
  1808. @Operation(summary = "模板下载")
  1809. @SaCheckPermission("permission.user")
  1810. @GetMapping("/TemplateDownload")
  1811. public ActionResult<DownloadVO> TemplateDownload() {
  1812. UserColumnMap columnMap = new UserColumnMap();
  1813. String excelName = columnMap.getExcelName();
  1814. Map<String, String> keyMap = columnMap.getColumnByType(0);
  1815. List<ExcelColumnAttr> models = columnMap.getFieldsModel(false);
  1816. List<Map<String, Object>> list = columnMap.getDefaultList();
  1817. Map<String, String[]> optionMap = getOptionMap();
  1818. ExcelModel excelModel = ExcelModel.builder().models(models).selectKey(new ArrayList<>(keyMap.keySet())).optionMap(optionMap).build();
  1819. DownloadVO vo = ExcelTool.getImportTemplate(FileTypeConstant.TEMPORARY, excelName, keyMap, list, excelModel);
  1820. return ActionResult.success(vo);
  1821. }
  1822. @Operation(summary = "上传导入Excel")
  1823. @SaCheckPermission("permission.user")
  1824. @PostMapping("/Uploader")
  1825. public ActionResult<Object> Uploader() {
  1826. return ExcelTool.uploader();
  1827. }
  1828. @Operation(summary = "导入预览")
  1829. @SaCheckPermission("permission.user")
  1830. @GetMapping("/ImportPreview")
  1831. public ActionResult<Map<String, Object>> ImportPreview(String fileName) throws Exception {
  1832. // 导入字段
  1833. UserColumnMap columnMap = new UserColumnMap();
  1834. Map<String, String> keyMap = columnMap.getColumnByType(0);
  1835. Map<String, Object> headAndDataMap = ExcelTool.importPreview(FileTypeConstant.TEMPORARY, fileName, keyMap);
  1836. return ActionResult.success(headAndDataMap);
  1837. }
  1838. /**
  1839. * 导出异常报告
  1840. *
  1841. * @return
  1842. */
  1843. @Operation(summary = "导出异常报告")
  1844. @SaCheckPermission("permission.user")
  1845. @PostMapping("/ExportExceptionData")
  1846. public ActionResult<DownloadVO> ExportExceptionData(@RequestBody ExcelImportForm visualImportModel) {
  1847. List<Map<String, Object>> dataList = visualImportModel.getList();
  1848. UserColumnMap columnMap = new UserColumnMap();
  1849. String excelName = columnMap.getExcelName();
  1850. Map<String, String> keyMap = columnMap.getColumnByType(0);
  1851. List<ExcelColumnAttr> models = columnMap.getFieldsModel(true);
  1852. ExcelModel excelModel = ExcelModel.builder().optionMap(getOptionMap()).models(models).build();
  1853. DownloadVO vo = ExcelTool.exportExceptionReport(FileTypeConstant.TEMPORARY, excelName, keyMap, dataList, excelModel);
  1854. return ActionResult.success(vo);
  1855. }
  1856. /**
  1857. * 导入数据
  1858. *
  1859. * @return
  1860. */
  1861. @Operation(summary = "导入数据")
  1862. @SaCheckPermission("permission.user")
  1863. @PostMapping("/ImportData")
  1864. public ActionResult<ExcelImportVO> ImportData(@RequestBody ExcelImportForm visualImportModel) throws Exception {
  1865. List<Map<String, Object>> listData = new ArrayList<>();
  1866. List<Map<String, Object>> headerRow = new ArrayList<>();
  1867. if (visualImportModel.isType()) {
  1868. ActionResult result = ImportPreview(visualImportModel.getFileName());
  1869. if (result == null) {
  1870. throw new Exception(MsgCode.FA018.get());
  1871. }
  1872. if (result.getCode() != 200) {
  1873. throw new Exception(result.getMsg());
  1874. }
  1875. if (result.getData() instanceof Map) {
  1876. Map<String, Object> data = (Map<String, Object>) result.getData();
  1877. listData = (List<Map<String, Object>>) data.get("dataRow");
  1878. headerRow = (List<Map<String, Object>>) data.get("headerRow");
  1879. }
  1880. } else {
  1881. listData = visualImportModel.getList();
  1882. }
  1883. List<UserEntity> addList = new ArrayList<>();
  1884. List<Map<String, Object>> failList = new ArrayList<>();
  1885. // 对数据做校验
  1886. this.validateImportData(listData, addList, failList);
  1887. //正常数据插入
  1888. for (UserEntity each : addList) {
  1889. userService.create(each);
  1890. }
  1891. ExcelImportVO importModel = new ExcelImportVO();
  1892. importModel.setSnum(addList.size());
  1893. importModel.setFnum(failList.size());
  1894. importModel.setResultType(failList.size() > 0 ? 1 : 0);
  1895. importModel.setFailResult(failList);
  1896. importModel.setHeaderRow(headerRow);
  1897. return ActionResult.success(importModel);
  1898. }
  1899. /**
  1900. * 导出Excel
  1901. *
  1902. * @return
  1903. */
  1904. @Operation(summary = "导出Excel")
  1905. @SaCheckPermission("permission.user")
  1906. @GetMapping("/ExportData")
  1907. public ActionResult ExportData(PaginationUser pagination) throws IOException {
  1908. if (StringUtil.isEmpty(pagination.getSelectKey())) {
  1909. return ActionResult.fail(MsgCode.IMP011.get());
  1910. }
  1911. List<UserEntity> list = userService.getList(pagination, null, false, false, null, null);
  1912. Map<String, String> roleIdAndNameMap = roleService.getList(false, PermissionConst.USER, null)
  1913. .stream().collect(Collectors.toMap(RoleEntity::getId, t -> t.getFullName() + "/" + t.getEnCode()));
  1914. Map<Object, String> posIdAndName = positionService.getPosEncodeAndName(true).entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));
  1915. Map<Object, String> groupEncodeMap = groupService.getGroupEncodeMap(true).entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));
  1916. Map<String, String> orgMap = organizeService.getAllOrgsTreeName(true);
  1917. Map<Object, String> userNameMap = userService.getUserNameAndIdMap(true).entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));
  1918. //性别
  1919. Map<String, String> sexMap = dictionaryDataApi.getByTypeCodeEnable(DictionaryDataEnum.SEX_TYPE.getDictionaryTypeId())
  1920. .stream().collect(Collectors.toMap(DictionaryDataEntity::getEnCode, DictionaryDataEntity::getFullName));
  1921. //职级
  1922. Map<String, String> ranksMap = dictionaryDataApi.getByTypeCodeEnable(DictionaryDataEnum.RANK.getDictionaryTypeId())
  1923. .stream().collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName));
  1924. //民族
  1925. Map<String, String> nationMap = dictionaryDataApi.getByTypeCodeEnable(DictionaryDataEnum.NATION.getDictionaryTypeId())
  1926. .stream().collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName));
  1927. //证件类型
  1928. Map<String, String> certificatesTypeMap = dictionaryDataApi.getByTypeCodeEnable(DictionaryDataEnum.CERTIFICATE_TYPE.getDictionaryTypeId())
  1929. .stream().collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName));
  1930. //文化程度
  1931. Map<String, String> educationMap = dictionaryDataApi.getByTypeCodeEnable(DictionaryDataEnum.EDUCATION.getDictionaryTypeId())
  1932. .stream().collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName));
  1933. List<RoleRelationEntity> roleRelationList = roleRelationService.getListByRoleId("", PermissionConst.USER);
  1934. List<UserRelationEntity> userRelationList = userRelationService.getListByObjectType(PermissionConst.POSITION);
  1935. List<Map<String, Object>> realList = new ArrayList<>();
  1936. for (UserEntity entity : list) {
  1937. entity.setHeadIcon(UploaderUtil.uploaderImg(entity.getHeadIcon()));
  1938. //获取角色
  1939. List<RoleRelationEntity> userRoleRelation = roleRelationList.stream().filter(t -> t.getObjectId().equals(entity.getId())).collect(Collectors.toList());
  1940. List<String> roleIdList = new ArrayList<>();
  1941. for (RoleRelationEntity ure : userRoleRelation) {
  1942. if (StringUtil.isNotEmpty(roleIdAndNameMap.get(ure.getRoleId()))) {
  1943. roleIdList.add(roleIdAndNameMap.get(ure.getRoleId()));
  1944. }
  1945. }
  1946. entity.setRoleId(String.join(",", roleIdList));
  1947. // 岗位装配
  1948. List<UserRelationEntity> userPosRelation = userRelationList.stream().filter(t -> t.getUserId().equals(entity.getId())).collect(Collectors.toList());
  1949. List<String> positionIds = new ArrayList<>();
  1950. for (UserRelationEntity ure : userPosRelation) {
  1951. if (posIdAndName.containsKey(ure.getObjectId())) {
  1952. positionIds.add(posIdAndName.get(ure.getObjectId()));
  1953. }
  1954. }
  1955. entity.setPositionId(String.join(",", positionIds));
  1956. //性别
  1957. entity.setGender(sexMap.get(entity.getGender()));
  1958. entity.setRanks(ranksMap.get(entity.getRanks()));
  1959. entity.setNation(nationMap.get(entity.getNation()));
  1960. entity.setCertificatesType(certificatesTypeMap.get(entity.getCertificatesType()));
  1961. entity.setEducation(educationMap.get(entity.getEducation()));
  1962. Map<String, Object> obj = JsonUtil.entityToMap(entity);
  1963. if (obj.get("enabledMark") != null) {
  1964. String stateName = "";
  1965. if (Objects.equals(obj.get("enabledMark"), 0)) {
  1966. stateName = "禁用";
  1967. } else if (Objects.equals(obj.get("enabledMark"), 1)) {
  1968. stateName = "启用";
  1969. } else if (Objects.equals(obj.get("enabledMark"), 2)) {
  1970. stateName = "锁定";
  1971. }
  1972. obj.put("enabledMark", stateName);
  1973. }
  1974. if (obj.get("birthday") != null) {
  1975. obj.put("birthday", DateUtil.daFormat(Long.parseLong(obj.get("birthday").toString())));
  1976. }
  1977. if (obj.get("entryDate") != null) {
  1978. obj.put("entryDate", DateUtil.daFormat(Long.parseLong(obj.get("entryDate").toString())));
  1979. }
  1980. realList.add(obj);
  1981. }
  1982. String[] keys = !StringUtil.isEmpty(pagination.getSelectKey()) ? pagination.getSelectKey() : new String[0];
  1983. UserColumnMap columnMap = new UserColumnMap();
  1984. String excelName = columnMap.getExcelName();
  1985. List<ExcelColumnAttr> models = columnMap.getFieldsModel(false);
  1986. Map<String, String> keyMap = columnMap.getColumnByType(null);
  1987. ExcelModel excelModel = ExcelModel.builder().selectKey(Arrays.asList(keys)).models(models).build();
  1988. DownloadVO vo = ExcelTool.creatModelExcel(FileTypeConstant.TEMPORARY, excelName, keyMap, realList, excelModel);
  1989. return ActionResult.success(vo);
  1990. }
  1991. /**
  1992. * 导入验证
  1993. *
  1994. * @param listData
  1995. * @param addList
  1996. * @param failList
  1997. */
  1998. private void validateImportData(List<Map<String, Object>> listData, List<UserEntity> addList, List<Map<String, Object>> failList) {
  1999. UserColumnMap columnMap = new UserColumnMap();
  2000. Map<String, String> keyMap = columnMap.getColumnByType(0);
  2001. List<DictionaryDataEntity> sexList = dictionaryDataApi.getListByTypeDataCode(DictionaryDataEnum.SEX_TYPE.getDictionaryTypeId());
  2002. Map<String, String> genderMap = sexList.stream().collect(Collectors.toMap(DictionaryDataEntity::getFullName, DictionaryDataEntity::getEnCode));
  2003. List<DictionaryDataEntity> rankList = dictionaryDataApi.getListByTypeDataCode(DictionaryDataEnum.RANK.getDictionaryTypeId());
  2004. Map<String, String> ranksMap = rankList.stream().collect(Collectors.toMap(DictionaryDataEntity::getFullName, DictionaryDataEntity::getId));
  2005. List<DictionaryDataEntity> nationList = dictionaryDataApi.getListByTypeDataCode(DictionaryDataEnum.NATION.getDictionaryTypeId());
  2006. Map<String, String> nationMap = nationList.stream().collect(Collectors.toMap(DictionaryDataEntity::getFullName, DictionaryDataEntity::getId));
  2007. List<DictionaryDataEntity> certificateList = dictionaryDataApi.getListByTypeDataCode(DictionaryDataEnum.CERTIFICATE_TYPE.getDictionaryTypeId());
  2008. Map<String, String> certificateMap = certificateList.stream().collect(Collectors.toMap(DictionaryDataEntity::getFullName, DictionaryDataEntity::getId));
  2009. List<DictionaryDataEntity> educationList = dictionaryDataApi.getListByTypeDataCode(DictionaryDataEnum.EDUCATION.getDictionaryTypeId());
  2010. Map<String, String> educationMap = educationList.stream().collect(Collectors.toMap(DictionaryDataEntity::getFullName, DictionaryDataEntity::getId));
  2011. Map<String, Object> allOrgsTreeName = organizeService.getAllOrgsTreeName();
  2012. Map<String, Object> userNameMap = userService.getUserNameAndIdMap();
  2013. List<PositionEntity> allPos = positionService.getList(true);
  2014. Map<String, Object> posNameMap = positionService.getPosEncodeAndName(true);
  2015. List<RoleEntity> allUserRole = roleService.getList(true, PermissionConst.USER, null);
  2016. Map<String, String> roleMap = allUserRole.stream().collect(Collectors.toMap(t -> t.getFullName(), RoleEntity::getId));
  2017. //所有岗位的用户列表
  2018. List<UserRelationEntity> posAllUser = userRelationService.getListByObjectType(PermissionConst.POSITION);
  2019. //所有用户角色的用户列表
  2020. List<RoleRelationEntity> roleAllUser = roleRelationService.getListByRoleId("", PermissionConst.USER);
  2021. //角色用户数量
  2022. Map<String, Integer> roleIdUserNum = new HashMap<>();
  2023. for (int i = 0, len = listData.size(); i < len; i++) {
  2024. Map<String, Object> eachMap = listData.get(i);
  2025. Map<String, Object> realMap = JsonUtil.getJsonToBean(eachMap, Map.class);
  2026. StringJoiner errInfo = new StringJoiner(",");
  2027. // 开启多租住的-判断用户额度
  2028. String tenantId = UserProvider.getUser().getTenantId();
  2029. if (StringUtil.isNotEmpty(tenantId)) {
  2030. TenantVO cacheTenantInfo = TenantDataSourceUtil.getCacheTenantInfo(tenantId);
  2031. long count = userService.count() + addList.size();
  2032. if (cacheTenantInfo.getAccountNum() != 0 && cacheTenantInfo.getAccountNum() < count) {
  2033. eachMap.put("errorsInfo", MsgCode.PS009.get());
  2034. failList.add(eachMap);
  2035. continue;
  2036. }
  2037. }
  2038. //组织多选id,用于查询角色和岗位
  2039. StringJoiner organizeIds = new StringJoiner(",");
  2040. for (String column : keyMap.keySet()) {
  2041. Object valueObj = eachMap.get(column);
  2042. String value = valueObj == null ? null : String.valueOf(valueObj);
  2043. String columnName = keyMap.get(column);
  2044. switch (column) {
  2045. case "gender":
  2046. if (StringUtil.isEmpty(value)) {
  2047. errInfo.add(columnName + "不能为空");
  2048. break;
  2049. }
  2050. if (genderMap.containsKey(valueObj.toString())) {
  2051. realMap.put("gender", genderMap.get(value));
  2052. } else {
  2053. errInfo.add("找不到该" + columnName + "值");
  2054. }
  2055. break;
  2056. case "ranks":
  2057. if (StringUtil.isNotEmpty(value)) {
  2058. if (ranksMap.containsKey(valueObj.toString())) {
  2059. realMap.put("ranks", ranksMap.get(value));
  2060. } else {
  2061. errInfo.add("找不到该" + columnName + "值");
  2062. }
  2063. }
  2064. break;
  2065. case "nation":
  2066. if (StringUtil.isNotEmpty(value)) {
  2067. if (nationMap.containsKey(valueObj.toString())) {
  2068. realMap.put("nation", nationMap.get(value));
  2069. } else {
  2070. errInfo.add("找不到该" + columnName + "值");
  2071. }
  2072. }
  2073. break;
  2074. case "certificatesType":
  2075. if (StringUtil.isNotEmpty(value)) {
  2076. if (certificateMap.containsKey(valueObj.toString())) {
  2077. realMap.put("certificatesType", certificateMap.get(value));
  2078. } else {
  2079. errInfo.add("找不到该" + columnName + "值");
  2080. }
  2081. }
  2082. break;
  2083. case "education":
  2084. if (StringUtil.isNotEmpty(value)) {
  2085. if (educationMap.containsKey(valueObj.toString())) {
  2086. realMap.put("education", educationMap.get(value));
  2087. } else {
  2088. errInfo.add("找不到该" + columnName + "值");
  2089. }
  2090. }
  2091. break;
  2092. case "account":
  2093. //账号
  2094. if (StringUtil.isEmpty(value)) {
  2095. errInfo.add(columnName + "不能为空");
  2096. break;
  2097. }
  2098. if (value.length() > 50) {
  2099. errInfo.add(columnName + "值超出最多输入字符限制");
  2100. }
  2101. //值不能含有特殊符号
  2102. if (!RegexUtils.checkSpecoalSymbols(value)) {
  2103. errInfo.add(columnName + "值不能含有特殊符号");
  2104. }
  2105. //库里重复
  2106. if (userService.isExistByAccount(value)) {
  2107. errInfo.add(columnName + "值已存在");
  2108. break;
  2109. }
  2110. //表格内重复
  2111. long enCodeCount = addList.stream().filter(t -> t.getAccount().equals(value)).count();
  2112. if (enCodeCount > 0) {
  2113. errInfo.add(columnName + "值已存在");
  2114. break;
  2115. }
  2116. break;
  2117. case "realName":
  2118. if (StringUtil.isEmpty(value)) {
  2119. errInfo.add(columnName + "不能为空");
  2120. break;
  2121. }
  2122. if (value.length() > 50) {
  2123. errInfo.add(columnName + "值超出最多输入字符限制");
  2124. }
  2125. //值不能含有特殊符号
  2126. if (!RegexUtils.checkSpecoalSymbols(value)) {
  2127. errInfo.add(columnName + "值不能含有特殊符号");
  2128. }
  2129. break;
  2130. case "positionId":
  2131. if (StringUtil.isNotEmpty(value)) {
  2132. List<String> posIds = new ArrayList<>();
  2133. List<String> posErrList = new ArrayList<>();
  2134. List<String> listName = Arrays.asList(value.split(","));
  2135. for (String item : listName) {
  2136. if (posNameMap.containsKey(item)) {
  2137. posIds.add(posNameMap.get(item).toString());
  2138. } else {
  2139. posErrList.add(item);
  2140. }
  2141. }
  2142. if (posErrList.size() > 0) {
  2143. if (listName.size() > 1) {
  2144. errInfo.add("找不到该" + columnName + "(" + String.join("、", posErrList) + ")");
  2145. break;
  2146. } else if (listName.size() == 1) {
  2147. errInfo.add("找不到该" + columnName);
  2148. break;
  2149. }
  2150. }
  2151. if (CollectionUtil.isNotEmpty(posIds)) {
  2152. //判断约束
  2153. for (String item : posIds) {
  2154. PositionEntity info = allPos.stream().filter(t -> t.getId().equals(item)).findFirst().orElse(null);
  2155. //库里岗位用户数
  2156. List<UserRelationEntity> thisPosUsers = posAllUser.stream().filter(t -> t.getObjectId().equals(item)).collect(Collectors.toList());
  2157. //表格里的岗位用户数
  2158. List<UserEntity> excelUserList = addList.stream().filter(t -> t.getPositionId() != null && t.getPositionId().contains(item)).collect(Collectors.toList());
  2159. Integer userNum = thisPosUsers.size() + excelUserList.size();
  2160. if (Objects.equals(info.getIsCondition(), 1)) {
  2161. PosConModel conModelP = JsonUtil.getJsonToBean(info.getConditionJson(), PosConModel.class);
  2162. conModelP.init();
  2163. if (conModelP.getMutualExclusionFlag() && conModelP.getMutualExclusion().stream().anyMatch(t -> posIds.contains(t))) {
  2164. errInfo.add(info.getFullName() + "存在互斥岗位");
  2165. break;
  2166. }
  2167. if (conModelP.getNumFlag() && userNum >= conModelP.getUserNum()) {
  2168. errInfo.add(info.getFullName() + "岗位已达用户限制个数");
  2169. break;
  2170. }
  2171. if (conModelP.getPrerequisiteFlag() && !posIds.containsAll(conModelP.getPrerequisite())) {
  2172. errInfo.add(info.getFullName() + "存在先决岗位");
  2173. break;
  2174. }
  2175. }
  2176. }
  2177. realMap.put("positionId", String.join(",", posIds));
  2178. Set<String> orgList = allPos.stream().filter(t -> posIds.contains(t)).map(PositionEntity::getOrganizeId).collect(Collectors.toSet());
  2179. realMap.put("organizeId", String.join(",", orgList));
  2180. break;
  2181. }
  2182. break;
  2183. }
  2184. break;
  2185. case "roleId":
  2186. if (StringUtil.isNotEmpty(value)) {
  2187. List<String> roleIds = new ArrayList<>();
  2188. List<String> roleErrList = new ArrayList<>();
  2189. List<String> listName = Arrays.asList(value.split(","));
  2190. for (String item : listName) {
  2191. if (roleMap.containsKey(item)) {
  2192. roleIds.add(roleMap.get(item));
  2193. } else {
  2194. roleErrList.add(item);
  2195. }
  2196. }
  2197. if (roleErrList.size() > 0) {
  2198. if (listName.size() > 1) {
  2199. errInfo.add("找不到该" + columnName + "(" + String.join("、", roleErrList) + ")");
  2200. break;
  2201. } else if (listName.size() == 1) {
  2202. errInfo.add("找不到该" + columnName);
  2203. break;
  2204. }
  2205. }
  2206. if (CollectionUtil.isNotEmpty(roleIds)) {
  2207. //判断约束
  2208. for (String item : roleIds) {
  2209. RoleEntity info = allUserRole.stream().filter(t -> t.getId().equals(item)).findFirst().orElse(null);
  2210. List<RoleRelationEntity> thisRoleUsers = roleAllUser.stream().filter(t -> t.getRoleId().equals(item)).collect(Collectors.toList());
  2211. //表格里的岗位用户数
  2212. List<UserEntity> excelUserList = addList.stream().filter(t -> t.getRoleId() != null && t.getRoleId().contains(item)).collect(Collectors.toList());
  2213. Integer userNum = thisRoleUsers.size() + excelUserList.size();
  2214. if (Objects.equals(info.getIsCondition(), 1)) {
  2215. PosConModel conModelP = JsonUtil.getJsonToBean(info.getConditionJson(), PosConModel.class);
  2216. conModelP.init();
  2217. if (conModelP.getMutualExclusionFlag() && conModelP.getMutualExclusion().stream().anyMatch(t -> roleIds.contains(t))) {
  2218. errInfo.add(info.getFullName() + "存在互斥角色");
  2219. break;
  2220. }
  2221. if (conModelP.getNumFlag() && userNum >= conModelP.getUserNum()) {
  2222. errInfo.add(info.getFullName() + "角色已达用户限制个数");
  2223. break;
  2224. }
  2225. if (conModelP.getPrerequisiteFlag() && !roleIds.containsAll(conModelP.getPrerequisite())) {
  2226. errInfo.add(info.getFullName() + "存在先决角色");
  2227. break;
  2228. }
  2229. }
  2230. }
  2231. realMap.put("roleId", String.join(",", roleIds));
  2232. break;
  2233. }
  2234. }
  2235. break;
  2236. case "entryDate":
  2237. if (StringUtil.isNotEmpty(value)) {
  2238. Date date = DateUtil.checkDate(value, "yyyy-MM-dd");
  2239. if (date == null) {
  2240. errInfo.add(columnName + "值不正确");
  2241. break;
  2242. }
  2243. realMap.put("entryDate", date);
  2244. }
  2245. break;
  2246. case "birthday":
  2247. if (StringUtil.isNotEmpty(value)) {
  2248. Date date = DateUtil.checkDate(value, "yyyy-MM-dd");
  2249. if (date == null) {
  2250. errInfo.add(columnName + "值不正确");
  2251. break;
  2252. }
  2253. realMap.put("birthday", date);
  2254. }
  2255. break;
  2256. case "sortCode":
  2257. if (StringUtil.isEmpty(value)) {
  2258. realMap.put("sortCode", 0);
  2259. break;
  2260. }
  2261. Long numValue = 0l;
  2262. try {
  2263. numValue = Long.parseLong(value);
  2264. } catch (Exception e) {
  2265. errInfo.add(columnName + "值不正确");
  2266. break;
  2267. }
  2268. if (numValue < 0) {
  2269. errInfo.add(columnName + "值不能小于0");
  2270. break;
  2271. }
  2272. if (numValue > 1000000) {
  2273. errInfo.add(columnName + "值不能大于999999");
  2274. break;
  2275. }
  2276. break;
  2277. case "enabledMark":
  2278. if (StringUtil.isEmpty(value)) {
  2279. errInfo.add(columnName + "不能为空");
  2280. break;
  2281. }
  2282. if ("启用".equals(value)) {
  2283. realMap.put("enabledMark", 1);
  2284. } else if ("禁用".equals(value)) {
  2285. realMap.put("enabledMark", 0);
  2286. } else if ("锁定".equals(value)) {
  2287. realMap.put("enabledMark", 2);
  2288. } else {
  2289. errInfo.add("找不到该" + columnName + "值");
  2290. }
  2291. break;
  2292. default:
  2293. break;
  2294. }
  2295. }
  2296. if (errInfo.length() == 0) {
  2297. UserEntity entity = JsonUtil.getJsonToBean(realMap, UserEntity.class);
  2298. entity.setCreatorTime(new Date());
  2299. addList.add(entity);
  2300. } else {
  2301. eachMap.put("errorsInfo", errInfo.toString());
  2302. failList.add(eachMap);
  2303. }
  2304. }
  2305. }
  2306. private CheckResult checkOrganizeId(String organizeName, Map<String, Object> allOrgsTreeName) {
  2307. for (String key : allOrgsTreeName.keySet()) {
  2308. Object o = allOrgsTreeName.get(key);
  2309. if (organizeName.equals(o.toString())) {
  2310. String[] split = key.split(",");
  2311. return new CheckResult(true, null, split[split.length - 1]);
  2312. }
  2313. }
  2314. return new CheckResult(false, "所属组织不正确", null);
  2315. }
  2316. /**
  2317. * 获取下拉框
  2318. *
  2319. * @return
  2320. */
  2321. private Map<String, String[]> getOptionMap() {
  2322. Map<String, String[]> optionMap = new HashMap<>();
  2323. //性别
  2324. List<DictionaryDataEntity> sexList = dictionaryDataApi.getByTypeCodeEnable(DictionaryDataEnum.SEX_TYPE.getDictionaryTypeId());
  2325. String[] gender = sexList.stream().map(DictionaryDataEntity::getFullName).toArray(String[]::new);
  2326. optionMap.put("gender", gender);
  2327. //职级
  2328. List<DictionaryDataEntity> ranksList = dictionaryDataApi.getByTypeCodeEnable(DictionaryDataEnum.RANK.getDictionaryTypeId());
  2329. String[] ranks = ranksList.stream().map(DictionaryDataEntity::getFullName).toArray(String[]::new);
  2330. optionMap.put("ranks", ranks);
  2331. //状态
  2332. optionMap.put("enabledMark", new String[]{"启用", "禁用", "锁定"});
  2333. //民族
  2334. List<DictionaryDataEntity> nationList = dictionaryDataApi.getByTypeCodeEnable(DictionaryDataEnum.NATION.getDictionaryTypeId());
  2335. String[] nation = nationList.stream().map(DictionaryDataEntity::getFullName).toArray(String[]::new);
  2336. optionMap.put("nation", nation);
  2337. //证件类型
  2338. List<DictionaryDataEntity> certificatesTypeList = dictionaryDataApi.getByTypeCodeEnable(DictionaryDataEnum.CERTIFICATE_TYPE.getDictionaryTypeId());
  2339. String[] certificatesType = certificatesTypeList.stream().map(DictionaryDataEntity::getFullName).toArray(String[]::new);
  2340. optionMap.put("certificatesType", certificatesType);
  2341. //文化程度
  2342. List<DictionaryDataEntity> educationList = dictionaryDataApi.getByTypeCodeEnable(DictionaryDataEnum.EDUCATION.getDictionaryTypeId());
  2343. String[] education = educationList.stream().map(DictionaryDataEntity::getFullName).toArray(String[]::new);
  2344. optionMap.put("education", education);
  2345. return optionMap;
  2346. }
  2347. }