| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786 |
- package jnpf.base.controller;
- import cn.dev33.satoken.annotation.SaCheckPermission;
- import cn.dev33.satoken.annotation.SaMode;
- import io.swagger.v3.oas.annotations.Operation;
- import io.swagger.v3.oas.annotations.Parameter;
- import io.swagger.v3.oas.annotations.Parameters;
- import io.swagger.v3.oas.annotations.tags.Tag;
- import jakarta.validation.Valid;
- import jnpf.base.ActionResult;
- import jnpf.base.entity.*;
- import jnpf.base.model.module.*;
- import jnpf.base.model.online.VisualMenuModel;
- import jnpf.base.service.*;
- import jnpf.base.util.visualUtil.PubulishUtil;
- import jnpf.base.vo.DownloadVO;
- import jnpf.base.vo.ListVO;
- import jnpf.base.vo.PaginationVO;
- import jnpf.config.ConfigValueUtil;
- import jnpf.constant.JnpfConst;
- import jnpf.constant.MsgCode;
- import jnpf.constant.PermissionConst;
- import jnpf.database.util.TenantDataSourceUtil;
- import jnpf.emnus.ModuleTypeEnum;
- import jnpf.exception.DataException;
- import jnpf.exception.WorkFlowException;
- import jnpf.model.FlowWorkModel;
- import jnpf.model.UserMenuModel;
- import jnpf.model.tenant.*;
- import jnpf.permission.entity.AuthorizeEntity;
- import jnpf.permission.entity.PermissionGroupEntity;
- import jnpf.permission.model.user.vo.BaseInfoVo;
- import jnpf.permission.service.AuthorizeService;
- import jnpf.permission.service.PermissionGroupService;
- import jnpf.permission.service.UserService;
- import jnpf.util.*;
- import jnpf.util.context.RequestContext;
- import jnpf.util.treeutil.ListToTreeUtil;
- import jnpf.util.treeutil.SumTree;
- import jnpf.util.treeutil.TreeViewModel;
- import jnpf.util.treeutil.newtreeutil.TreeDotUtils;
- import jnpf.util.type.AuthorizeType;
- import jnpf.workflow.service.TemplateApi;
- import org.apache.commons.collections4.CollectionUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.MediaType;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import java.util.*;
- import java.util.function.Function;
- import java.util.stream.Collectors;
- /**
- * 系统功能
- *
- * @author JNPF开发平台组
- * @version V3.1.0
- * @copyright 引迈信息技术有限公司
- * @date 2019年9月27日 上午9:18
- */
- @Tag(name = "系统菜单", description = "menu")
- @RestController
- @RequestMapping("/api/system/Menu")
- public class ModuleController extends SuperController<ModuleService, ModuleEntity> {
- @Autowired
- private ModuleService moduleService;
- @Autowired
- private RedisUtil redisUtil;
- @Autowired
- private CacheKeyUtil cacheKeyUtil;
- @Autowired
- private SystemService systemService;
- @Autowired
- private ConfigValueUtil configValueUtil;
- @Autowired
- private TemplateApi templateApi;
- @Autowired
- private PubulishUtil pubulishUtil;
- @Operation(summary = "获取菜单列表")
- @Parameters({
- @Parameter(name = "systemId", description = "系统id", required = true)
- })
- @GetMapping("/ModuleBySystem")
- public ActionResult<ListVO<MenuListVO>> list(PaginationMenu paginationMenu) {
- String appCode = RequestContext.getAppCode();
- List<ModuleEntity> data = moduleService.getList(appCode, paginationMenu.getCategory(), paginationMenu.getKeyword(), paginationMenu.getType(), paginationMenu.getEnabledMark(), null, false);
- // 递归查上级
- Map<String, ModuleEntity> moduleEntityMap = data.stream().collect(Collectors.toMap(ModuleEntity::getId, Function.identity()));
- if (StringUtil.isNotEmpty(paginationMenu.getKeyword())) {
- moduleService.getParentModule(data, moduleEntityMap);
- }
- List<UserMenuModel> list = JsonUtil.getJsonToList(moduleEntityMap.values(), UserMenuModel.class);
- for (UserMenuModel item : list) {
- if (Objects.equals(item.getType(), 3)) {
- if (Objects.equals(item.getIsButtonAuthorize(), 1)
- || Objects.equals(item.getIsColumnAuthorize(), 1)
- || Objects.equals(item.getIsDataAuthorize(), 1)
- || Objects.equals(item.getIsFormAuthorize(), 1)) {
- item.setHasPermission(1);
- }
- //添加视图标识
- if (StringUtil.isNotEmpty(item.getPropertyJson())) {
- PropertyJsonModel model = JsonUtil.getJsonToBean(item.getPropertyJson(), PropertyJsonModel.class);
- item.setWebType(model.getWebType());
- if (Objects.equals(model.getWebType(), 4)) {
- item.setHasPermission(0);
- }
- }
- } else {
- item.setHasPermission(1);
- }
- }
- list = list.stream().sorted(Comparator.comparing(UserMenuModel::getSortCode, Comparator.nullsLast(Comparator.naturalOrder())).thenComparing(UserMenuModel::getCreatorTime, Comparator.nullsLast(Comparator.reverseOrder()))).collect(Collectors.toList());
- List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDot(list);
- List<MenuListVO> menuvo = JsonUtil.getJsonToList(menuList, MenuListVO.class);
- ListVO vo = new ListVO();
- vo.setList(menuvo);
- return ActionResult.success(vo);
- }
- @Operation(summary = "新建系统功能")
- @Parameters({
- @Parameter(name = "moduleCrForm", description = "实体对象", required = true)
- })
- @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR)
- @PostMapping
- public ActionResult create(@RequestBody @Valid ModuleCrForm moduleCrForm) {
- SystemEntity info = systemService.getInfoByEnCode(RequestContext.getAppCode());
- moduleCrForm.setSystemId(info.getId());
- ModuleEntity entity = JsonUtil.getJsonToBean(moduleCrForm, ModuleEntity.class);
- if (entity.getUrlAddress() != null) {
- entity.setUrlAddress(entity.getUrlAddress().trim());
- }
- if (moduleService.isExistByFullName(entity, moduleCrForm.getCategory(), moduleCrForm.getSystemId())) {
- return ActionResult.fail(MsgCode.EXIST001.get());
- }
- if (moduleService.isExistByEnCode(entity, moduleCrForm.getCategory(), moduleCrForm.getSystemId())) {
- return ActionResult.fail(MsgCode.EXIST002.get());
- }
- if (moduleService.isExistByAddress(entity, moduleCrForm.getCategory(), moduleCrForm.getSystemId())) {
- return ActionResult.fail(MsgCode.EXIST104.get());
- }
- moduleService.create(entity);
- return ActionResult.success(MsgCode.SU001.get());
- }
- @Operation(summary = "更新系统功能")
- @Parameters({
- @Parameter(name = "id", description = "主键值", required = true),
- @Parameter(name = "moduleUpForm", description = "实体对象", required = true)
- })
- @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR)
- @PutMapping("/{id}")
- public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid ModuleUpForm moduleUpForm) {
- SystemEntity info = systemService.getInfoByEnCode(RequestContext.getAppCode());
- moduleUpForm.setSystemId(info.getId());
- ModuleEntity entity = JsonUtil.getJsonToBean(moduleUpForm, ModuleEntity.class);
- //判断如果是目录则不能修改类型
- ModuleEntity moduleEntity = moduleService.getInfo(id);
- if (moduleEntity != null && moduleEntity.getType() == 1 && entity.getType() != 1 && moduleService.getListByParentId(moduleEntity.getId()).size() > 0) {
- return ActionResult.fail(MsgCode.SYS016.get());
- }
- entity.setId(id);
- if (entity.getUrlAddress() != null) {
- entity.setUrlAddress(entity.getUrlAddress().trim());
- }
- if (moduleService.isExistByFullName(entity, moduleUpForm.getCategory(), moduleUpForm.getSystemId())) {
- return ActionResult.fail(MsgCode.EXIST001.get());
- }
- if (moduleService.isExistByEnCode(entity, moduleUpForm.getCategory(), moduleUpForm.getSystemId())) {
- return ActionResult.fail(MsgCode.EXIST002.get());
- }
- if (moduleService.isExistByAddress(entity, moduleUpForm.getCategory(), moduleUpForm.getSystemId())) {
- return ActionResult.fail(MsgCode.EXIST104.get());
- }
- boolean flag = moduleService.update(id, entity);
- if (!flag) {
- return ActionResult.fail(MsgCode.FA002.get());
- }
- return ActionResult.success(MsgCode.SU004.get());
- }
- @Operation(summary = "删除系统功能")
- @Parameters({
- @Parameter(name = "id", description = "主键值", required = true)
- })
- @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR)
- @DeleteMapping("/{id}")
- public ActionResult delete(@PathVariable("id") String id) {
- ModuleEntity entity = moduleService.getInfo(id);
- if (entity != null) {
- List<ModuleEntity> list = moduleService.getList(false, new ArrayList<>(), new ArrayList<>()).stream().filter(t -> t.getParentId().equals(entity.getId())).collect(Collectors.toList());
- if (list.size() > 0) {
- return ActionResult.fail(MsgCode.SYS017.get());
- }
- moduleService.delete(entity);
- return ActionResult.success(MsgCode.SU003.get());
- }
- return ActionResult.fail(MsgCode.FA003.get());
- }
- @Operation(summary = "获取菜单信息")
- @Parameters({
- @Parameter(name = "id", description = "主键值", required = true)
- })
- @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR)
- @GetMapping("/{id}")
- public ActionResult<ModuleInfoVO> info(@PathVariable("id") String id) throws DataException {
- ModuleEntity entity = moduleService.getInfo(id);
- ModuleInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, ModuleInfoVO.class);
- return ActionResult.success(vo);
- }
- //+++++++++++++++++++++++++++增删改查end+++++++++++++++++++++++++++++++++++++++++++++++
- /**
- * 获取菜单列表(下拉框)
- *
- * @param category 分类
- * @param id 主键
- * @return ignore
- */
- @Operation(summary = "获取菜单列表(下拉框)")
- @Parameters({
- @Parameter(name = "category", description = "分类"),
- @Parameter(name = "id", description = "主键", required = true)
- })
- @GetMapping("/Selector/{id}")
- public ActionResult<ListVO<MenuSelectVO>> treeView(String category, @PathVariable("id") String id) {
- //应用编码
- String appCode = RequestContext.getAppCode();
- List<ModuleEntity> data = moduleService.getList(appCode, category, null, 1, null, null, false);
- if (!"0".equals(id)) {
- data.remove(moduleService.getInfo(id));
- }
- List<UserMenuModel> list = JsonUtil.getJsonToList(data, UserMenuModel.class);
- List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDotFilter(list);
- List<MenuSelectVO> menuvo = JsonUtil.getJsonToList(menuList, MenuSelectVO.class);
- ListVO vo = new ListVO();
- vo.setList(menuvo);
- return ActionResult.success(vo);
- }
- /**
- * 获取开发平台菜单
- *
- * @return ignore
- */
- @Operation(summary = "获取开发平台菜单")
- @GetMapping("/SystemSelector")
- public ActionResult<ListVO<MenuSelectVO>> mainSystemSelector() {
- SystemEntity mainSystem = systemService.getInfoByEnCode(JnpfConst.MAIN_SYSTEM_CODE);
- List<ModuleEntity> data = moduleService.getList(mainSystem.getId(), null, null, null, 1, null, false);
- List<UserMenuModel> list = JsonUtil.getJsonToList(data, UserMenuModel.class);
- list.forEach(t -> {
- if ("-1".equals(t.getParentId())) {
- t.setParentId(t.getSystemId());
- }
- });
- UserMenuModel userMenuModel = JsonUtil.getJsonToBean(mainSystem, UserMenuModel.class);
- userMenuModel.setType(0);
- userMenuModel.setParentId("-1");
- list.add(userMenuModel);
- List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDotFilter(list);
- List<MenuSelectVO> menuvo = JsonUtil.getJsonToList(menuList, MenuSelectVO.class);
- ListVO vo = new ListVO();
- vo.setList(menuvo);
- return ActionResult.success(vo);
- }
- /**
- * 通过系统id获取菜单列表(下拉框)
- *
- * @param category 分类
- * @param id 主键
- * @return ignore
- */
- @Operation(summary = "通过系统id获取菜单列表(下拉框)")
- @Parameters({
- @Parameter(name = "id", description = "主键", required = true),
- @Parameter(name = "systemId", description = "系统主键", required = true),
- @Parameter(name = "enabledMark", description = "查询类型:null-全部,0-禁用,1-启用", required = false)
- })
- @GetMapping("/Selector/{id}/{systemId}")
- public ActionResult<ListVO<MenuSelectAllVO>> treeView(@PathVariable("id") String id,
- @PathVariable("systemId") String systemId,
- @RequestParam("category") String category,
- @RequestParam(value = "enabledMark", required = false) Integer enabledMark) {
- List<ModuleEntity> data = moduleService.getList(systemId, category, null, 1, enabledMark, null, true);
- if (!"0".equals(id)) {
- data.remove(moduleService.getInfo(id));
- }
- List<UserMenuModel> list = JsonUtil.getJsonToList(data, UserMenuModel.class);
- if ("0".equals(systemId)) {
- List<String> moduleAuthorize = new ArrayList<>();
- if (configValueUtil.isMultiTenancy()) {
- TenantAuthorizeModel tenantAuthorizeModel = TenantDataSourceUtil.getCacheModuleAuthorize(UserProvider.getUser().getTenantId());
- moduleAuthorize = tenantAuthorizeModel.getModuleIdList();
- }
- List<SystemEntity> list1 = systemService.getList(null, true, false, true, false, moduleAuthorize);
- list.forEach(t -> {
- if ("-1".equals(t.getParentId())) {
- t.setParentId(t.getSystemId());
- }
- });
- List<UserMenuModel> jsonToList = JsonUtil.getJsonToList(list1, UserMenuModel.class);
- jsonToList.forEach(t -> {
- t.setType(0);
- t.setParentId("-1");
- });
- list.addAll(jsonToList);
- }
- List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDotFilter(list);
- List<MenuSelectAllVO> menuvo = JsonUtil.getJsonToList(menuList, MenuSelectAllVO.class);
- ListVO vo = new ListVO();
- vo.setList(menuvo);
- return ActionResult.success(vo);
- }
- /**
- * 通过系统id获取菜单列表(下拉框)
- *
- * @param category 分类
- * @return ignore
- */
- @Operation(summary = "通过系统id获取菜单列表(下拉框)")
- @Parameters({
- @Parameter(name = "id", description = "主键", required = true),
- @Parameter(name = "systemId", description = "系统主键", required = true)
- })
- @GetMapping("/SelectorFilter/{visualId}")
- public ActionResult<ListVO<MenuSelectAllVO>> SelectorFilter(String category, @PathVariable("visualId") String visualId) {
- String appCode = RequestContext.getAppCode();
- SystemEntity systemEntity = systemService.getInfoByEnCode(appCode);
- List<ModuleEntity> data = moduleService.getList(appCode, category, null, 1, 1, null, true);
- List<ModuleEntity> moduleList = moduleService.getModuleList(visualId);
- List<String> moduleIds = new ArrayList<>();
- List<String> systemIds = new ArrayList<>();
- if (CollectionUtils.isNotEmpty(moduleList)) {
- for (ModuleEntity item : moduleList) {
- if ("-1".equals(item.getParentId())) {
- systemIds.add(item.getSystemId());
- } else {
- moduleIds.add(item.getParentId());
- }
- }
- }
- List<UserMenuModel> list = JsonUtil.getJsonToList(data, UserMenuModel.class);
- List<SystemEntity> list1 = new ArrayList<>();
- list1.add(systemEntity);
- list.forEach(t -> {
- if ("-1".equals(t.getParentId())) {
- t.setParentId(t.getSystemId());
- }
- });
- List<UserMenuModel> jsonToList = JsonUtil.getJsonToList(list1, UserMenuModel.class);
- jsonToList.forEach(t -> {
- t.setType(0);
- t.setParentId("-1");
- });
- list.addAll(jsonToList);
- for (UserMenuModel userMenuModel : list) {
- if (moduleIds.contains(userMenuModel.getId()) || systemIds.contains(userMenuModel.getId())) {
- userMenuModel.setDisabled(true);
- }
- }
- List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDotFilter(list);
- List<MenuSelectAllVO> menuvo = JsonUtil.getJsonToList(menuList, MenuSelectAllVO.class);
- ListVO vo = new ListVO();
- vo.setList(menuvo);
- return ActionResult.success(vo);
- }
- /**
- * 获取菜单列表(下拉框)
- *
- * @param category 分类
- * @return ignore
- */
- @Operation(summary = "获取菜单列表下拉框")
- @GetMapping("/Selector/All")
- public ActionResult<ListVO<MenuSelectAllVO>> menuSelect(String category) {
- List<ModuleEntity> data = moduleService.getList(RequestContext.getAppCode(), category, null, null, 1, null, false);
- List<UserMenuModel> list = JsonUtil.getJsonToList(data, UserMenuModel.class);
- List<String> moduleAuthorize = new ArrayList<>();
- if (configValueUtil.isMultiTenancy()) {
- TenantAuthorizeModel tenantAuthorizeModel = TenantDataSourceUtil.getCacheModuleAuthorize(UserProvider.getUser().getTenantId());
- moduleAuthorize = tenantAuthorizeModel.getModuleIdList();
- }
- List<SystemEntity> list1 = systemService.getList(null, true, false, false, false, moduleAuthorize);
- list.forEach(t -> {
- t.setHasModule(!"1".equals(String.valueOf(t.getType())));
- if ("-1".equals(t.getParentId())) {
- t.setParentId(t.getSystemId());
- }
- });
- List<UserMenuModel> jsonToList = JsonUtil.getJsonToList(list1, UserMenuModel.class);
- jsonToList.forEach(t -> {
- t.setType(0);
- t.setHasModule(false);
- t.setParentId("-1");
- });
- list.addAll(jsonToList);
- List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDotFilter(list);
- List<MenuSelectAllVO> menuvo = JsonUtil.getJsonToList(menuList, MenuSelectAllVO.class);
- ListVO vo = new ListVO();
- vo.setList(menuvo);
- return ActionResult.success(vo);
- }
- /**
- * 系统功能类别树形
- *
- * @return ignore
- */
- @Operation(summary = "系统功能类别树形")
- @GetMapping("/{systemId}/TreeView")
- public ActionResult treeView(@PathVariable("systemId") String systemId) {
- List<ModuleEntity> moduleList = moduleService.getList(systemId, null, null, null, null, "0", true);
- List<TreeViewModel> treeList = new ArrayList<>();
- TreeViewModel treeViewModel = new TreeViewModel();
- treeViewModel.setId("apply");
- treeViewModel.setText("软件开发平台");
- treeViewModel.setParentId("0");
- treeViewModel.setImg("fa fa-windows apply");
- treeList.add(treeViewModel);
- for (ModuleEntity entity : moduleList) {
- TreeViewModel treeModel = new TreeViewModel();
- treeModel.setId(entity.getId());
- treeModel.setText(entity.getFullName());
- treeModel.setParentId("apply");
- treeModel.setImg("fa fa-tags");
- treeList.add(treeModel);
- }
- return ActionResult.success(ListToTreeUtil.toTreeView(treeList));
- }
- /**
- * 更新菜单状态
- *
- * @param id 主键值
- * @return ignore
- */
- @Operation(summary = "更新菜单状态")
- @Parameters({
- @Parameter(name = "id", description = "主键值", required = true)
- })
- @SaCheckPermission("permission.menu")
- @PutMapping("/{id}/Actions/State")
- public ActionResult upState(@PathVariable("id") String id) {
- ModuleEntity entity = moduleService.getInfo(id);
- if (entity != null) {
- if (entity.getEnabledMark() == null || "1".equals(String.valueOf(entity.getEnabledMark()))) {
- entity.setEnabledMark(0);
- } else {
- entity.setEnabledMark(1);
- }
- moduleService.update(id, entity);
- //清除redis权限
- String cacheKey = cacheKeyUtil.getUserAuthorize() + UserProvider.getUser().getUserId();
- if (redisUtil.exists(cacheKey)) {
- redisUtil.remove(cacheKey);
- }
- return ActionResult.success(MsgCode.SU004.get());
- }
- return ActionResult.fail(MsgCode.FA002.get());
- }
- /**
- * 系统菜单导出功能
- *
- * @param id 接口id
- * @return ignore
- */
- @Operation(summary = "导出系统菜单数据")
- @Parameters({
- @Parameter(name = "id", description = "主键值", required = true)
- })
- @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR)
- @GetMapping("/{id}/Actions/Export")
- public ActionResult exportFile(@PathVariable("id") String id) {
- DownloadVO downloadVO = moduleService.exportData(id);
- return ActionResult.success(downloadVO);
- }
- /**
- * 系统菜单导入功能
- * @param multipartFile 文件
- * @param parentId 父级id
- * @param category 分类
- * @return ignore
- */
- @Operation(summary = "系统菜单导入功能")
- @Parameters({
- @Parameter(name = "systemId", description = "系统id", required = true),
- })
- @SaCheckPermission(value = {"permission.menu", "appConfig.appMenu"}, mode = SaMode.OR)
- @PostMapping(value = "/Actions/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
- public ActionResult importFile(@RequestPart("file") MultipartFile multipartFile,
- @RequestParam("parentId") String parentId,
- @RequestParam("category") String category,
- @RequestParam("type") Integer type) throws DataException {
- SystemEntity systemEntity = systemService.getInfoByEnCode(RequestContext.getAppCode());
- //判断是否为.bm结尾
- if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.SYSTEM_MODULE.getTableName())) {
- return ActionResult.fail(MsgCode.IMP002.get());
- }
- try {
- //读取文件内容
- String fileContent = FileUtil.getFileContent(multipartFile);
- //转model后导入
- ModuleExportModel exportModel = JsonUtil.getJsonToBean(fileContent, ModuleExportModel.class);
- ModuleEntity moduleEntity = exportModel.getModuleEntity();
- if (!category.equals(moduleEntity.getCategory())) {
- return ActionResult.fail(MsgCode.SYS018.get(category.toUpperCase()));
- }
- if (JnpfConst.APP.equals(moduleEntity.getCategory()) && "-1".equals(parentId)) {
- return ActionResult.fail(MsgCode.SYS019.get());
- }
- // 设置系统id然后重新赋值
- if (!systemEntity.getId().equals(moduleEntity.getSystemId())) {
- moduleEntity.setId(RandomUtil.uuId());
- moduleEntity.setEnCode(null);
- moduleService.setAutoEnCode(moduleEntity);
- moduleEntity.setSystemId(systemEntity.getId());
- }
- moduleEntity.setParentId(parentId);
- //清空同步菜单记录 避免重复
- moduleEntity.setModuleId(null);
- moduleEntity.setCreatorTime(new Date());
- // String enCode = moduleEntity.getEnCode();
- // moduleEntity.setEnCode(moduleEntity.getEnCode() + "_" + RandomUtil.getRandomCode());
- // if (moduleEntity.getType() == 3) {
- // moduleEntity.setUrlAddress(moduleEntity.getUrlAddress().replace(enCode, moduleEntity.getEnCode()));
- // }
- exportModel.setModuleEntity(moduleEntity);
- return moduleService.importData(exportModel, type);
- } catch (Exception e) {
- throw new DataException(MsgCode.IMP004.get());
- }
- }
- // ------------------多租户调用
- /**
- * 通过租户id获取菜单
- *
- * @param tenantMenuModel 模型
- * @return ignore
- */
- @Operation(summary = "通过租户id获取菜单")
- @Parameters({
- @Parameter(name = "tenantMenuModel", description = "模型", required = true)
- })
- @NoDataSourceBind
- @PostMapping("/Tenant/Menu")
- public TenantMenuVO menu(@RequestBody TenantMenuModel tenantMenuModel) throws DataException {
- if (configValueUtil.isMultiTenancy()) {
- TenantDataSourceUtil.switchTenant(tenantMenuModel.getTenantId());
- }
- List<SystemEntity> systemEntityList = systemService.getList();
- List<String> ids = new ArrayList<>();
- if (Objects.nonNull(tenantMenuModel.getIds())) {
- ids = tenantMenuModel.getIds();
- }
- List<String> urlAddressList = new ArrayList<>();
- if (Objects.nonNull(tenantMenuModel.getIds())) {
- urlAddressList = tenantMenuModel.getUrlAddressList();
- }
- List<ModuleEntity> moduleEntityList = moduleService.getList(true, new ArrayList<>(), new ArrayList<>());
- TenantMenuVO module = module(systemEntityList, moduleEntityList, ids, urlAddressList);
- return module;
- }
- /**
- * 功能权限
- *
- * @param moduleEntityList 所有菜单
- * @param systemEntityList 所有应用
- * @return
- */
- private TenantMenuVO module(List<SystemEntity> systemEntityList, List<ModuleEntity> moduleEntityList, List<String> ids, List<String> urlAddressList) {
- TenantMenuVO vo = new TenantMenuVO();
- // 转树前所有数据
- List<TenantMenuTreeModel> moduleAllList = new ArrayList<>();
- List<TenantMenuTreeModel> systemList = JsonUtil.getJsonToList(systemEntityList, TenantMenuTreeModel.class);
- systemList.forEach(t -> t.setParentId("-1"));
- moduleAllList.addAll(systemList);
- Map<String, List<ModuleEntity>> moduleMap = moduleEntityList.stream().collect(Collectors.groupingBy(t -> {
- if (JnpfConst.WEB.equals(t.getCategory())) {
- return JnpfConst.WEB;
- } else {
- return JnpfConst.APP;
- }
- }));
- List<ModuleEntity> webModuleList = moduleMap.get(JnpfConst.WEB) == null ? new ArrayList<>() : moduleMap.get(JnpfConst.WEB);
- List<ModuleEntity> appModuleList = moduleMap.get(JnpfConst.APP) == null ? new ArrayList<>() : moduleMap.get(JnpfConst.APP);
- Map<String, ModuleEntity> appModuleMap = appModuleList.stream().collect(Collectors.toMap(ModuleEntity::getId, Function.identity()));
- Map<String, String> webIds = new HashMap<>(16);
- List<ModuleEntity> temWebList = webModuleList.stream().filter(t -> "-1".equals(t.getParentId())).collect(Collectors.toList());
- temWebList.stream().filter(t -> "-1".equals(t.getParentId())).forEach(t -> {
- if (!webIds.containsKey(t.getSystemId())) {
- ModuleEntity webData = new ModuleEntity();
- webData.setId(t.getSystemId() + "1");
- t.setParentId(webData.getId());
- webData.setFullName("WEB菜单");
- webData.setIcon(PermissionConst.PC_ICON);
- webData.setParentId(t.getSystemId());
- webData.setSystemId(t.getSystemId());
- webModuleList.add(webData);
- webIds.put(t.getSystemId(), webData.getId());
- } else {
- t.setParentId(webIds.get(t.getSystemId()) + "");
- }
- });
- List<TenantMenuTreeModel> webReturnModuleList = JsonUtil.getJsonToList(webModuleList, TenantMenuTreeModel.class);
- moduleAllList.addAll(webReturnModuleList);
- // 处理App菜单
- List<ModuleEntity> temList = appModuleList.stream().filter(t -> "-1".equals(t.getParentId()) && !JnpfConst.MAIN_SYSTEM_CODE.equals(t.getEnCode())).collect(Collectors.toList());
- Map<String, String> appIds = new HashMap<>(16);
- for (ModuleEntity appModuleEntity : temList) {
- if (StringUtil.isEmpty(appIds.get(appModuleEntity.getSystemId()))) {
- ModuleEntity appData = new ModuleEntity();
- appData.setId(appModuleEntity.getSystemId() + appModuleEntity.getSystemId() + "2");
- appModuleEntity.setParentId(appData.getId());
- appData.setFullName("APP菜单");
- appData.setIcon(PermissionConst.APP_ICON);
- appData.setParentId(appModuleEntity.getSystemId());
- appData.setSystemId(appModuleEntity.getSystemId());
- appModuleList.add(appData);
- appIds.put(appModuleEntity.getSystemId(), appData.getId());
- } else {
- appModuleList.remove(appModuleEntity);
- ModuleEntity entity = appModuleMap.get(appModuleEntity.getId());
- entity.setParentId(appIds.get(appModuleEntity.getSystemId()));
- appModuleList.add(entity);
- }
- }
- List<TenantMenuTreeModel> appReturnModuleList = JsonUtil.getJsonToList(appModuleList, TenantMenuTreeModel.class);
- moduleAllList.addAll(appReturnModuleList);
- List<SumTree<TenantMenuTreeModel>> sumTrees = TreeDotUtils.convertListToTreeDot(moduleAllList);
- List<TenantMenuTreeReturnModel> data = new ArrayList<>();
- TenantMenuTreeReturnModel workFlowEnabled = new TenantMenuTreeReturnModel();
- workFlowEnabled.setId("-999");
- workFlowEnabled.setFullName("协同办公");
- data.add(workFlowEnabled);
- data.addAll(JsonUtil.getJsonToList(sumTrees, TenantMenuTreeReturnModel.class));
- vo.setList(data);
- List<String> allId = moduleAllList.stream().map(TenantMenuTreeModel::getId).collect(Collectors.toList());
- allId.add(workFlowEnabled.getId());
- vo.setAll(allId);
- List<String> ids0 = moduleService.getListByUrlAddress(ids, urlAddressList).stream().map(ModuleEntity::getId).collect(Collectors.toList());
- List<String> selectorIds = allId.stream().filter(t -> !ids0.contains(t)).collect(Collectors.toList());
- if (ids.contains("-999")) {
- selectorIds.remove("-999");
- }
- vo.setIds(selectorIds);
- return vo;
- }
- /**
- * 通过租户id及菜单id获取菜单
- *
- * @param tenantMenuModel 模型
- * @return ignore
- */
- @Operation(summary = "通过租户id及菜单id获取菜单")
- @Parameters({
- @Parameter(name = "tenantMenuModel", description = "模型", required = true)
- })
- @NoDataSourceBind
- @PostMapping("/Tenant/MenuByIds")
- public Map MenuByIds(@RequestBody TenantMenuModel tenantMenuModel) throws DataException {
- if (configValueUtil.isMultiTenancy()) {
- TenantDataSourceUtil.switchTenant(tenantMenuModel.getTenantId());
- }
- List<ModuleEntity> list = moduleService.getListTenant();
- return list.stream().collect(Collectors.toMap(ModuleEntity::getId, ModuleEntity::getUrlAddress));
- }
- /**
- * 获取在线开发“表单”和“流程”类型的菜单数据
- */
- @Operation(summary = "菜单获取表单列表")
- @GetMapping("/Selector/Form")
- @Parameters({
- @Parameter(name = "systemId", description = "系统id", required = false),
- })
- public ActionResult getFormList(ModulePagination pagination) {
- List<ModuleSelectorVo> list = moduleService.getFormMenuList(pagination);
- list.stream().forEach(t -> {
- t.setTypeName(Objects.equals(t.getType(), 3) ? "表单" : "流程");
- PropertyJsonModel model = JsonUtil.getJsonToBean(t.getPropertyJson(), PropertyJsonModel.class);
- if (Objects.equals(t.getType(), 3)) {
- t.setFormId(model.getModuleId());
- } else {
- t.setFlowId(model.getModuleId());
- t.setFormId(templateApi.getFormByFlowId(model.getModuleId()));
- }
- });
- PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
- return ActionResult.page(list, paginationVO);
- }
- @Operation(summary = "根据type获取菜单列表")
- @GetMapping("/Selector/Page")
- public ActionResult getPageList(ModulePagination pagination) {
- SystemEntity info = systemService.getInfoByEnCode(RequestContext.getAppCode());
- pagination.setSystemId(info.getId());
- List<ModuleSelectorVo> list = moduleService.getPageList(pagination);
- // PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
- return ActionResult.page(list, null);
- }
- /**
- * 报表发布菜单
- *
- * @return ignore
- */
- @Operation(summary = "报表发布菜单")
- @Parameters({
- @Parameter(name = "menuModel", description = "模型", required = true)
- })
- @PostMapping("/saveReportMenu")
- public ActionResult saveReportMenu(@RequestBody VisualMenuModel menuModel) {
- try {
- pubulishUtil.publishMenu(menuModel);
- return ActionResult.success();
- } catch (WorkFlowException e) {
- return ActionResult.fail(e.getMessage());
- }
- }
- /**
- * 报表发布菜单
- *
- * @return ignore
- */
- @Operation(summary = "获取报表发布菜单")
- @Parameters({
- @Parameter(name = "id", description = "主键值", required = true)
- })
- @PostMapping("/getReportMenu")
- public ActionResult getReportMenu(@RequestBody VisualMenuModel menuModel) {
- ModuleNameVO moduleNameVO = moduleService.getModuleNameList(menuModel.getId());
- return ActionResult.success(moduleNameVO);
- }
- /**
- * 获取系统菜单列表(下拉树形)
- */
- @Operation(summary = "获取系统菜单列表(下拉树形)")
- @GetMapping("/getSystemMenu")
- public ActionResult<List<MenuSelectAllVO>> getSystemMenu() {
- List<MenuSelectAllVO> systemMenu = moduleService.getSystemMenu(3, Arrays.asList(2, 4), Arrays.asList("web"));
- return ActionResult.success(systemMenu);
- }
- @Operation(summary = "资源管理菜单")
- @Parameters({
- @Parameter(name = "systemId", description = "系统id", required = true)
- })
- @GetMapping("/ResourceManage")
- public ActionResult<ListVO<MenuListVO>> resourceManage(PaginationMenu paginationMenu) {
- String appCode = RequestContext.getAppCode();
- List<ModuleEntity> data = moduleService.getList(appCode, null, paginationMenu.getKeyword(), null, 1, null, false);
- // 递归查上级
- Map<String, ModuleEntity> moduleEntityMap = data.stream().collect(Collectors.toMap(ModuleEntity::getId, Function.identity()));
- if (StringUtil.isNotEmpty(paginationMenu.getKeyword())) {
- moduleService.getParentModule(data, moduleEntityMap);
- }
- List<UserMenuModel> list = JsonUtil.getJsonToList(moduleEntityMap.values(), UserMenuModel.class);
- list = list.stream().sorted(Comparator.comparing(UserMenuModel::getSortCode, Comparator.nullsLast(Comparator.naturalOrder())).thenComparing(UserMenuModel::getCreatorTime, Comparator.nullsLast(Comparator.reverseOrder()))).collect(Collectors.toList());
- List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDot(list);
- List<MenuListVO> menuvo = JsonUtil.getJsonToList(menuList, MenuListVO.class);
- ListVO vo = new ListVO();
- vo.setList(menuvo);
- return ActionResult.success(vo);
- }
- }
|