ModuleController.java 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. package jnpf.base.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.dev33.satoken.annotation.SaMode;
  4. import io.swagger.v3.oas.annotations.Operation;
  5. import io.swagger.v3.oas.annotations.Parameter;
  6. import io.swagger.v3.oas.annotations.Parameters;
  7. import io.swagger.v3.oas.annotations.tags.Tag;
  8. import jakarta.validation.Valid;
  9. import jnpf.base.ActionResult;
  10. import jnpf.base.entity.*;
  11. import jnpf.base.model.module.*;
  12. import jnpf.base.model.online.VisualMenuModel;
  13. import jnpf.base.service.*;
  14. import jnpf.base.util.visualUtil.PubulishUtil;
  15. import jnpf.base.vo.DownloadVO;
  16. import jnpf.base.vo.ListVO;
  17. import jnpf.base.vo.PaginationVO;
  18. import jnpf.config.ConfigValueUtil;
  19. import jnpf.constant.JnpfConst;
  20. import jnpf.constant.MsgCode;
  21. import jnpf.constant.PermissionConst;
  22. import jnpf.database.util.TenantDataSourceUtil;
  23. import jnpf.emnus.ModuleTypeEnum;
  24. import jnpf.exception.DataException;
  25. import jnpf.exception.WorkFlowException;
  26. import jnpf.model.FlowWorkModel;
  27. import jnpf.model.UserMenuModel;
  28. import jnpf.model.tenant.*;
  29. import jnpf.permission.entity.AuthorizeEntity;
  30. import jnpf.permission.entity.PermissionGroupEntity;
  31. import jnpf.permission.model.user.vo.BaseInfoVo;
  32. import jnpf.permission.service.AuthorizeService;
  33. import jnpf.permission.service.PermissionGroupService;
  34. import jnpf.permission.service.UserService;
  35. import jnpf.util.*;
  36. import jnpf.util.context.RequestContext;
  37. import jnpf.util.treeutil.ListToTreeUtil;
  38. import jnpf.util.treeutil.SumTree;
  39. import jnpf.util.treeutil.TreeViewModel;
  40. import jnpf.util.treeutil.newtreeutil.TreeDotUtils;
  41. import jnpf.util.type.AuthorizeType;
  42. import jnpf.workflow.service.TemplateApi;
  43. import org.apache.commons.collections4.CollectionUtils;
  44. import org.springframework.beans.factory.annotation.Autowired;
  45. import org.springframework.http.MediaType;
  46. import org.springframework.web.bind.annotation.*;
  47. import org.springframework.web.multipart.MultipartFile;
  48. import java.util.*;
  49. import java.util.function.Function;
  50. import java.util.stream.Collectors;
  51. /**
  52. * 系统功能
  53. *
  54. * @author JNPF开发平台组
  55. * @version V3.1.0
  56. * @copyright 引迈信息技术有限公司
  57. * @date 2019年9月27日 上午9:18
  58. */
  59. @Tag(name = "系统菜单", description = "menu")
  60. @RestController
  61. @RequestMapping("/api/system/Menu")
  62. public class ModuleController extends SuperController<ModuleService, ModuleEntity> {
  63. @Autowired
  64. private ModuleService moduleService;
  65. @Autowired
  66. private RedisUtil redisUtil;
  67. @Autowired
  68. private CacheKeyUtil cacheKeyUtil;
  69. @Autowired
  70. private SystemService systemService;
  71. @Autowired
  72. private ConfigValueUtil configValueUtil;
  73. @Autowired
  74. private TemplateApi templateApi;
  75. @Autowired
  76. private PubulishUtil pubulishUtil;
  77. @Operation(summary = "获取菜单列表")
  78. @Parameters({
  79. @Parameter(name = "systemId", description = "系统id", required = true)
  80. })
  81. @GetMapping("/ModuleBySystem")
  82. public ActionResult<ListVO<MenuListVO>> list(PaginationMenu paginationMenu) {
  83. String appCode = RequestContext.getAppCode();
  84. List<ModuleEntity> data = moduleService.getList(appCode, paginationMenu.getCategory(), paginationMenu.getKeyword(), paginationMenu.getType(), paginationMenu.getEnabledMark(), null, false);
  85. // 递归查上级
  86. Map<String, ModuleEntity> moduleEntityMap = data.stream().collect(Collectors.toMap(ModuleEntity::getId, Function.identity()));
  87. if (StringUtil.isNotEmpty(paginationMenu.getKeyword())) {
  88. moduleService.getParentModule(data, moduleEntityMap);
  89. }
  90. List<UserMenuModel> list = JsonUtil.getJsonToList(moduleEntityMap.values(), UserMenuModel.class);
  91. for (UserMenuModel item : list) {
  92. if (Objects.equals(item.getType(), 3)) {
  93. if (Objects.equals(item.getIsButtonAuthorize(), 1)
  94. || Objects.equals(item.getIsColumnAuthorize(), 1)
  95. || Objects.equals(item.getIsDataAuthorize(), 1)
  96. || Objects.equals(item.getIsFormAuthorize(), 1)) {
  97. item.setHasPermission(1);
  98. }
  99. //添加视图标识
  100. if (StringUtil.isNotEmpty(item.getPropertyJson())) {
  101. PropertyJsonModel model = JsonUtil.getJsonToBean(item.getPropertyJson(), PropertyJsonModel.class);
  102. item.setWebType(model.getWebType());
  103. if (Objects.equals(model.getWebType(), 4)) {
  104. item.setHasPermission(0);
  105. }
  106. }
  107. } else {
  108. item.setHasPermission(1);
  109. }
  110. }
  111. list = list.stream().sorted(Comparator.comparing(UserMenuModel::getSortCode, Comparator.nullsLast(Comparator.naturalOrder())).thenComparing(UserMenuModel::getCreatorTime, Comparator.nullsLast(Comparator.reverseOrder()))).collect(Collectors.toList());
  112. List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDot(list);
  113. List<MenuListVO> menuvo = JsonUtil.getJsonToList(menuList, MenuListVO.class);
  114. ListVO vo = new ListVO();
  115. vo.setList(menuvo);
  116. return ActionResult.success(vo);
  117. }
  118. @Operation(summary = "新建系统功能")
  119. @Parameters({
  120. @Parameter(name = "moduleCrForm", description = "实体对象", required = true)
  121. })
  122. @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR)
  123. @PostMapping
  124. public ActionResult create(@RequestBody @Valid ModuleCrForm moduleCrForm) {
  125. SystemEntity info = systemService.getInfoByEnCode(RequestContext.getAppCode());
  126. moduleCrForm.setSystemId(info.getId());
  127. ModuleEntity entity = JsonUtil.getJsonToBean(moduleCrForm, ModuleEntity.class);
  128. if (entity.getUrlAddress() != null) {
  129. entity.setUrlAddress(entity.getUrlAddress().trim());
  130. }
  131. if (moduleService.isExistByFullName(entity, moduleCrForm.getCategory(), moduleCrForm.getSystemId())) {
  132. return ActionResult.fail(MsgCode.EXIST001.get());
  133. }
  134. if (moduleService.isExistByEnCode(entity, moduleCrForm.getCategory(), moduleCrForm.getSystemId())) {
  135. return ActionResult.fail(MsgCode.EXIST002.get());
  136. }
  137. if (moduleService.isExistByAddress(entity, moduleCrForm.getCategory(), moduleCrForm.getSystemId())) {
  138. return ActionResult.fail(MsgCode.EXIST104.get());
  139. }
  140. moduleService.create(entity);
  141. return ActionResult.success(MsgCode.SU001.get());
  142. }
  143. @Operation(summary = "更新系统功能")
  144. @Parameters({
  145. @Parameter(name = "id", description = "主键值", required = true),
  146. @Parameter(name = "moduleUpForm", description = "实体对象", required = true)
  147. })
  148. @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR)
  149. @PutMapping("/{id}")
  150. public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid ModuleUpForm moduleUpForm) {
  151. SystemEntity info = systemService.getInfoByEnCode(RequestContext.getAppCode());
  152. moduleUpForm.setSystemId(info.getId());
  153. ModuleEntity entity = JsonUtil.getJsonToBean(moduleUpForm, ModuleEntity.class);
  154. //判断如果是目录则不能修改类型
  155. ModuleEntity moduleEntity = moduleService.getInfo(id);
  156. if (moduleEntity != null && moduleEntity.getType() == 1 && entity.getType() != 1 && moduleService.getListByParentId(moduleEntity.getId()).size() > 0) {
  157. return ActionResult.fail(MsgCode.SYS016.get());
  158. }
  159. entity.setId(id);
  160. if (entity.getUrlAddress() != null) {
  161. entity.setUrlAddress(entity.getUrlAddress().trim());
  162. }
  163. if (moduleService.isExistByFullName(entity, moduleUpForm.getCategory(), moduleUpForm.getSystemId())) {
  164. return ActionResult.fail(MsgCode.EXIST001.get());
  165. }
  166. if (moduleService.isExistByEnCode(entity, moduleUpForm.getCategory(), moduleUpForm.getSystemId())) {
  167. return ActionResult.fail(MsgCode.EXIST002.get());
  168. }
  169. if (moduleService.isExistByAddress(entity, moduleUpForm.getCategory(), moduleUpForm.getSystemId())) {
  170. return ActionResult.fail(MsgCode.EXIST104.get());
  171. }
  172. boolean flag = moduleService.update(id, entity);
  173. if (!flag) {
  174. return ActionResult.fail(MsgCode.FA002.get());
  175. }
  176. return ActionResult.success(MsgCode.SU004.get());
  177. }
  178. @Operation(summary = "删除系统功能")
  179. @Parameters({
  180. @Parameter(name = "id", description = "主键值", required = true)
  181. })
  182. @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR)
  183. @DeleteMapping("/{id}")
  184. public ActionResult delete(@PathVariable("id") String id) {
  185. ModuleEntity entity = moduleService.getInfo(id);
  186. if (entity != null) {
  187. List<ModuleEntity> list = moduleService.getList(false, new ArrayList<>(), new ArrayList<>()).stream().filter(t -> t.getParentId().equals(entity.getId())).collect(Collectors.toList());
  188. if (list.size() > 0) {
  189. return ActionResult.fail(MsgCode.SYS017.get());
  190. }
  191. moduleService.delete(entity);
  192. return ActionResult.success(MsgCode.SU003.get());
  193. }
  194. return ActionResult.fail(MsgCode.FA003.get());
  195. }
  196. @Operation(summary = "获取菜单信息")
  197. @Parameters({
  198. @Parameter(name = "id", description = "主键值", required = true)
  199. })
  200. @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR)
  201. @GetMapping("/{id}")
  202. public ActionResult<ModuleInfoVO> info(@PathVariable("id") String id) throws DataException {
  203. ModuleEntity entity = moduleService.getInfo(id);
  204. ModuleInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, ModuleInfoVO.class);
  205. return ActionResult.success(vo);
  206. }
  207. //+++++++++++++++++++++++++++增删改查end+++++++++++++++++++++++++++++++++++++++++++++++
  208. /**
  209. * 获取菜单列表(下拉框)
  210. *
  211. * @param category 分类
  212. * @param id 主键
  213. * @return ignore
  214. */
  215. @Operation(summary = "获取菜单列表(下拉框)")
  216. @Parameters({
  217. @Parameter(name = "category", description = "分类"),
  218. @Parameter(name = "id", description = "主键", required = true)
  219. })
  220. @GetMapping("/Selector/{id}")
  221. public ActionResult<ListVO<MenuSelectVO>> treeView(String category, @PathVariable("id") String id) {
  222. //应用编码
  223. String appCode = RequestContext.getAppCode();
  224. List<ModuleEntity> data = moduleService.getList(appCode, category, null, 1, null, null, false);
  225. if (!"0".equals(id)) {
  226. data.remove(moduleService.getInfo(id));
  227. }
  228. List<UserMenuModel> list = JsonUtil.getJsonToList(data, UserMenuModel.class);
  229. List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDotFilter(list);
  230. List<MenuSelectVO> menuvo = JsonUtil.getJsonToList(menuList, MenuSelectVO.class);
  231. ListVO vo = new ListVO();
  232. vo.setList(menuvo);
  233. return ActionResult.success(vo);
  234. }
  235. /**
  236. * 获取开发平台菜单
  237. *
  238. * @return ignore
  239. */
  240. @Operation(summary = "获取开发平台菜单")
  241. @GetMapping("/SystemSelector")
  242. public ActionResult<ListVO<MenuSelectVO>> mainSystemSelector() {
  243. SystemEntity mainSystem = systemService.getInfoByEnCode(JnpfConst.MAIN_SYSTEM_CODE);
  244. List<ModuleEntity> data = moduleService.getList(mainSystem.getId(), null, null, null, 1, null, false);
  245. List<UserMenuModel> list = JsonUtil.getJsonToList(data, UserMenuModel.class);
  246. list.forEach(t -> {
  247. if ("-1".equals(t.getParentId())) {
  248. t.setParentId(t.getSystemId());
  249. }
  250. });
  251. UserMenuModel userMenuModel = JsonUtil.getJsonToBean(mainSystem, UserMenuModel.class);
  252. userMenuModel.setType(0);
  253. userMenuModel.setParentId("-1");
  254. list.add(userMenuModel);
  255. List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDotFilter(list);
  256. List<MenuSelectVO> menuvo = JsonUtil.getJsonToList(menuList, MenuSelectVO.class);
  257. ListVO vo = new ListVO();
  258. vo.setList(menuvo);
  259. return ActionResult.success(vo);
  260. }
  261. /**
  262. * 通过系统id获取菜单列表(下拉框)
  263. *
  264. * @param category 分类
  265. * @param id 主键
  266. * @return ignore
  267. */
  268. @Operation(summary = "通过系统id获取菜单列表(下拉框)")
  269. @Parameters({
  270. @Parameter(name = "id", description = "主键", required = true),
  271. @Parameter(name = "systemId", description = "系统主键", required = true),
  272. @Parameter(name = "enabledMark", description = "查询类型:null-全部,0-禁用,1-启用", required = false)
  273. })
  274. @GetMapping("/Selector/{id}/{systemId}")
  275. public ActionResult<ListVO<MenuSelectAllVO>> treeView(@PathVariable("id") String id,
  276. @PathVariable("systemId") String systemId,
  277. @RequestParam("category") String category,
  278. @RequestParam(value = "enabledMark", required = false) Integer enabledMark) {
  279. List<ModuleEntity> data = moduleService.getList(systemId, category, null, 1, enabledMark, null, true);
  280. if (!"0".equals(id)) {
  281. data.remove(moduleService.getInfo(id));
  282. }
  283. List<UserMenuModel> list = JsonUtil.getJsonToList(data, UserMenuModel.class);
  284. if ("0".equals(systemId)) {
  285. List<String> moduleAuthorize = new ArrayList<>();
  286. if (configValueUtil.isMultiTenancy()) {
  287. TenantAuthorizeModel tenantAuthorizeModel = TenantDataSourceUtil.getCacheModuleAuthorize(UserProvider.getUser().getTenantId());
  288. moduleAuthorize = tenantAuthorizeModel.getModuleIdList();
  289. }
  290. List<SystemEntity> list1 = systemService.getList(null, true, false, true, false, moduleAuthorize);
  291. list.forEach(t -> {
  292. if ("-1".equals(t.getParentId())) {
  293. t.setParentId(t.getSystemId());
  294. }
  295. });
  296. List<UserMenuModel> jsonToList = JsonUtil.getJsonToList(list1, UserMenuModel.class);
  297. jsonToList.forEach(t -> {
  298. t.setType(0);
  299. t.setParentId("-1");
  300. });
  301. list.addAll(jsonToList);
  302. }
  303. List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDotFilter(list);
  304. List<MenuSelectAllVO> menuvo = JsonUtil.getJsonToList(menuList, MenuSelectAllVO.class);
  305. ListVO vo = new ListVO();
  306. vo.setList(menuvo);
  307. return ActionResult.success(vo);
  308. }
  309. /**
  310. * 通过系统id获取菜单列表(下拉框)
  311. *
  312. * @param category 分类
  313. * @return ignore
  314. */
  315. @Operation(summary = "通过系统id获取菜单列表(下拉框)")
  316. @Parameters({
  317. @Parameter(name = "id", description = "主键", required = true),
  318. @Parameter(name = "systemId", description = "系统主键", required = true)
  319. })
  320. @GetMapping("/SelectorFilter/{visualId}")
  321. public ActionResult<ListVO<MenuSelectAllVO>> SelectorFilter(String category, @PathVariable("visualId") String visualId) {
  322. String appCode = RequestContext.getAppCode();
  323. SystemEntity systemEntity = systemService.getInfoByEnCode(appCode);
  324. List<ModuleEntity> data = moduleService.getList(appCode, category, null, 1, 1, null, true);
  325. List<ModuleEntity> moduleList = moduleService.getModuleList(visualId);
  326. List<String> moduleIds = new ArrayList<>();
  327. List<String> systemIds = new ArrayList<>();
  328. if (CollectionUtils.isNotEmpty(moduleList)) {
  329. for (ModuleEntity item : moduleList) {
  330. if ("-1".equals(item.getParentId())) {
  331. systemIds.add(item.getSystemId());
  332. } else {
  333. moduleIds.add(item.getParentId());
  334. }
  335. }
  336. }
  337. List<UserMenuModel> list = JsonUtil.getJsonToList(data, UserMenuModel.class);
  338. List<SystemEntity> list1 = new ArrayList<>();
  339. list1.add(systemEntity);
  340. list.forEach(t -> {
  341. if ("-1".equals(t.getParentId())) {
  342. t.setParentId(t.getSystemId());
  343. }
  344. });
  345. List<UserMenuModel> jsonToList = JsonUtil.getJsonToList(list1, UserMenuModel.class);
  346. jsonToList.forEach(t -> {
  347. t.setType(0);
  348. t.setParentId("-1");
  349. });
  350. list.addAll(jsonToList);
  351. for (UserMenuModel userMenuModel : list) {
  352. if (moduleIds.contains(userMenuModel.getId()) || systemIds.contains(userMenuModel.getId())) {
  353. userMenuModel.setDisabled(true);
  354. }
  355. }
  356. List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDotFilter(list);
  357. List<MenuSelectAllVO> menuvo = JsonUtil.getJsonToList(menuList, MenuSelectAllVO.class);
  358. ListVO vo = new ListVO();
  359. vo.setList(menuvo);
  360. return ActionResult.success(vo);
  361. }
  362. /**
  363. * 获取菜单列表(下拉框)
  364. *
  365. * @param category 分类
  366. * @return ignore
  367. */
  368. @Operation(summary = "获取菜单列表下拉框")
  369. @GetMapping("/Selector/All")
  370. public ActionResult<ListVO<MenuSelectAllVO>> menuSelect(String category) {
  371. List<ModuleEntity> data = moduleService.getList(RequestContext.getAppCode(), category, null, null, 1, null, false);
  372. List<UserMenuModel> list = JsonUtil.getJsonToList(data, UserMenuModel.class);
  373. List<String> moduleAuthorize = new ArrayList<>();
  374. if (configValueUtil.isMultiTenancy()) {
  375. TenantAuthorizeModel tenantAuthorizeModel = TenantDataSourceUtil.getCacheModuleAuthorize(UserProvider.getUser().getTenantId());
  376. moduleAuthorize = tenantAuthorizeModel.getModuleIdList();
  377. }
  378. List<SystemEntity> list1 = systemService.getList(null, true, false, false, false, moduleAuthorize);
  379. list.forEach(t -> {
  380. t.setHasModule(!"1".equals(String.valueOf(t.getType())));
  381. if ("-1".equals(t.getParentId())) {
  382. t.setParentId(t.getSystemId());
  383. }
  384. });
  385. List<UserMenuModel> jsonToList = JsonUtil.getJsonToList(list1, UserMenuModel.class);
  386. jsonToList.forEach(t -> {
  387. t.setType(0);
  388. t.setHasModule(false);
  389. t.setParentId("-1");
  390. });
  391. list.addAll(jsonToList);
  392. List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDotFilter(list);
  393. List<MenuSelectAllVO> menuvo = JsonUtil.getJsonToList(menuList, MenuSelectAllVO.class);
  394. ListVO vo = new ListVO();
  395. vo.setList(menuvo);
  396. return ActionResult.success(vo);
  397. }
  398. /**
  399. * 系统功能类别树形
  400. *
  401. * @return ignore
  402. */
  403. @Operation(summary = "系统功能类别树形")
  404. @GetMapping("/{systemId}/TreeView")
  405. public ActionResult treeView(@PathVariable("systemId") String systemId) {
  406. List<ModuleEntity> moduleList = moduleService.getList(systemId, null, null, null, null, "0", true);
  407. List<TreeViewModel> treeList = new ArrayList<>();
  408. TreeViewModel treeViewModel = new TreeViewModel();
  409. treeViewModel.setId("apply");
  410. treeViewModel.setText("软件开发平台");
  411. treeViewModel.setParentId("0");
  412. treeViewModel.setImg("fa fa-windows apply");
  413. treeList.add(treeViewModel);
  414. for (ModuleEntity entity : moduleList) {
  415. TreeViewModel treeModel = new TreeViewModel();
  416. treeModel.setId(entity.getId());
  417. treeModel.setText(entity.getFullName());
  418. treeModel.setParentId("apply");
  419. treeModel.setImg("fa fa-tags");
  420. treeList.add(treeModel);
  421. }
  422. return ActionResult.success(ListToTreeUtil.toTreeView(treeList));
  423. }
  424. /**
  425. * 更新菜单状态
  426. *
  427. * @param id 主键值
  428. * @return ignore
  429. */
  430. @Operation(summary = "更新菜单状态")
  431. @Parameters({
  432. @Parameter(name = "id", description = "主键值", required = true)
  433. })
  434. @SaCheckPermission("permission.menu")
  435. @PutMapping("/{id}/Actions/State")
  436. public ActionResult upState(@PathVariable("id") String id) {
  437. ModuleEntity entity = moduleService.getInfo(id);
  438. if (entity != null) {
  439. if (entity.getEnabledMark() == null || "1".equals(String.valueOf(entity.getEnabledMark()))) {
  440. entity.setEnabledMark(0);
  441. } else {
  442. entity.setEnabledMark(1);
  443. }
  444. moduleService.update(id, entity);
  445. //清除redis权限
  446. String cacheKey = cacheKeyUtil.getUserAuthorize() + UserProvider.getUser().getUserId();
  447. if (redisUtil.exists(cacheKey)) {
  448. redisUtil.remove(cacheKey);
  449. }
  450. return ActionResult.success(MsgCode.SU004.get());
  451. }
  452. return ActionResult.fail(MsgCode.FA002.get());
  453. }
  454. /**
  455. * 系统菜单导出功能
  456. *
  457. * @param id 接口id
  458. * @return ignore
  459. */
  460. @Operation(summary = "导出系统菜单数据")
  461. @Parameters({
  462. @Parameter(name = "id", description = "主键值", required = true)
  463. })
  464. @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR)
  465. @GetMapping("/{id}/Actions/Export")
  466. public ActionResult exportFile(@PathVariable("id") String id) {
  467. DownloadVO downloadVO = moduleService.exportData(id);
  468. return ActionResult.success(downloadVO);
  469. }
  470. /**
  471. * 系统菜单导入功能
  472. * @param multipartFile 文件
  473. * @param parentId 父级id
  474. * @param category 分类
  475. * @return ignore
  476. */
  477. @Operation(summary = "系统菜单导入功能")
  478. @Parameters({
  479. @Parameter(name = "systemId", description = "系统id", required = true),
  480. })
  481. @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR)
  482. @PostMapping(value = "/Actions/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
  483. public ActionResult importFile(@RequestPart("file") MultipartFile multipartFile,
  484. @RequestParam("parentId") String parentId,
  485. @RequestParam("category") String category,
  486. @RequestParam("type") Integer type) throws DataException {
  487. SystemEntity systemEntity = systemService.getInfoByEnCode(RequestContext.getAppCode());
  488. //判断是否为.bm结尾
  489. if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.SYSTEM_MODULE.getTableName())) {
  490. return ActionResult.fail(MsgCode.IMP002.get());
  491. }
  492. try {
  493. //读取文件内容
  494. String fileContent = FileUtil.getFileContent(multipartFile);
  495. //转model后导入
  496. ModuleExportModel exportModel = JsonUtil.getJsonToBean(fileContent, ModuleExportModel.class);
  497. ModuleEntity moduleEntity = exportModel.getModuleEntity();
  498. if (!category.equals(moduleEntity.getCategory())) {
  499. return ActionResult.fail(MsgCode.SYS018.get(category.toUpperCase()));
  500. }
  501. if (JnpfConst.APP.equals(moduleEntity.getCategory()) && "-1".equals(parentId)) {
  502. return ActionResult.fail(MsgCode.SYS019.get());
  503. }
  504. // 设置系统id然后重新赋值
  505. if (!systemEntity.getId().equals(moduleEntity.getSystemId())) {
  506. moduleEntity.setId(RandomUtil.uuId());
  507. moduleEntity.setEnCode(null);
  508. moduleService.setAutoEnCode(moduleEntity);
  509. moduleEntity.setSystemId(systemEntity.getId());
  510. }
  511. moduleEntity.setParentId(parentId);
  512. //清空同步菜单记录 避免重复
  513. moduleEntity.setModuleId(null);
  514. moduleEntity.setCreatorTime(new Date());
  515. // String enCode = moduleEntity.getEnCode();
  516. // moduleEntity.setEnCode(moduleEntity.getEnCode() + "_" + RandomUtil.getRandomCode());
  517. // if (moduleEntity.getType() == 3) {
  518. // moduleEntity.setUrlAddress(moduleEntity.getUrlAddress().replace(enCode, moduleEntity.getEnCode()));
  519. // }
  520. exportModel.setModuleEntity(moduleEntity);
  521. return moduleService.importData(exportModel, type);
  522. } catch (Exception e) {
  523. throw new DataException(MsgCode.IMP004.get());
  524. }
  525. }
  526. // ------------------多租户调用
  527. /**
  528. * 通过租户id获取菜单
  529. *
  530. * @param tenantMenuModel 模型
  531. * @return ignore
  532. */
  533. @Operation(summary = "通过租户id获取菜单")
  534. @Parameters({
  535. @Parameter(name = "tenantMenuModel", description = "模型", required = true)
  536. })
  537. @NoDataSourceBind
  538. @PostMapping("/Tenant/Menu")
  539. public TenantMenuVO menu(@RequestBody TenantMenuModel tenantMenuModel) throws DataException {
  540. if (configValueUtil.isMultiTenancy()) {
  541. TenantDataSourceUtil.switchTenant(tenantMenuModel.getTenantId());
  542. }
  543. List<SystemEntity> systemEntityList = systemService.getList();
  544. List<String> ids = new ArrayList<>();
  545. if (Objects.nonNull(tenantMenuModel.getIds())) {
  546. ids = tenantMenuModel.getIds();
  547. }
  548. List<String> urlAddressList = new ArrayList<>();
  549. if (Objects.nonNull(tenantMenuModel.getIds())) {
  550. urlAddressList = tenantMenuModel.getUrlAddressList();
  551. }
  552. List<ModuleEntity> moduleEntityList = moduleService.getList(true, new ArrayList<>(), new ArrayList<>());
  553. TenantMenuVO module = module(systemEntityList, moduleEntityList, ids, urlAddressList);
  554. return module;
  555. }
  556. /**
  557. * 功能权限
  558. *
  559. * @param moduleEntityList 所有菜单
  560. * @param systemEntityList 所有应用
  561. * @return
  562. */
  563. private TenantMenuVO module(List<SystemEntity> systemEntityList, List<ModuleEntity> moduleEntityList, List<String> ids, List<String> urlAddressList) {
  564. TenantMenuVO vo = new TenantMenuVO();
  565. // 转树前所有数据
  566. List<TenantMenuTreeModel> moduleAllList = new ArrayList<>();
  567. List<TenantMenuTreeModel> systemList = JsonUtil.getJsonToList(systemEntityList, TenantMenuTreeModel.class);
  568. systemList.forEach(t -> t.setParentId("-1"));
  569. moduleAllList.addAll(systemList);
  570. Map<String, List<ModuleEntity>> moduleMap = moduleEntityList.stream().collect(Collectors.groupingBy(t -> {
  571. if (JnpfConst.WEB.equals(t.getCategory())) {
  572. return JnpfConst.WEB;
  573. } else {
  574. return JnpfConst.APP;
  575. }
  576. }));
  577. List<ModuleEntity> webModuleList = moduleMap.get(JnpfConst.WEB) == null ? new ArrayList<>() : moduleMap.get(JnpfConst.WEB);
  578. List<ModuleEntity> appModuleList = moduleMap.get(JnpfConst.APP) == null ? new ArrayList<>() : moduleMap.get(JnpfConst.APP);
  579. Map<String, ModuleEntity> appModuleMap = appModuleList.stream().collect(Collectors.toMap(ModuleEntity::getId, Function.identity()));
  580. Map<String, String> webIds = new HashMap<>(16);
  581. List<ModuleEntity> temWebList = webModuleList.stream().filter(t -> "-1".equals(t.getParentId())).collect(Collectors.toList());
  582. temWebList.stream().filter(t -> "-1".equals(t.getParentId())).forEach(t -> {
  583. if (!webIds.containsKey(t.getSystemId())) {
  584. ModuleEntity webData = new ModuleEntity();
  585. webData.setId(t.getSystemId() + "1");
  586. t.setParentId(webData.getId());
  587. webData.setFullName("WEB菜单");
  588. webData.setIcon(PermissionConst.PC_ICON);
  589. webData.setParentId(t.getSystemId());
  590. webData.setSystemId(t.getSystemId());
  591. webModuleList.add(webData);
  592. webIds.put(t.getSystemId(), webData.getId());
  593. } else {
  594. t.setParentId(webIds.get(t.getSystemId()) + "");
  595. }
  596. });
  597. List<TenantMenuTreeModel> webReturnModuleList = JsonUtil.getJsonToList(webModuleList, TenantMenuTreeModel.class);
  598. moduleAllList.addAll(webReturnModuleList);
  599. // 处理App菜单
  600. List<ModuleEntity> temList = appModuleList.stream().filter(t -> "-1".equals(t.getParentId()) && !JnpfConst.MAIN_SYSTEM_CODE.equals(t.getEnCode())).collect(Collectors.toList());
  601. Map<String, String> appIds = new HashMap<>(16);
  602. for (ModuleEntity appModuleEntity : temList) {
  603. if (StringUtil.isEmpty(appIds.get(appModuleEntity.getSystemId()))) {
  604. ModuleEntity appData = new ModuleEntity();
  605. appData.setId(appModuleEntity.getSystemId() + appModuleEntity.getSystemId() + "2");
  606. appModuleEntity.setParentId(appData.getId());
  607. appData.setFullName("APP菜单");
  608. appData.setIcon(PermissionConst.APP_ICON);
  609. appData.setParentId(appModuleEntity.getSystemId());
  610. appData.setSystemId(appModuleEntity.getSystemId());
  611. appModuleList.add(appData);
  612. appIds.put(appModuleEntity.getSystemId(), appData.getId());
  613. } else {
  614. appModuleList.remove(appModuleEntity);
  615. ModuleEntity entity = appModuleMap.get(appModuleEntity.getId());
  616. entity.setParentId(appIds.get(appModuleEntity.getSystemId()));
  617. appModuleList.add(entity);
  618. }
  619. }
  620. List<TenantMenuTreeModel> appReturnModuleList = JsonUtil.getJsonToList(appModuleList, TenantMenuTreeModel.class);
  621. moduleAllList.addAll(appReturnModuleList);
  622. List<SumTree<TenantMenuTreeModel>> sumTrees = TreeDotUtils.convertListToTreeDot(moduleAllList);
  623. List<TenantMenuTreeReturnModel> data = new ArrayList<>();
  624. TenantMenuTreeReturnModel workFlowEnabled = new TenantMenuTreeReturnModel();
  625. workFlowEnabled.setId("-999");
  626. workFlowEnabled.setFullName("协同办公");
  627. data.add(workFlowEnabled);
  628. data.addAll(JsonUtil.getJsonToList(sumTrees, TenantMenuTreeReturnModel.class));
  629. vo.setList(data);
  630. List<String> allId = moduleAllList.stream().map(TenantMenuTreeModel::getId).collect(Collectors.toList());
  631. allId.add(workFlowEnabled.getId());
  632. vo.setAll(allId);
  633. List<String> ids0 = moduleService.getListByUrlAddress(ids, urlAddressList).stream().map(ModuleEntity::getId).collect(Collectors.toList());
  634. List<String> selectorIds = allId.stream().filter(t -> !ids0.contains(t)).collect(Collectors.toList());
  635. if (ids.contains("-999")) {
  636. selectorIds.remove("-999");
  637. }
  638. vo.setIds(selectorIds);
  639. return vo;
  640. }
  641. /**
  642. * 通过租户id及菜单id获取菜单
  643. *
  644. * @param tenantMenuModel 模型
  645. * @return ignore
  646. */
  647. @Operation(summary = "通过租户id及菜单id获取菜单")
  648. @Parameters({
  649. @Parameter(name = "tenantMenuModel", description = "模型", required = true)
  650. })
  651. @NoDataSourceBind
  652. @PostMapping("/Tenant/MenuByIds")
  653. public Map MenuByIds(@RequestBody TenantMenuModel tenantMenuModel) throws DataException {
  654. if (configValueUtil.isMultiTenancy()) {
  655. TenantDataSourceUtil.switchTenant(tenantMenuModel.getTenantId());
  656. }
  657. List<ModuleEntity> list = moduleService.getListTenant();
  658. return list.stream().collect(Collectors.toMap(ModuleEntity::getId, ModuleEntity::getUrlAddress));
  659. }
  660. /**
  661. * 获取在线开发“表单”和“流程”类型的菜单数据
  662. */
  663. @Operation(summary = "菜单获取表单列表")
  664. @GetMapping("/Selector/Form")
  665. @Parameters({
  666. @Parameter(name = "systemId", description = "系统id", required = false),
  667. })
  668. public ActionResult getFormList(ModulePagination pagination) {
  669. List<ModuleSelectorVo> list = moduleService.getFormMenuList(pagination);
  670. list.stream().forEach(t -> {
  671. t.setTypeName(Objects.equals(t.getType(), 3) ? "表单" : "流程");
  672. PropertyJsonModel model = JsonUtil.getJsonToBean(t.getPropertyJson(), PropertyJsonModel.class);
  673. if (Objects.equals(t.getType(), 3)) {
  674. t.setFormId(model.getModuleId());
  675. } else {
  676. t.setFlowId(model.getModuleId());
  677. t.setFormId(templateApi.getFormByFlowId(model.getModuleId()));
  678. }
  679. });
  680. PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
  681. return ActionResult.page(list, paginationVO);
  682. }
  683. @Operation(summary = "根据type获取菜单列表")
  684. @GetMapping("/Selector/Page")
  685. public ActionResult getPageList(ModulePagination pagination) {
  686. SystemEntity info = systemService.getInfoByEnCode(RequestContext.getAppCode());
  687. pagination.setSystemId(info.getId());
  688. List<ModuleSelectorVo> list = moduleService.getPageList(pagination);
  689. // PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
  690. return ActionResult.page(list, null);
  691. }
  692. /**
  693. * 报表发布菜单
  694. *
  695. * @return ignore
  696. */
  697. @Operation(summary = "报表发布菜单")
  698. @Parameters({
  699. @Parameter(name = "menuModel", description = "模型", required = true)
  700. })
  701. @PostMapping("/saveReportMenu")
  702. public ActionResult saveReportMenu(@RequestBody VisualMenuModel menuModel) {
  703. try {
  704. pubulishUtil.publishMenu(menuModel);
  705. return ActionResult.success();
  706. } catch (WorkFlowException e) {
  707. return ActionResult.fail(e.getMessage());
  708. }
  709. }
  710. /**
  711. * 报表发布菜单
  712. *
  713. * @return ignore
  714. */
  715. @Operation(summary = "获取报表发布菜单")
  716. @Parameters({
  717. @Parameter(name = "id", description = "主键值", required = true)
  718. })
  719. @PostMapping("/getReportMenu")
  720. public ActionResult getReportMenu(@RequestBody VisualMenuModel menuModel) {
  721. ModuleNameVO moduleNameVO = moduleService.getModuleNameList(menuModel.getId());
  722. return ActionResult.success(moduleNameVO);
  723. }
  724. /**
  725. * 获取系统菜单列表(下拉树形)
  726. */
  727. @Operation(summary = "获取系统菜单列表(下拉树形)")
  728. @GetMapping("/getSystemMenu")
  729. public ActionResult<List<MenuSelectAllVO>> getSystemMenu() {
  730. List<MenuSelectAllVO> systemMenu = moduleService.getSystemMenu(3, Arrays.asList(2, 4), Arrays.asList("web"));
  731. return ActionResult.success(systemMenu);
  732. }
  733. @Operation(summary = "资源管理菜单")
  734. @Parameters({
  735. @Parameter(name = "systemId", description = "系统id", required = true)
  736. })
  737. @GetMapping("/ResourceManage")
  738. public ActionResult<ListVO<MenuListVO>> resourceManage(PaginationMenu paginationMenu) {
  739. String appCode = RequestContext.getAppCode();
  740. List<ModuleEntity> data = moduleService.getList(appCode, null, paginationMenu.getKeyword(), null, 1, null, false);
  741. // 递归查上级
  742. Map<String, ModuleEntity> moduleEntityMap = data.stream().collect(Collectors.toMap(ModuleEntity::getId, Function.identity()));
  743. if (StringUtil.isNotEmpty(paginationMenu.getKeyword())) {
  744. moduleService.getParentModule(data, moduleEntityMap);
  745. }
  746. List<UserMenuModel> list = JsonUtil.getJsonToList(moduleEntityMap.values(), UserMenuModel.class);
  747. list = list.stream().sorted(Comparator.comparing(UserMenuModel::getSortCode, Comparator.nullsLast(Comparator.naturalOrder())).thenComparing(UserMenuModel::getCreatorTime, Comparator.nullsLast(Comparator.reverseOrder()))).collect(Collectors.toList());
  748. List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDot(list);
  749. List<MenuListVO> menuvo = JsonUtil.getJsonToList(menuList, MenuListVO.class);
  750. ListVO vo = new ListVO();
  751. vo.setList(menuvo);
  752. return ActionResult.success(vo);
  753. }
  754. }