UserSettingController.java 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  1. package jnpf.permission.controller;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollectionUtil;
  4. import cn.hutool.core.util.ObjectUtil;
  5. import cn.hutool.http.HttpRequest;
  6. import cn.hutool.http.HttpResponse;
  7. import com.alibaba.fastjson.JSON;
  8. import com.google.common.collect.ImmutableList;
  9. import com.google.common.collect.ImmutableMap;
  10. import io.swagger.v3.oas.annotations.Operation;
  11. import io.swagger.v3.oas.annotations.Parameter;
  12. import io.swagger.v3.oas.annotations.Parameters;
  13. import io.swagger.v3.oas.annotations.tags.Tag;
  14. import jakarta.validation.Valid;
  15. import jnpf.base.ActionResult;
  16. import jnpf.base.ActionResultCode;
  17. import jnpf.base.UserInfo;
  18. import jnpf.base.entity.DictionaryDataEntity;
  19. import jnpf.base.entity.PrintDevEntity;
  20. import jnpf.base.entity.SystemEntity;
  21. import jnpf.base.model.base.SystemBaeModel;
  22. import jnpf.base.model.button.ButtonModel;
  23. import jnpf.base.model.column.ColumnModel;
  24. import jnpf.base.model.form.ModuleFormModel;
  25. import jnpf.base.model.module.ModuleModel;
  26. import jnpf.base.model.portalManage.PortalManagePage;
  27. import jnpf.base.model.portalManage.PortalManagePageDO;
  28. import jnpf.base.model.portalManage.PortalModel;
  29. import jnpf.base.model.print.PaginationPrint;
  30. import jnpf.base.model.resource.ResourceModel;
  31. import jnpf.base.model.sign.SignForm;
  32. import jnpf.base.model.sign.SignListVO;
  33. import jnpf.base.service.*;
  34. import jnpf.base.service.impl.UserOnlineServiceImpl;
  35. import jnpf.base.vo.PageListVO;
  36. import jnpf.base.vo.PaginationVO;
  37. import jnpf.config.ConfigValueUtil;
  38. import jnpf.constant.AuthorizeConst;
  39. import jnpf.constant.JnpfConst;
  40. import jnpf.constant.MsgCode;
  41. import jnpf.constant.PermissionConst;
  42. import jnpf.consts.DeviceType;
  43. import jnpf.entity.LogEntity;
  44. import jnpf.flowable.entity.TemplateEntity;
  45. import jnpf.flowable.model.template.TemplateTreeListVo;
  46. import jnpf.message.model.UserOnlineModel;
  47. import jnpf.message.model.websocket.UserOnLineModelVo;
  48. import jnpf.model.PaginationLogModel;
  49. import jnpf.model.UserLogVO;
  50. import jnpf.permission.entity.*;
  51. import jnpf.permission.model.authorize.AuthorizeModel;
  52. import jnpf.permission.model.position.PosistionCurrentModel;
  53. import jnpf.permission.model.user.UserAuthForm;
  54. import jnpf.permission.model.user.form.*;
  55. import jnpf.permission.model.user.mod.UserAuthorizeModel;
  56. import jnpf.permission.model.user.vo.UserAuthorizeVO;
  57. import jnpf.permission.model.user.vo.UserBaseInfoVO;
  58. import jnpf.permission.model.user.vo.UserSubordinateVO;
  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.LogService;
  64. import jnpf.util.*;
  65. import jnpf.util.treeutil.ListToTreeUtil;
  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.util.*;
  73. import java.util.stream.Collectors;
  74. /**
  75. * 个人资料
  76. *
  77. * @author JNPF开发平台组
  78. * @version V3.1.0
  79. * @copyright 引迈信息技术有限公司
  80. * @date 2019年9月26日 上午9:18
  81. */
  82. @Tag(name = "个人资料", description = "CurrentUsersInfo")
  83. @RestController
  84. @RequestMapping("/api/permission/Users/Current")
  85. @Slf4j
  86. public class UserSettingController {
  87. public final static String APP_CODE = "APP";
  88. public final static String PC_CODE = "PC";
  89. @Autowired
  90. private UserService userService;
  91. @Autowired
  92. private AuthorizeService authorizeService;
  93. @Autowired
  94. private LogService logService;
  95. @Autowired
  96. private RedisUtil redisUtil;
  97. @Autowired
  98. private PositionService positionService;
  99. @Autowired
  100. private OrganizeService organizeService;
  101. @Autowired
  102. private CacheKeyUtil cacheKeyUtil;
  103. @Autowired
  104. private UserRelationService userRelationService;
  105. @Autowired
  106. private SystemService systemService;
  107. @Autowired
  108. private SignService signService;
  109. @Autowired
  110. private SysconfigService sysConfigApi;
  111. @Autowired
  112. private UserOldPasswordService userOldPasswordService;
  113. @Autowired
  114. private OrganizeAdministratorService organizeAdministratorService;
  115. @Autowired
  116. private PermissionGroupService permissionGroupService;
  117. @Autowired
  118. private ConfigValueUtil configValueUtil;
  119. @Autowired
  120. private DictionaryDataService dictionaryDataApi;
  121. @Autowired
  122. private TemplateApi templateApi;
  123. @Autowired
  124. private PortalManageService portalManageApi;
  125. @Autowired
  126. private PrintDevService printDevApi;
  127. @Autowired
  128. private UserExtraService userExtraService;
  129. @Autowired
  130. private AuthPermUtil authPermUtil;
  131. @Autowired
  132. private RoleRelationService roleRelationService;
  133. /**
  134. * 我的信息
  135. *
  136. * @return
  137. */
  138. @Operation(summary = "个人资料")
  139. @GetMapping("/BaseInfo")
  140. public ActionResult<UserBaseInfoVO> get() {
  141. UserInfo userInfo = UserProvider.getUser();
  142. UserEntity userEntity = userService.getInfo(userInfo.getUserId());
  143. //获取用户额外信息
  144. UserExtraEntity userExtraEntity = userExtraService.getUserExtraByUserId(userEntity.getId());
  145. String catchKey = cacheKeyUtil.getAllUser();
  146. if (redisUtil.exists(catchKey)) {
  147. redisUtil.remove(catchKey);
  148. }
  149. UserBaseInfoVO vo = JsonUtil.getJsonToBean(userEntity, UserBaseInfoVO.class);
  150. BeanUtil.copyProperties(userExtraEntity, vo);
  151. if (StringUtil.isNotEmpty(userEntity.getManagerId())) {
  152. UserEntity menager = userService.getInfo(userEntity.getManagerId());
  153. vo.setManager(menager != null && !ObjectUtil.equal(menager.getEnabledMark(), 0) ? menager.getRealName() + "/" + menager.getAccount() : "");
  154. }
  155. //设置语言和主题
  156. vo.setLanguage(userEntity.getLanguage() != null ? userEntity.getLanguage() : "zh-CN");
  157. vo.setTheme(userEntity.getTheme() != null ? userEntity.getTheme() : "W-001");
  158. // 获取组织
  159. vo.setOrganize(PermissionUtil.getLinkInfoByOrgId(userInfo.getOrganizeId(), organizeService, false));
  160. // 获取主要岗位
  161. List<PositionEntity> positionEntityList = positionService.getListByOrgIdAndUserId(userInfo.getOrganizeId(), userEntity.getId());
  162. if (positionEntityList.size() > 0) {
  163. List<String> fullNames = positionEntityList.stream().map(PositionEntity::getFullName).collect(Collectors.toList());
  164. vo.setPosition(String.join(",", fullNames));
  165. }
  166. // 获取用户
  167. if (StringUtil.isNotEmpty(userInfo.getTenantId())) {
  168. vo.setAccount(userInfo.getTenantId() + "@" + vo.getAccount());
  169. }
  170. // 获取用户头像
  171. if (!StringUtil.isEmpty(userInfo.getUserIcon())) {
  172. vo.setAvatar(UploaderUtil.uploaderImg(userInfo.getUserIcon()));
  173. }
  174. vo.setBirthday(userEntity.getBirthday() != null ? userEntity.getBirthday().getTime() : null);
  175. DictionaryDataEntity dictionaryDataEntity3 = dictionaryDataApi.getInfo(userEntity.getRanks());
  176. vo.setRanks(dictionaryDataEntity3 != null && ObjectUtil.equal(dictionaryDataEntity3.getEnabledMark(), 1) ? dictionaryDataEntity3.getFullName() : null);
  177. // 多租户
  178. String tenantId = UserProvider.getUser().getTenantId();
  179. Map<String, String> headers = Collections.EMPTY_MAP;
  180. try {
  181. String ip = IpUtil.getIpAddr();
  182. if (StringUtil.isNotEmpty(ip) && !Objects.equals("127.0.0.1", ip)) {
  183. headers = ImmutableMap.of("X-Forwarded-For", ip);
  184. }
  185. } catch (Exception e) {
  186. }
  187. if (StringUtil.isNotEmpty(tenantId)) {
  188. vo.setIsTenant(true);
  189. try (HttpResponse execute = HttpRequest.get(configValueUtil.getMultiTenancyUrl() + "GetTenantInfo/" + tenantId)
  190. .addHeaders(headers)
  191. .execute()) {
  192. vo.setCurrentTenantInfo(JSON.parseObject(execute.body()));
  193. } catch (Exception e) {
  194. log.error("获取远端多租户信息失败: {}", e.getMessage());
  195. }
  196. }
  197. //获取在线用户
  198. List<UserOnlineModel> userOnlineModels = UserOnlineServiceImpl.getUserOnlineModels();
  199. Map<String, List<UserOnLineModelVo>> collect = userOnlineModels.stream()
  200. .filter(it -> it.getUserId().equals(userInfo.getUserId()))
  201. .map(it -> {
  202. UserOnLineModelVo userOnLineModelVo = JsonUtil.getJsonToBean(it, UserOnLineModelVo.class);
  203. userOnLineModelVo.setIsCurrent(it.getToken().equals(UserProvider.getUser().getToken().replace("bearer ", "")));
  204. return userOnLineModelVo;
  205. })
  206. .collect(Collectors.groupingBy(UserOnLineModelVo::getDevice));
  207. vo.setPcOnlineModelList(Optional.ofNullable(collect.get(PC_CODE)).orElse(Collections.emptyList()));
  208. vo.setAppOnlineModelList(Optional.ofNullable(collect.get(APP_CODE)).orElse(Collections.emptyList()));
  209. return ActionResult.success(vo);
  210. }
  211. /**
  212. * 我的权限
  213. *
  214. * @return
  215. */
  216. @Operation(summary = "系统权限")
  217. @GetMapping("/Authorize")
  218. public ActionResult<UserAuthorizeVO> getList() {
  219. // 根据应用过滤权限
  220. // List<AuthorizeEntity> authorizeList = new ArrayList<>();
  221. // String appCode = RequestContext.getAppCode();
  222. // SystemEntity infoByEnCode = systemService.getInfoByEnCode(appCode);
  223. // //系统权限
  224. // AuthorizeVO authorizeModel = authorizeService.getAuthorize(false, appCode, 0);
  225. // //赋值图标
  226. // Map<String, ModuleModel> moduleMap = this.moduleList(authorizeModel.getModuleList());
  227. // UserInfo userInfo = UserProvider.getUser();
  228. //
  229. // List<ModuleModel> moduleList = authorizeModel.getModuleList();
  230. // moduleList = moduleList.stream().filter(t -> t != null && StringUtil.isNotEmpty(t.getSystemId()) && t.getSystemId().equals(infoByEnCode.getId())).collect(Collectors.toList());
  231. // moduleList.forEach(t -> {
  232. // if (t.getParentId().equals(t.getSystemId())) {
  233. // t.setParentId("-1");
  234. // }
  235. // });
  236. //
  237. // UserAuthorizeVO vo = UserAuthorizeVO.builder()
  238. // .button(this.moduleButton(moduleList, authorizeModel.getButtonList(), authorizeList, moduleMap))
  239. // .column(this.moduleColumn(moduleList, authorizeModel.getColumnList(), authorizeList, moduleMap))
  240. // .form(this.moduleForm(moduleList, authorizeModel.getFormsList(), authorizeList, moduleMap))
  241. // .resource(this.resourceData(moduleList, authorizeModel.getResourceList(), authorizeList, moduleMap))
  242. // .module(this.module(moduleList, authorizeList))
  243. // .flow(this.flow(authorizeList))
  244. // .print(this.print(authorizeList))
  245. // .portal(this.portal(authorizeModel.getSystemList())).build();
  246. // return ActionResult.success(vo);
  247. // 全部应用的权限
  248. return ActionResult.success(authPermUtil.getUserAuth(new UserAuthForm()));
  249. }
  250. /**
  251. * 系统日志
  252. *
  253. * @param pagination 页面参数
  254. * @return
  255. */
  256. @Operation(summary = "系统日志")
  257. @GetMapping("/SystemLog")
  258. public ActionResult<PageListVO<UserLogVO>> getLogList(PaginationLogModel pagination) {
  259. List<LogEntity> data = logService.getList(pagination.getCategory(), pagination, true);
  260. List<UserLogVO> loginLogVOList = JsonUtil.getJsonToList(data, UserLogVO.class);
  261. for (int i = 0; i < loginLogVOList.size(); i++) {
  262. loginLogVOList.get(i).setAbstracts(data.get(i).getDescription());
  263. }
  264. PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
  265. return ActionResult.page(loginLogVOList, paginationVO);
  266. }
  267. /**
  268. * 修改用户资料
  269. *
  270. * @param userInfoForm 页面参数
  271. * @return
  272. */
  273. @Operation(summary = "修改用户资料")
  274. @Parameters({
  275. @Parameter(name = "userInfoForm", description = "页面参数", required = true)
  276. })
  277. @PutMapping("/BaseInfo")
  278. public ActionResult updateInfo(@RequestBody UserInfoForm userInfoForm) throws Exception {
  279. UserEntity userEntity = userService.getInfo(UserProvider.getUser().getUserId());
  280. userEntity.setBirthday(userInfoForm.getBirthday() == null ? null : new Date(userInfoForm.getBirthday()));
  281. userEntity.setCertificatesNumber(userInfoForm.getCertificatesNumber());
  282. userEntity.setCertificatesType(userInfoForm.getCertificatesType());
  283. userEntity.setEducation(userInfoForm.getEducation());
  284. userEntity.setEmail(userInfoForm.getEmail());
  285. userEntity.setGender(userInfoForm.getGender());
  286. userEntity.setLandline(userInfoForm.getLandline());
  287. userEntity.setMobilePhone(userInfoForm.getMobilePhone());
  288. userEntity.setNation(userInfoForm.getNation());
  289. userEntity.setNativePlace(userInfoForm.getNativePlace());
  290. userEntity.setPostalAddress(userInfoForm.getPostalAddress());
  291. userEntity.setRealName(userInfoForm.getRealName());
  292. userEntity.setSignature(userInfoForm.getSignature());
  293. userEntity.setTelePhone(userInfoForm.getTelePhone());
  294. userEntity.setUrgentContacts(userInfoForm.getUrgentContacts());
  295. userEntity.setUrgentTelePhone(userInfoForm.getUrgentTelePhone());
  296. UserExtraEntity userExtraEntity = BeanUtil.copyProperties(userInfoForm, UserExtraEntity.class);
  297. userExtraEntity.setUserId(userEntity.getId());
  298. UserExtraEntity userExtraByUserId = userExtraService.getUserExtraByUserId(userExtraEntity.getUserId());
  299. if (null != userExtraByUserId) {
  300. userExtraEntity.setId(userExtraByUserId.getId());
  301. }
  302. userExtraService.saveOrUpdate(userExtraEntity);
  303. userService.updateById(userEntity);
  304. return ActionResult.success(MsgCode.SU002.get());
  305. }
  306. /**
  307. * 修改用户密码
  308. *
  309. * @param userModifyPasswordForm 用户修改密码表单
  310. * @return
  311. */
  312. @Operation(summary = "修改用户密码")
  313. @Parameters({
  314. @Parameter(name = "userModifyPasswordForm", description = "用户修改密码表单", required = true)
  315. })
  316. @PostMapping("/Actions/ModifyPassword")
  317. public ActionResult modifyPassword(@RequestBody @Valid UserModifyPasswordForm userModifyPasswordForm) {
  318. UserEntity userEntity = userService.getInfo(UserProvider.getUser().getUserId());
  319. if (userEntity != null) {
  320. // if ("1".equals(String.valueOf(userEntity.getIsAdministrator()))) {
  321. // return ActionResult.fail("无法修改管理员账户");
  322. // }
  323. String timestamp = String.valueOf(redisUtil.getString(userModifyPasswordForm.getTimestamp()));
  324. if (!userModifyPasswordForm.getCode().equalsIgnoreCase(timestamp)) {
  325. return ActionResult.fail(MsgCode.LOG104.get());
  326. }
  327. if (!Md5Util.getStringMd5((userModifyPasswordForm.getOldPassword().toLowerCase() + userEntity.getSecretkey().toLowerCase())).equals(userEntity.getPassword())) {
  328. return ActionResult.fail(MsgCode.LOG201.get());
  329. }
  330. //禁用旧密码
  331. String disableOldPassword = sysConfigApi.getValueByKey("disableOldPassword");
  332. if (disableOldPassword.equals("1")) {
  333. String disableTheNumberOfOldPasswords = sysConfigApi.getValueByKey("disableTheNumberOfOldPasswords");
  334. List<UserOldPasswordEntity> userOldPasswordList = userOldPasswordService.getList(UserProvider.getLoginUserId());
  335. userOldPasswordList = userOldPasswordList.stream().limit(Long.valueOf(disableTheNumberOfOldPasswords)).collect(Collectors.toList());
  336. for (UserOldPasswordEntity userOldPassword : userOldPasswordList) {
  337. String newPassword = Md5Util.getStringMd5(userModifyPasswordForm.getPassword().toLowerCase() + userOldPassword.getSecretkey().toLowerCase());
  338. if (userOldPassword.getOldPassword().equals(newPassword)) {
  339. return ActionResult.fail(MsgCode.LOG204.get());
  340. }
  341. }
  342. }
  343. userEntity.setPassword(userModifyPasswordForm.getPassword());
  344. userService.updatePassword(userEntity);
  345. userService.logoutUser(MsgCode.PS011.get(), Arrays.asList(userEntity.getId()));
  346. UserProvider.logoutByUserId(userEntity.getId());
  347. userEntity.setPassword(userModifyPasswordForm.getPassword());
  348. PullUserUtil.syncUser(userEntity, "modifyPassword", UserProvider.getUser().getTenantId());
  349. return ActionResult.success(MsgCode.PS011.get());
  350. }
  351. return ActionResult.fail(MsgCode.LOG203.get());
  352. }
  353. /**
  354. * 我的下属
  355. *
  356. * @param id 主键
  357. * @return
  358. */
  359. @Operation(summary = "我的下属")
  360. @Parameters({
  361. @Parameter(name = "id", description = "主键", required = true)
  362. })
  363. @GetMapping("/Subordinate/{id}")
  364. public ActionResult<List<UserSubordinateVO>> getSubordinate(@PathVariable("id") String id) {
  365. List<UserEntity> userName = new ArrayList<>(16);
  366. List<UserSubordinateVO> list = new ArrayList<>();
  367. if ("0".equals(id)) {
  368. if (Objects.isNull(UserProvider.getUser()) || StringUtil.isEmpty(UserProvider.getUser().getUserId())) {
  369. return ActionResult.success(list);
  370. }
  371. userName.add(userService.getInfo(UserProvider.getUser().getUserId()));
  372. } else {
  373. userName = new ArrayList<>(userService.getListByManagerId(id, null));
  374. }
  375. List<String> department = userName.stream().map(t -> t.getOrganizeId()).collect(Collectors.toList());
  376. List<OrganizeEntity> departmentList = organizeService.getOrganizeName(department);
  377. for (UserEntity user : userName) {
  378. String departName = departmentList.stream().filter(
  379. t -> String.valueOf(user.getOrganizeId()).equals(String.valueOf(t.getId()))
  380. ).findFirst().orElse(new OrganizeEntity()).getFullName();
  381. PositionEntity entity = null;
  382. if (StringUtil.isNotEmpty(user.getPositionId())) {
  383. String[] split = user.getPositionId().split(",");
  384. for (String positionId : split) {
  385. entity = positionService.getInfo(positionId);
  386. if (Objects.nonNull(entity)) {
  387. break;
  388. }
  389. }
  390. }
  391. UserSubordinateVO subordinateVO = UserSubordinateVO.builder()
  392. .id(user.getId())
  393. .avatar(UploaderUtil.uploaderImg(user.getHeadIcon()))
  394. .department(departName)
  395. .userName(user.getRealName() + "/" + user.getAccount())
  396. .position(entity != null ? entity.getFullName() : null)
  397. .isLeaf(false).build();
  398. list.add(subordinateVO);
  399. }
  400. return ActionResult.success(list);
  401. }
  402. /**
  403. * 修改系统主题
  404. *
  405. * @param userThemeForm 主题模板
  406. * @return
  407. */
  408. @Operation(summary = "修改系统主题")
  409. @Parameters({
  410. @Parameter(name = "userThemeForm", description = "主题模板", required = true)
  411. })
  412. @PutMapping("/SystemTheme")
  413. public ActionResult updateTheme(@RequestBody @Valid UserThemeForm userThemeForm) {
  414. UserEntity entity = JsonUtil.getJsonToBean(userThemeForm, UserEntity.class);
  415. entity.setId(UserProvider.getUser().getUserId());
  416. userService.updateById(entity);
  417. return ActionResult.success(MsgCode.SU016.get());
  418. }
  419. /**
  420. * 修改头像
  421. *
  422. * @param name 名称
  423. * @return
  424. */
  425. @Operation(summary = "修改头像")
  426. @Parameters({
  427. @Parameter(name = "name", description = "名称", required = true)
  428. })
  429. @PutMapping("/Avatar/{name}")
  430. public ActionResult updateAvatar(@PathVariable("name") String name) throws Exception {
  431. UserInfo userInfo = UserProvider.getUser();
  432. UserEntity userEntity = userService.getInfo(userInfo.getUserId());
  433. userEntity.setHeadIcon(name);
  434. userService.update(userEntity.getId(), userEntity);
  435. if (!StringUtil.isEmpty(userInfo.getId())) {
  436. userInfo.setUserIcon(name);
  437. //redisUtil.insert(userInfo.getId(), userInfo, DateUtil.getTime(userInfo.getOverdueTime()) - DateUtil.getTime(new Date()));
  438. UserProvider.setLoginUser(userInfo);
  439. UserProvider.setLocalLoginUser(userInfo);
  440. }
  441. return ActionResult.success(MsgCode.SU004.get());
  442. }
  443. /**
  444. * 修改系统语言
  445. *
  446. * @param userLanguageForm 修改语言模型
  447. * @return
  448. */
  449. @Operation(summary = "修改系统语言")
  450. @Parameters({
  451. @Parameter(name = "userLanguageForm", description = "修改语言模型", required = true)
  452. })
  453. @PutMapping("/SystemLanguage")
  454. public ActionResult updateLanguage(@RequestBody @Valid UserLanguageForm userLanguageForm) {
  455. UserEntity userEntity = userService.getInfo(UserProvider.getUser().getUserId());
  456. userEntity.setLanguage(userLanguageForm.getLanguage());
  457. userService.updateById(userEntity);
  458. return ActionResult.success(MsgCode.SU016.get());
  459. }
  460. /**
  461. * 赋值图标
  462. *
  463. * @param moduleList
  464. * @return
  465. */
  466. private Map<String, ModuleModel> moduleList(List<ModuleModel> moduleList) {
  467. Map<String, ModuleModel> auth = new HashMap<>(16);
  468. for (ModuleModel module : moduleList) {
  469. auth.put(module.getId(), module);
  470. module.setIcon(module.getIcon());
  471. }
  472. return auth;
  473. }
  474. /**
  475. * 功能权限
  476. *
  477. * @param moduleList 功能
  478. * @param authorizeLiat 权限集合
  479. * @return
  480. */
  481. private List<UserAuthorizeModel> module(List<ModuleModel> moduleList, List<AuthorizeEntity> authorizeLiat) {
  482. List<String> appId = moduleList.stream().filter(t -> JnpfConst.APP.equals(t.getCategory())).map(t -> t.getId()).collect(Collectors.toList());
  483. List<AuthorizeModel> treeList = JsonUtil.getJsonToList(moduleList, AuthorizeModel.class);
  484. treeList = treeList.stream().sorted(Comparator.comparing(AuthorizeModel::getSortCode).thenComparing(AuthorizeModel::getCreatorTime, Comparator.reverseOrder())).collect(Collectors.toList());
  485. List<SumTree<AuthorizeModel>> trees = TreeDotUtils.convertListToTreeDot(treeList, "-1");
  486. List<UserAuthorizeModel> vo = JsonUtil.getJsonToList(trees, UserAuthorizeModel.class);
  487. List<UserAuthorizeModel> dataList = new LinkedList<>();
  488. List<UserAuthorizeModel> webChildList = new LinkedList<>();
  489. List<UserAuthorizeModel> appChildList = new LinkedList<>();
  490. for (UserAuthorizeModel model : vo) {
  491. if (appId.contains(model.getId())) {
  492. appChildList.add(model);
  493. } else {
  494. webChildList.add(model);
  495. }
  496. }
  497. if (webChildList.size() > 0) {
  498. UserAuthorizeModel webData = new UserAuthorizeModel();
  499. webData.setId("1");
  500. webData.setFullName("WEB菜单");
  501. webData.setIcon(PermissionConst.PC_ICON);
  502. webData.setChildren(webChildList);
  503. dataList.add(webData);
  504. }
  505. if (appChildList.size() > 0) {
  506. UserAuthorizeModel appData = new UserAuthorizeModel();
  507. appData.setId("2");
  508. appData.setFullName("APP菜单");
  509. appData.setIcon(PermissionConst.APP_ICON);
  510. appData.setChildren(appChildList);
  511. dataList.add(appData);
  512. }
  513. return dataList;
  514. }
  515. /**
  516. * 按钮权限
  517. *
  518. * @param moduleList 功能
  519. * @param moduleButtonList 按钮
  520. * @param authorizeLiat 权限集合
  521. * @return
  522. */
  523. private List<UserAuthorizeModel> moduleButton(List<ModuleModel> moduleList, List<ButtonModel> moduleButtonList, List<AuthorizeEntity> authorizeLiat, Map<String, ModuleModel> moduleMap) {
  524. List<AuthorizeModel> treeList = new ArrayList<>();
  525. Set<String> moduleModeId = new HashSet<>();
  526. //获取按钮的菜单id
  527. for (ButtonModel buttonModel : moduleButtonList) {
  528. moduleModeId.add(buttonModel.getModuleId());
  529. AuthorizeModel treeModel = new AuthorizeModel();
  530. treeModel.setId(buttonModel.getId());
  531. treeModel.setFullName(buttonModel.getFullName());
  532. treeModel.setParentId(buttonModel.getModuleId());
  533. treeModel.setIcon(buttonModel.getIcon());
  534. treeModel.setCreatorTime(buttonModel.getCreatorTimes());
  535. treeList.add(treeModel);
  536. }
  537. List<ModuleModel> buttonList = moduleList.stream().filter(t -> moduleModeId.contains(t.getId())).collect(Collectors.toList());
  538. List<AuthorizeModel> moduleListAll = JsonUtil.getJsonToList(ListToTreeUtil.treeWhere(buttonList, moduleList), AuthorizeModel.class);
  539. treeList.addAll(moduleListAll);
  540. treeList = treeList.stream().sorted(Comparator.comparing(AuthorizeModel::getSortCode).thenComparing(AuthorizeModel::getCreatorTime, Comparator.reverseOrder())).collect(Collectors.toList());
  541. List<SumTree<AuthorizeModel>> trees = TreeDotUtils.convertListToTreeDot(treeList, "-1");
  542. //组装菜单树
  543. List<String> appId = moduleList.stream().filter(t -> JnpfConst.APP.equals(t.getCategory())).map(t -> t.getId()).collect(Collectors.toList());
  544. List<UserAuthorizeModel> data = JsonUtil.getJsonToList(trees, UserAuthorizeModel.class);
  545. List<UserAuthorizeModel> dataList = new LinkedList<>();
  546. List<UserAuthorizeModel> webChildList = new LinkedList<>();
  547. List<UserAuthorizeModel> appChildList = new LinkedList<>();
  548. for (UserAuthorizeModel model : data) {
  549. if (appId.contains(model.getId())) {
  550. appChildList.add(model);
  551. } else {
  552. webChildList.add(model);
  553. }
  554. }
  555. if (webChildList.size() > 0) {
  556. UserAuthorizeModel webData = new UserAuthorizeModel();
  557. webData.setId("1");
  558. webData.setFullName("WEB菜单");
  559. webData.setIcon(PermissionConst.PC_ICON);
  560. webData.setChildren(webChildList);
  561. dataList.add(webData);
  562. }
  563. if (appChildList.size() > 0) {
  564. UserAuthorizeModel appData = new UserAuthorizeModel();
  565. appData.setId("2");
  566. appData.setFullName("APP菜单");
  567. appData.setIcon(PermissionConst.APP_ICON);
  568. appData.setChildren(appChildList);
  569. dataList.add(appData);
  570. }
  571. return dataList;
  572. }
  573. /**
  574. * 列表权限
  575. *
  576. * @param moduleList 功能
  577. * @param moduleColumnList 列表
  578. * @param authorizeLiat 权限集合
  579. * @return
  580. */
  581. private List<UserAuthorizeModel> moduleColumn(List<ModuleModel> moduleList, List<ColumnModel> moduleColumnList, List<AuthorizeEntity> authorizeLiat, Map<String, ModuleModel> moduleMap) {
  582. List<AuthorizeModel> treeList = new ArrayList<>();
  583. List<String> moduleModeId = new ArrayList<>();
  584. //获取按钮的菜单id
  585. for (ColumnModel columnModel : moduleColumnList) {
  586. moduleModeId.add(columnModel.getModuleId());
  587. AuthorizeModel treeModel = new AuthorizeModel();
  588. treeModel.setId(columnModel.getId());
  589. treeModel.setFullName(columnModel.getFullName());
  590. treeModel.setParentId(columnModel.getModuleId());
  591. treeModel.setIcon("fa fa-tags column");
  592. treeModel.setCreatorTime(columnModel.getCreatorTimes());
  593. treeList.add(treeModel);
  594. }
  595. List<ModuleModel> buttonList = moduleList.stream().filter(t -> moduleModeId.contains(t.getId())).collect(Collectors.toList());
  596. List<AuthorizeModel> moduleListAll = JsonUtil.getJsonToList(ListToTreeUtil.treeWhere(buttonList, moduleList), AuthorizeModel.class);
  597. treeList.addAll(moduleListAll);
  598. treeList = treeList.stream().sorted(Comparator.comparing(AuthorizeModel::getSortCode).thenComparing(AuthorizeModel::getCreatorTime, Comparator.reverseOrder())).collect(Collectors.toList());
  599. List<SumTree<AuthorizeModel>> trees = TreeDotUtils.convertListToTreeDot(treeList, "-1");
  600. //组装菜单树
  601. List<String> appId = moduleList.stream().filter(t -> JnpfConst.APP.equals(t.getCategory())).map(t -> t.getId()).collect(Collectors.toList());
  602. List<UserAuthorizeModel> data = JsonUtil.getJsonToList(trees, UserAuthorizeModel.class);
  603. List<UserAuthorizeModel> dataList = new LinkedList<>();
  604. List<UserAuthorizeModel> webChildList = new LinkedList<>();
  605. List<UserAuthorizeModel> appChildList = new LinkedList<>();
  606. for (UserAuthorizeModel model : data) {
  607. if (appId.contains(model.getId())) {
  608. appChildList.add(model);
  609. } else {
  610. webChildList.add(model);
  611. }
  612. }
  613. if (webChildList.size() > 0) {
  614. UserAuthorizeModel webData = new UserAuthorizeModel();
  615. webData.setId("1");
  616. webData.setFullName("WEB菜单");
  617. webData.setIcon(PermissionConst.PC_ICON);
  618. webData.setChildren(webChildList);
  619. dataList.add(webData);
  620. }
  621. if (appChildList.size() > 0) {
  622. UserAuthorizeModel appData = new UserAuthorizeModel();
  623. appData.setId("2");
  624. appData.setFullName("APP菜单");
  625. appData.setIcon(PermissionConst.APP_ICON);
  626. appData.setChildren(appChildList);
  627. dataList.add(appData);
  628. }
  629. return dataList;
  630. }
  631. /**
  632. * 表单权限
  633. *
  634. * @param moduleList 功能
  635. * @param moduleFormList 表单
  636. * @param authorizeLiat 权限集合
  637. * @return ignore
  638. */
  639. private List<UserAuthorizeModel> moduleForm(List<ModuleModel> moduleList, List<ModuleFormModel> moduleFormList, List<AuthorizeEntity> authorizeLiat, Map<String, ModuleModel> moduleMap) {
  640. List<AuthorizeModel> treeList = new ArrayList<>();
  641. List<String> moduleModeId = new ArrayList<>();
  642. //获取按钮的菜单id
  643. for (ModuleFormModel formModel : moduleFormList) {
  644. moduleModeId.add(formModel.getModuleId());
  645. AuthorizeModel treeModel = new AuthorizeModel();
  646. treeModel.setId(formModel.getId());
  647. treeModel.setFullName(formModel.getFullName());
  648. treeModel.setParentId(formModel.getModuleId());
  649. treeModel.setIcon("fa fa-binoculars resource");
  650. treeModel.setCreatorTime(formModel.getCreatorTimes());
  651. treeList.add(treeModel);
  652. }
  653. List<ModuleModel> buttonList = moduleList.stream().filter(t -> moduleModeId.contains(t.getId())).collect(Collectors.toList());
  654. List<AuthorizeModel> moduleListAll = JsonUtil.getJsonToList(ListToTreeUtil.treeWhere(buttonList, moduleList), AuthorizeModel.class);
  655. treeList.addAll(moduleListAll);
  656. treeList = treeList.stream().sorted(Comparator.comparing(AuthorizeModel::getSortCode).thenComparing(AuthorizeModel::getCreatorTime, Comparator.reverseOrder())).collect(Collectors.toList());
  657. List<SumTree<AuthorizeModel>> trees = TreeDotUtils.convertListToTreeDot(treeList, "-1");
  658. //组装菜单树
  659. List<String> appId = moduleList.stream().filter(t -> JnpfConst.APP.equals(t.getCategory())).map(t -> t.getId()).collect(Collectors.toList());
  660. List<UserAuthorizeModel> data = JsonUtil.getJsonToList(trees, UserAuthorizeModel.class);
  661. List<UserAuthorizeModel> dataList = new LinkedList<>();
  662. List<UserAuthorizeModel> webChildList = new LinkedList<>();
  663. List<UserAuthorizeModel> appChildList = new LinkedList<>();
  664. for (UserAuthorizeModel model : data) {
  665. if (appId.contains(model.getId())) {
  666. appChildList.add(model);
  667. } else {
  668. webChildList.add(model);
  669. }
  670. }
  671. if (webChildList.size() > 0) {
  672. UserAuthorizeModel webData = new UserAuthorizeModel();
  673. webData.setId("1");
  674. webData.setFullName("WEB菜单");
  675. webData.setIcon(PermissionConst.PC_ICON);
  676. webData.setChildren(webChildList);
  677. dataList.add(webData);
  678. }
  679. if (appChildList.size() > 0) {
  680. UserAuthorizeModel appData = new UserAuthorizeModel();
  681. appData.setId("2");
  682. appData.setFullName("APP菜单");
  683. appData.setIcon(PermissionConst.APP_ICON);
  684. appData.setChildren(appChildList);
  685. dataList.add(appData);
  686. }
  687. return dataList;
  688. }
  689. /**
  690. * 数据权限
  691. *
  692. * @param moduleList 功能
  693. * @param moduleResourceList 资源
  694. * @param authorizeLiat 权限集合
  695. * @return ignore
  696. */
  697. private List<UserAuthorizeModel> resourceData(List<ModuleModel> moduleList, List<ResourceModel> moduleResourceList, List<AuthorizeEntity> authorizeLiat, Map<String, ModuleModel> moduleMap) {
  698. List<AuthorizeModel> treeList = new ArrayList<>();
  699. List<String> moduleModeId = new ArrayList<>();
  700. //获取按钮的菜单id
  701. for (ResourceModel resourceModel : moduleResourceList) {
  702. moduleModeId.add(resourceModel.getModuleId());
  703. AuthorizeModel treeModel = new AuthorizeModel();
  704. treeModel.setId(resourceModel.getId());
  705. treeModel.setFullName(resourceModel.getFullName());
  706. treeModel.setParentId(resourceModel.getModuleId());
  707. treeModel.setIcon("fa fa-binoculars resource");
  708. treeModel.setCreatorTime(resourceModel.getCreatorTimes());
  709. treeList.add(treeModel);
  710. }
  711. List<ModuleModel> buttonList = moduleList.stream().filter(t -> moduleModeId.contains(t.getId())).collect(Collectors.toList());
  712. List<AuthorizeModel> moduleListAll = JsonUtil.getJsonToList(ListToTreeUtil.treeWhere(buttonList, moduleList), AuthorizeModel.class);
  713. treeList.addAll(moduleListAll);
  714. treeList = treeList.stream().sorted(Comparator.comparing(AuthorizeModel::getSortCode).thenComparing(AuthorizeModel::getCreatorTime, Comparator.reverseOrder())).collect(Collectors.toList());
  715. List<SumTree<AuthorizeModel>> trees = TreeDotUtils.convertListToTreeDot(treeList, "-1");
  716. //组装菜单树
  717. List<String> appId = moduleList.stream().filter(t -> JnpfConst.APP.equals(t.getCategory())).map(t -> t.getId()).collect(Collectors.toList());
  718. List<UserAuthorizeModel> data = JsonUtil.getJsonToList(trees, UserAuthorizeModel.class);
  719. List<UserAuthorizeModel> dataList = new LinkedList<>();
  720. List<UserAuthorizeModel> webChildList = new LinkedList<>();
  721. List<UserAuthorizeModel> appChildList = new LinkedList<>();
  722. for (UserAuthorizeModel model : data) {
  723. if (appId.contains(model.getId())) {
  724. appChildList.add(model);
  725. } else {
  726. webChildList.add(model);
  727. }
  728. }
  729. if (webChildList.size() > 0) {
  730. UserAuthorizeModel webData = new UserAuthorizeModel();
  731. webData.setId("1");
  732. webData.setFullName("WEB菜单");
  733. webData.setIcon(PermissionConst.PC_ICON);
  734. webData.setChildren(webChildList);
  735. dataList.add(webData);
  736. }
  737. if (appChildList.size() > 0) {
  738. UserAuthorizeModel appData = new UserAuthorizeModel();
  739. appData.setId("2");
  740. appData.setFullName("APP菜单");
  741. appData.setIcon(PermissionConst.APP_ICON);
  742. appData.setChildren(appChildList);
  743. dataList.add(appData);
  744. }
  745. return dataList;
  746. }
  747. /**
  748. * 门户权限
  749. *
  750. * @param systemBaeModelList
  751. * @return
  752. */
  753. private List<UserAuthorizeModel> portal(List<SystemBaeModel> systemBaeModelList) {
  754. List<PortalModel> myPortalList = new ArrayList<>();
  755. List<SystemEntity> mySystemList = JsonUtil.getJsonToList(systemBaeModelList, SystemEntity.class);
  756. SystemEntity systemEntity = mySystemList.stream().filter(t -> t.getId().equals(UserProvider.getUser().getSystemId())).findFirst().orElse(null);
  757. List<String> roleIdList = new ArrayList<>();
  758. permissionGroupService.getPermissionGroupByUserId(UserProvider.getLoginUserId(), null, true, null).forEach(t -> {
  759. roleIdList.add(t.getId());
  760. });
  761. List<String> collect = authorizeService.getListByRoleIdsAndItemType(roleIdList, AuthorizeConst.AUTHORIZE_PORTAL_MANAGE).stream().map(AuthorizeEntity::getItemId).collect(Collectors.toList());
  762. //管理员查看全部
  763. PortalManagePage page = new PortalManagePage();
  764. page.setEnabledMark(1);
  765. page.setSystemId(UserProvider.getUser().getSystemId());
  766. page.setState(0);
  767. List<String> portalIdList = portalManageApi.getSelectList(page).stream().map(PortalManagePageDO::getId).collect(Collectors.toList());
  768. if (UserProvider.getUser().getIsAdministrator()) {
  769. collect.addAll(portalIdList);
  770. }
  771. authorizeService.getPortal(systemEntity == null ? new ArrayList<>() : Collections.singletonList(systemEntity), myPortalList, System.currentTimeMillis(), collect.size() > 0 ? collect : null);
  772. myPortalList.remove(JsonUtil.getJsonToBean(systemEntity, PortalModel.class));
  773. List<SumTree<PortalModel>> trees = TreeDotUtils.convertListToTreeDot(myPortalList);
  774. trees.forEach(t -> {
  775. if (t.getParentId().startsWith(systemEntity.getId())) {
  776. t.setParentId("-1");
  777. }
  778. });
  779. return JsonUtil.getJsonToList(trees, UserAuthorizeModel.class);
  780. }
  781. /**
  782. * 权限
  783. *
  784. * @return
  785. */
  786. private List<UserAuthorizeModel> flow(List<AuthorizeEntity> authorizeLiat) {
  787. UserInfo user = UserProvider.getUser();
  788. List<String> itemId = new ArrayList<>();
  789. if (user.getIsAdministrator()) {
  790. List<TemplateTreeListVo> treeListVoList = templateApi.treeListWithPower();
  791. for (TemplateTreeListVo treeListVo : treeListVoList) {
  792. itemId.add(treeListVo.getId());
  793. if (ObjectUtil.isNotEmpty(treeListVo.getChildren())) {
  794. for (TemplateTreeListVo child : treeListVo.getChildren()) {
  795. itemId.add(child.getId());
  796. }
  797. }
  798. }
  799. } else {
  800. List<String> roleIdList = new ArrayList<>();
  801. roleIdList.addAll(user.getRoleIds());
  802. roleIdList.addAll(user.getPositionIds());
  803. itemId = authorizeService.getListByRoleIdsAndItemType(roleIdList, AuthorizeConst.FLOW).stream().map(AuthorizeEntity::getItemId).collect(Collectors.toList());
  804. }
  805. List<UserAuthorizeModel> listVO = new ArrayList<>();
  806. if (!itemId.isEmpty()) {
  807. List<TemplateEntity> list = templateApi.getListByFlowIds(itemId);
  808. List<String> systemId = list.stream().map(TemplateEntity::getSystemId).collect(Collectors.toList());
  809. List<SystemEntity> systemList = systemService.getListByIds(systemId, new ArrayList<>());
  810. for (SystemEntity system : systemList) {
  811. UserAuthorizeModel vo = JsonUtil.getJsonToBean(system, UserAuthorizeModel.class);
  812. List<TemplateEntity> childList = list.stream()
  813. .filter(e -> system.getId().equals(e.getSystemId()))
  814. .sorted(Comparator.comparing(TemplateEntity::getSortCode, Comparator.nullsLast(Comparator.naturalOrder())).thenComparing(TemplateEntity::getCreatorTime, Comparator.reverseOrder())).collect(Collectors.toList());
  815. if (!childList.isEmpty()) {
  816. vo.setChildren(JsonUtil.getJsonToList(childList, UserAuthorizeModel.class));
  817. listVO.add(vo);
  818. }
  819. }
  820. }
  821. return listVO;
  822. }
  823. /**
  824. * 权限
  825. *
  826. * @return
  827. */
  828. private List<UserAuthorizeModel> print(List<AuthorizeEntity> authorizeLiat) {
  829. UserInfo user = UserProvider.getUser();
  830. List<String> itemId = new ArrayList<>();
  831. if (!authorizeService.getUserCurrentStanding(user.getUserId(), 3)) {
  832. PaginationPrint paginationPrint = new PaginationPrint();
  833. paginationPrint.setDataType(1);
  834. paginationPrint.setVisibleType(2);
  835. List<PrintDevEntity> list = printDevApi.getWorkSelector(paginationPrint);
  836. itemId.addAll(list.stream().map(PrintDevEntity::getId).collect(Collectors.toList()));
  837. } else {
  838. List<String> roleIdList = new ArrayList<>();
  839. permissionGroupService.getPermissionGroupByUserId(UserProvider.getLoginUserId(), null, true, null).forEach(t -> {
  840. roleIdList.add(t.getId());
  841. });
  842. itemId = authorizeService.getListByRoleIdsAndItemType(roleIdList, AuthorizeConst.PRINT).stream().map(AuthorizeEntity::getItemId).collect(Collectors.toList());
  843. }
  844. List<UserAuthorizeModel> listVO = new ArrayList<>();
  845. if (itemId.size() > 0) {
  846. List<PrintDevEntity> list = printDevApi.getWorkSelector(itemId);
  847. List<String> category = list.stream().map(PrintDevEntity::getCategory).collect(Collectors.toList());
  848. List<DictionaryDataEntity> dictionName = dictionaryDataApi.getDictionName(category);
  849. for (DictionaryDataEntity dict : dictionName) {
  850. UserAuthorizeModel vo = JsonUtil.getJsonToBean(dict, UserAuthorizeModel.class);
  851. List<PrintDevEntity> childList = list.stream()
  852. .filter(e -> dict.getId().equals(e.getCategory()))
  853. .sorted(Comparator.comparing(PrintDevEntity::getSortCode).thenComparing(PrintDevEntity::getCreatorTime, Comparator.reverseOrder())).collect(Collectors.toList());
  854. if (childList.size() > 0) {
  855. vo.setChildren(JsonUtil.getJsonToList(childList, UserAuthorizeModel.class));
  856. listVO.add(vo);
  857. }
  858. }
  859. }
  860. return listVO;
  861. }
  862. @Operation(summary = "设置默认岗位/切换身份(岗位不切换权限)")
  863. @Parameters({
  864. @Parameter(name = "userSettingForm", description = "页面参数", required = true)
  865. })
  866. @PutMapping("/major")
  867. public ActionResult<String> defaultOrganize(@RequestBody UserSettingForm userSettingForm) {
  868. UserInfo userInfo = UserProvider.getUser();
  869. UserEntity userEntity = userService.getInfo(userInfo.getUserId());
  870. if (userEntity == null) {
  871. return ActionResult.fail(ActionResultCode.SessionOverdue.getCode(), ActionResultCode.SessionOverdue.getMessage());
  872. }
  873. UserEntity updateUser = new UserEntity();
  874. switch (userSettingForm.getMajorType()) {
  875. //切岗位(组织也被切了)
  876. case PermissionConst.POSITION:
  877. PositionEntity info = positionService.getInfo(userSettingForm.getMajorId());
  878. updateUser.setOrganizeId(info.getOrganizeId());
  879. updateUser.setPositionId(userSettingForm.getMajorId());
  880. break;
  881. case PermissionConst.STAND:
  882. if (DeviceType.PC.getDevice().equals(userInfo.getLoginDevice())) {
  883. updateUser.setStanding(userSettingForm.getMajorId());
  884. } else {
  885. updateUser.setAppStanding(userSettingForm.getMajorId());
  886. List<AuthorizeEntity> standingList = authorizeService.getAuthorizeByItem(PermissionConst.STAND, userSettingForm.getMajorId());
  887. List<String> posAndRoles = new ArrayList<>();
  888. List<String> stdPos = standingList.stream().filter(t -> userInfo.getPositionIds().contains(t.getObjectId())
  889. && PermissionConst.POSITION.equals(t.getObjectType())).map(AuthorizeEntity::getObjectId).collect(Collectors.toList());
  890. //获取当前岗位角色
  891. List<String> stdPosRole = roleRelationService.getListByObjectId(stdPos, null)
  892. .stream().map(RoleRelationEntity::getRoleId).collect(Collectors.toList());
  893. List<String> stdRole = standingList.stream().filter(t -> userInfo.getRoleIds().contains(t.getObjectId())
  894. && PermissionConst.ROLE.equals(t.getObjectType())).map(AuthorizeEntity::getObjectId).collect(Collectors.toList());
  895. posAndRoles.addAll(stdPos);
  896. posAndRoles.addAll(stdPosRole);
  897. posAndRoles.addAll(stdRole);
  898. List<SystemEntity> allSysList = systemService.getList();
  899. List<String> mainSysIds = allSysList.stream().filter(t -> Objects.equals(t.getIsMain(), 1)).map(SystemEntity::getId).collect(Collectors.toList());
  900. List<AuthorizeEntity> sysList = authorizeService.getListByObjectId(posAndRoles).stream()
  901. .filter(t -> PermissionConst.SYSTEM.equals(t.getItemType()) && !mainSysIds.contains(t.getItemId())).collect(Collectors.toList());
  902. if (CollectionUtil.isEmpty(sysList)) {
  903. return ActionResult.fail(MsgCode.FA052.get());
  904. }
  905. List<String> collect = sysList.stream().map(AuthorizeEntity::getItemId).collect(Collectors.toList());
  906. if (StringUtil.isEmpty(userEntity.getAppSystemId()) || !collect.contains(userEntity.getAppSystemId())) {
  907. updateUser.setAppSystemId(collect.get(0));
  908. }
  909. }
  910. break;
  911. case PermissionConst.SYSTEM:
  912. //app切换系统
  913. SystemEntity systemEntity = systemService.getInfo(userSettingForm.getMajorId());
  914. if (systemEntity == null) {
  915. return ActionResult.fail(MsgCode.PS031.get());
  916. }
  917. if (systemEntity.getEnabledMark() == 0) {
  918. return ActionResult.fail(MsgCode.PS014.get());
  919. }
  920. List<ModuleModel> moduleList = authorizeService.getAuthorizeByUser(false).getModuleList()
  921. .stream().filter(t -> StringUtil.isNotEmpty(t.getSystemId()) && t.getSystemId().equals(userSettingForm.getMajorId())).collect(Collectors.toList());
  922. Map<String, List<ModuleModel>> map = moduleList.stream().collect(Collectors.groupingBy(t -> {
  923. if (JnpfConst.WEB.equals(t.getCategory())) {
  924. return JnpfConst.WEB;
  925. } else {
  926. return JnpfConst.APP;
  927. }
  928. }));
  929. List<ModuleModel> appModule = map.containsKey(JnpfConst.APP) ? map.get(JnpfConst.APP) : new ArrayList<>();
  930. if (Objects.equals(userSettingForm.getMenuType(), 1)) {
  931. if (appModule.size() == 0) {
  932. return ActionResult.fail(MsgCode.FA027.get());
  933. }
  934. }
  935. if (userSettingForm.getMenuType() != null && userSettingForm.getMenuType() == 1) {
  936. updateUser.setAppSystemId(userSettingForm.getMajorId());
  937. userInfo.setAppSystemId(userSettingForm.getMajorId());
  938. UserProvider.setLoginUser(userInfo);
  939. UserProvider.setLocalLoginUser(userInfo);
  940. }
  941. updateUser.setId(userEntity.getId());
  942. userService.updateById(updateUser);
  943. return ActionResult.success(MsgCode.SU005.get());
  944. default:
  945. break;
  946. }
  947. updateUser.setId(userEntity.getId());
  948. userService.updateById(updateUser);
  949. authorizeService.removeAuthByUserOrMenu(Arrays.asList(userInfo.getUserId()), null);
  950. if (PermissionConst.STAND.equals(userSettingForm.getMajorType())) {
  951. userService.majorStandFreshUser();
  952. }
  953. return ActionResult.success(MsgCode.SU016.get());
  954. }
  955. @Operation(summary = "获取当前用户所有岗位")
  956. @GetMapping("/getUserPositions")
  957. public ActionResult<List<PosistionCurrentModel>> getUserPositions() {
  958. return ActionResult.success(userRelationService.getObjectVoList());
  959. }
  960. /*= different =*/
  961. /**
  962. * 修改app常用
  963. *
  964. * @param userAppDataForm 页面参数
  965. * @return
  966. */
  967. @Operation(summary = "修改app常用数据")
  968. @Parameter(name = "userAppDataForm", description = "页面参数", required = true)
  969. @PutMapping("/SystemAppData")
  970. public ActionResult updateAppData(@RequestBody @Valid UserAppDataForm userAppDataForm) {
  971. UserInfo userInfo = UserProvider.getUser();
  972. UserEntity entity = userService.getInfo(userInfo.getUserId());
  973. UserExtraEntity userExtraByUserId = userExtraService.getUserExtraByUserId(userInfo.getUserId());
  974. userExtraByUserId.setPropertyJson(userAppDataForm.getData());
  975. userService.updateById(entity);
  976. userExtraService.updateById(userExtraByUserId);
  977. return ActionResult.success(MsgCode.SU016.get());
  978. }
  979. /**
  980. * 列表
  981. *
  982. * @return ignore
  983. */
  984. @Operation(summary = "获取个性签名列表")
  985. @GetMapping("/SignImg")
  986. public ActionResult getListSignImg() {
  987. List<SignEntity> list = signService.getList();
  988. List<SignListVO> data = JsonUtil.getJsonToList(list, SignListVO.class);
  989. return ActionResult.success(data);
  990. }
  991. /**
  992. * 新建
  993. *
  994. * @param signForm 实体对象
  995. * @return ignore
  996. */
  997. @Operation(summary = "添加个性签名")
  998. @Parameter(name = "signForm", description = "实体对象", required = true)
  999. @PostMapping("/SignImg")
  1000. public ActionResult create(@RequestBody @Valid SignForm signForm) {
  1001. SignEntity entity = JsonUtil.getJsonToBean(signForm, SignEntity.class);
  1002. boolean b = signService.create(entity);
  1003. if (b) {
  1004. return ActionResult.success(MsgCode.SU001.get());
  1005. }
  1006. return ActionResult.fail(MsgCode.SU001.get());
  1007. }
  1008. /**
  1009. * 删除
  1010. *
  1011. * @param id 主键值
  1012. * @return ignore
  1013. */
  1014. @Operation(summary = "删除个性签名")
  1015. @Parameter(name = "id", description = "主键值", required = true)
  1016. @DeleteMapping("/{id}/SignImg")
  1017. public ActionResult delete(@PathVariable("id") String id) {
  1018. boolean delete = signService.delete(id);
  1019. if (delete) {
  1020. return ActionResult.success(MsgCode.SU003.get());
  1021. }
  1022. return ActionResult.fail(MsgCode.SU003.get());
  1023. }
  1024. /**
  1025. * 设置默认
  1026. *
  1027. * @param id 主键值
  1028. * @return ignore
  1029. */
  1030. @Operation(summary = "设置默认")
  1031. @Parameter(name = "id", description = "主键值", required = true)
  1032. @PutMapping("/{id}/SignImg")
  1033. public ActionResult uptateDefault(@PathVariable("id") String id) {
  1034. boolean b = signService.updateDefault(id);
  1035. if (b) {
  1036. return ActionResult.success(MsgCode.SU004.get());
  1037. }
  1038. return ActionResult.fail(MsgCode.SU004.get());
  1039. }
  1040. }