From 14a6584d799e7d0c26e6f834985d8b67f247c218 Mon Sep 17 00:00:00 2001 From: chenjg <17688741996@163.com> Date: Tue, 19 Dec 2023 17:09:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E9=99=84=E5=8A=A0?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tenant/api/extramenu/ExtraMenuApi.java | 93 +++++++++++ .../api/extramenu/ExtraMenuDeleteApi.java | 83 ++++++++++ .../tenant/api/extramenu/ExtraMenuGetApi.java | 62 ++++++++ .../api/extramenu/ExtraMenuMoveApi.java | 91 +++++++++++ .../api/extramenu/ExtraMenuSaveApi.java | 138 ++++++++++++++++ .../api/extramenu/ExtraMenuTreeApi.java | 75 +++++++++ .../tenant/dao/mapper/ExtraMenuMapper.java | 50 ++++++ .../tenant/dao/mapper/ExtraMenuMapper.xml | 149 ++++++++++++++++++ .../service/extramenu/ExtraMenuService.java | 22 +++ .../extramenu/ExtraMenuServiceImpl.java | 67 ++++++++ 10 files changed, 830 insertions(+) create mode 100644 src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuApi.java create mode 100644 src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuDeleteApi.java create mode 100644 src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuGetApi.java create mode 100644 src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuMoveApi.java create mode 100644 src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuSaveApi.java create mode 100644 src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuTreeApi.java create mode 100644 src/main/java/neatlogic/module/tenant/dao/mapper/ExtraMenuMapper.java create mode 100644 src/main/java/neatlogic/module/tenant/dao/mapper/ExtraMenuMapper.xml create mode 100644 src/main/java/neatlogic/module/tenant/service/extramenu/ExtraMenuService.java create mode 100644 src/main/java/neatlogic/module/tenant/service/extramenu/ExtraMenuServiceImpl.java diff --git a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuApi.java b/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuApi.java new file mode 100644 index 00000000..dc113a36 --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuApi.java @@ -0,0 +1,93 @@ +/* + * Copyright(c) 2023 NeatLogic Co., Ltd. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package neatlogic.module.tenant.api.extramenu; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.asynchronization.threadlocal.UserContext; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.dto.AuthenticationInfoVo; +import neatlogic.framework.extramenu.dto.ExtraMenuVo; +import neatlogic.framework.restful.annotation.Description; +import neatlogic.framework.restful.annotation.OperationType; +import neatlogic.framework.restful.annotation.Output; +import neatlogic.framework.restful.annotation.Param; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.module.tenant.dao.mapper.ExtraMenuMapper; +import neatlogic.module.tenant.service.extramenu.ExtraMenuService; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +@Service + +@OperationType(type = OperationTypeEnum.SEARCH) +public class ExtraMenuApi extends PrivateApiComponentBase { + + @Resource + private ExtraMenuMapper extraMenuMapper; + + @Resource + private ExtraMenuService extraMenuService; + + @Override + public String getName() { + return "nmtae.extramenuapi.getname"; + } + + @Output({@Param(name = "Return", type = ApiParamType.JSONOBJECT, explode = ExtraMenuVo.class)}) + @Description(desc = "nmtae.extramenuapi.getname") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + ExtraMenuVo root = extraMenuService.buildRootExtraMenu(); + AuthenticationInfoVo authenticationInfoVo = UserContext.get().getAuthenticationInfoVo(); + // 已授权的节点 + List idList = extraMenuMapper.getAuthorizedExtraMenuIdList(UserContext.get().getUserUuid(true), + authenticationInfoVo.getTeamUuidList(), authenticationInfoVo.getRoleUuidList()); + if (CollectionUtils.isEmpty(idList)) { + return null; + } + idList.add(ExtraMenuVo.ROOT_ID); + List list = extraMenuMapper.getExtraMenuForTree(root.getLft(), root.getRht()); + if (!list.isEmpty()) { + Map map = new LinkedHashMap<>(); + list.add(root); + for (ExtraMenuVo vo : list) { + // 过滤无权限以及未激活的节点 + if (!idList.contains(vo.getId()) || vo.getIsActive().intValue() == 0) { + continue; + } + map.put(vo.getId(), vo); + } + for (Long id : map.keySet()) { + ExtraMenuVo parent = map.get(map.get(id).getParentId()); + map.get(id).setParent(parent); + } + } + if (root.getChildren() != null && root.getChildren().size() > 0) { + return extraMenuService.removeEmptyDirectory(root.getChildren().get(0)); + } else { + return null; + } + } + + @Override + public String getToken() { + return "/extramenu/list"; + } +} diff --git a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuDeleteApi.java b/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuDeleteApi.java new file mode 100644 index 00000000..8303d10f --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuDeleteApi.java @@ -0,0 +1,83 @@ +/* + * Copyright(c) 2023 NeatLogic Co., Ltd. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package neatlogic.module.tenant.api.extramenu; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.auth.label.EXTRA_MENU_MODIFY; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.extramenu.constvalue.ExtraMenuType; +import neatlogic.framework.extramenu.exception.ExtraMenuRootNotAllowedException; +import neatlogic.framework.lrcode.LRCodeManager; +import neatlogic.framework.restful.annotation.Description; +import neatlogic.framework.restful.annotation.Input; +import neatlogic.framework.restful.annotation.OperationType; +import neatlogic.framework.restful.annotation.Param; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.module.tenant.dao.mapper.ExtraMenuMapper; +import neatlogic.framework.extramenu.dto.ExtraMenuVo; +import neatlogic.framework.extramenu.exception.ExtraMenuExistChildrenException; +import neatlogic.framework.extramenu.exception.ExtraMenuNotFoundException; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; + +@Service +@Transactional +@AuthAction(action = EXTRA_MENU_MODIFY.class) +@OperationType(type = OperationTypeEnum.DELETE) +public class ExtraMenuDeleteApi extends PrivateApiComponentBase { + + @Resource + private ExtraMenuMapper extraMenuMapper; + + @Override + public String getName() { + return "nmtae.extramenudeleteapi.getname"; + } + + @Input({@Param(name = "id", type = ApiParamType.LONG, isRequired = true, desc = "common.id")}) + @Description(desc = "nmtae.extramenudeleteapi.getname") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + Long id = paramObj.getLong("id"); + ExtraMenuVo vo = extraMenuMapper.getExtraMenuById(id); + if (vo == null) { + throw new ExtraMenuNotFoundException(id); + } + if (ExtraMenuVo.ROOT_ID.equals(vo.getParentId())) { + throw new ExtraMenuRootNotAllowedException(); + } + if (ExtraMenuType.DIRECTORY.getType() == vo.getType()) { + List list = extraMenuMapper.getExtraMenuForTree(vo.getLft(), vo.getRht()); + if (CollectionUtils.isNotEmpty(list) && list.size() > 1) { + // 存在子节点 + throw new ExtraMenuExistChildrenException(vo.getName()); + } + } + LRCodeManager.beforeDeleteTreeNode("extramenu", "id", "parent_id", id); + extraMenuMapper.deleteExtraMenuAuthorityByMenuId(id); + extraMenuMapper.deleteExtraMenuById(id); + return null; + } + + @Override + public String getToken() { + return "/extramenu/delete"; + } +} diff --git a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuGetApi.java b/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuGetApi.java new file mode 100644 index 00000000..1b140770 --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuGetApi.java @@ -0,0 +1,62 @@ +/* + * Copyright(c) 2023 NeatLogic Co., Ltd. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package neatlogic.module.tenant.api.extramenu; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.auth.label.EXTRA_MENU_MODIFY; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.dto.AuthorityVo; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.module.tenant.dao.mapper.ExtraMenuMapper; +import neatlogic.framework.extramenu.dto.ExtraMenuVo; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +@Service + +@AuthAction(action = EXTRA_MENU_MODIFY.class) +@OperationType(type = OperationTypeEnum.SEARCH) +public class ExtraMenuGetApi extends PrivateApiComponentBase { + + @Resource + private ExtraMenuMapper extraMenuMapper; + + @Override + public String getName() { + return "nmtae.extramenugetapi.getname"; + } + + @Input({@Param(name = "id", type = ApiParamType.LONG, isRequired = true, desc = "common.id")}) + @Output({@Param(name = "Return", type = ApiParamType.JSONOBJECT, explode = ExtraMenuVo.class)}) + @Description(desc = "nmtae.extramenugetapi.getname") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + ExtraMenuVo vo = extraMenuMapper.getExtraMenuById(paramObj.getLong("id")); + if (vo != null) { + List authorityVoList = extraMenuMapper.getExtraMenuAuthorityListByMenuId(vo.getId()); + vo.setAuthorityVoList(authorityVoList); + } + return vo; + } + + @Override + public String getToken() { + return "/extramenu/get"; + } +} diff --git a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuMoveApi.java b/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuMoveApi.java new file mode 100644 index 00000000..ff1d301a --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuMoveApi.java @@ -0,0 +1,91 @@ +/* + * Copyright(c) 2023 NeatLogic Co., Ltd. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package neatlogic.module.tenant.api.extramenu; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.auth.label.EXTRA_MENU_MODIFY; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.extramenu.constvalue.ExtraMenuType; +import neatlogic.framework.extramenu.dto.ExtraMenuVo; +import neatlogic.framework.extramenu.exception.ExtraMenuNameRepeatException; +import neatlogic.framework.extramenu.exception.ExtraMenuNotAllowedAddException; +import neatlogic.framework.extramenu.exception.ExtraMenuRootException; +import neatlogic.framework.lrcode.LRCodeManager; +import neatlogic.framework.lrcode.constvalue.MoveType; +import neatlogic.framework.restful.annotation.Description; +import neatlogic.framework.restful.annotation.Input; +import neatlogic.framework.restful.annotation.OperationType; +import neatlogic.framework.restful.annotation.Param; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.module.tenant.dao.mapper.ExtraMenuMapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; + +@Service + +@AuthAction(action = EXTRA_MENU_MODIFY.class) +@OperationType(type = OperationTypeEnum.UPDATE) +@Transactional +public class ExtraMenuMoveApi extends PrivateApiComponentBase { + + @Resource + private ExtraMenuMapper extraMenuMapper; + + @Override + public String getName() { + return "nmtae.extramenumoveapi.getname"; + } + + @Input({ + @Param(name = "id", type = ApiParamType.LONG, isRequired = true, + desc = "nmtae.extramenumoveapi.input.param.id.desc"), + @Param(name = "targetId", type = ApiParamType.LONG, isRequired = true, + desc = "nmtae.extramenumoveapi.input.param.targetid.desc"), + @Param(name = "moveType", type = ApiParamType.ENUM, rule = "inner,prev,next", isRequired = true, + desc = "nmtae.extramenumoveapi.input.param.movetype.desc")}) + @Description(desc = "nmtae.extramenumoveapi.getname") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + Long id = paramObj.getLong("id"); + Long targetId = paramObj.getLong("targetId"); + String moveType = paramObj.getString("moveType"); + LRCodeManager.moveTreeNode("extramenu", "id", "parent_id", id, MoveType.getMoveType(moveType), targetId); + + ExtraMenuVo vo = extraMenuMapper.getExtraMenuById(id); + if (ExtraMenuVo.ROOT_ID.equals(vo.getParentId())) { + if (extraMenuMapper.checkExtraMenuRootCount(ExtraMenuVo.ROOT_ID) > 1) { + throw new ExtraMenuRootException(); + } + } else { + // 判断移动后的父节点是否为目录节点 + ExtraMenuVo parentVo = extraMenuMapper.getExtraMenuById(vo.getParentId()); + if (parentVo.getType().intValue() != ExtraMenuType.DIRECTORY.getType()) { + throw new ExtraMenuNotAllowedAddException(); + } + } + // 判断移动后是否在同一父目录下节点是否存在相同名称 + if (extraMenuMapper.checkExtraMenuNameIsRepeat(vo) > 0) { + throw new ExtraMenuNameRepeatException(vo.getName()); + } + return null; + } + + @Override + public String getToken() { + return "/extramenu/move"; + } +} diff --git a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuSaveApi.java b/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuSaveApi.java new file mode 100644 index 00000000..017cc6a0 --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuSaveApi.java @@ -0,0 +1,138 @@ +/* + * Copyright(c) 2023 NeatLogic Co., Ltd. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package neatlogic.module.tenant.api.extramenu; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.auth.label.EXTRA_MENU_MODIFY; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.dto.AuthorityVo; +import neatlogic.framework.dto.FieldValidResultVo; +import neatlogic.framework.extramenu.constvalue.ExtraMenuType; +import neatlogic.framework.extramenu.exception.*; +import neatlogic.framework.lrcode.LRCodeManager; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.IValid; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.framework.util.RegexUtils; +import neatlogic.module.tenant.dao.mapper.ExtraMenuMapper; +import neatlogic.framework.extramenu.dto.ExtraMenuVo; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; + +@Service + +@AuthAction(action = EXTRA_MENU_MODIFY.class) +@OperationType(type = OperationTypeEnum.UPDATE) +@Transactional +public class ExtraMenuSaveApi extends PrivateApiComponentBase { + + @Resource + private ExtraMenuMapper extraMenuMapper; + + @Override + public String getToken() { + return "/extramenu/save"; + } + + @Override + public String getName() { + return "nmtae.extramenusaveapi.getname"; + } + + @Input({@Param(name = "id", type = ApiParamType.LONG, desc = "id"), + @Param(name = "name", type = ApiParamType.STRING, xss = true, isRequired = true, maxLength = 50, + desc = "common.name"), + @Param(name = "type", type = ApiParamType.ENUM, rule = "0,1", isRequired = true, + desc = "nmtae.extramenusaveapi.input.param.type.desc"), + @Param(name = "isActive", type = ApiParamType.ENUM, rule = "0,1", isRequired = true, desc = "common.isactive"), + @Param(name = "url", type = ApiParamType.REGEX, desc = "URL", rule = RegexUtils.CONNECT_URL), + @Param(name = "description", type = ApiParamType.STRING, desc = "common.description"), + @Param(name = "authorityList", type = ApiParamType.JSONARRAY, isRequired = true, desc = "common.authlist"), + @Param(name = "parentId", type = ApiParamType.LONG, desc = "common.parentid")}) + @Output({@Param(name = "id", type = ApiParamType.LONG, desc = "id")}) + @Description(desc = "nmtae.extramenusaveapi.getname") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + Long id = paramObj.getLong("id"); + ExtraMenuVo vo = JSON.toJavaObject(paramObj, ExtraMenuVo.class); + if (vo.getParentId() == null) { + vo.setParentId(ExtraMenuVo.ROOT_ID); + } else { + // 判断父节点是否为目录 + ExtraMenuVo parentVo = extraMenuMapper.getExtraMenuById(vo.getParentId()); + if (parentVo == null || parentVo.getType() != null && parentVo.getType() == ExtraMenuType.MENU.getType()) { + throw new ExtraMenuNotAllowedAddException(); + } + } + if (extraMenuMapper.checkExtraMenuNameIsRepeat(vo) > 0) { + throw new ExtraMenuNameRepeatException(vo.getName()); + } + if (vo.getType() != null && ExtraMenuType.MENU.getType() == vo.getType().intValue()) { + if (StringUtils.isBlank(vo.getUrl())) { + throw new ExtraMenuParamException("url"); + } + } + if (id != null) { + if (extraMenuMapper.checkExtraMenuIsExists(id) == 0) { + throw new ExtraMenuNotFoundException(id); + } + extraMenuMapper.deleteExtraMenuAuthorityByMenuId(id); + extraMenuMapper.updateExtraMenuById(vo); + } else { + if (!ExtraMenuVo.ROOT_ID.equals(vo.getParentId())) { + if (extraMenuMapper.checkExtraMenuIsExists(vo.getParentId()) == 0) { + throw new ExtraMenuNotFoundException(vo.getParentId()); + } + } else { + if (extraMenuMapper.checkExtraMenuRootCount(ExtraMenuVo.ROOT_ID) == 1) { + throw new ExtraMenuRootException(); + } + } + int lft = LRCodeManager.beforeAddTreeNode("extramenu", "id", "parent_id", vo.getParentId()); + vo.setParentId(vo.getParentId()); + vo.setLft(lft); + vo.setRht(lft + 1); + extraMenuMapper.insertExtraMenu(vo); + } + + List authorityList = vo.getAuthorityVoList(); + if (CollectionUtils.isNotEmpty(authorityList)) { + for (AuthorityVo authorityVo : authorityList) { + extraMenuMapper.insertExtraMenuAuthority(authorityVo, vo.getId()); + } + } + return vo.getId(); + } + + public IValid name() { + return value -> { + ExtraMenuVo vo = JSON.toJavaObject(value, ExtraMenuVo.class); + if (vo.getParentId() == null) { + vo.setParentId(ExtraMenuVo.ROOT_ID); + } + if (extraMenuMapper.checkExtraMenuNameIsRepeat(vo) > 0) { + return new FieldValidResultVo(new ExtraMenuNameRepeatException(vo.getName())); + } + return new FieldValidResultVo(); + }; + } +} diff --git a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuTreeApi.java b/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuTreeApi.java new file mode 100644 index 00000000..026c32a3 --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuTreeApi.java @@ -0,0 +1,75 @@ +/* + * Copyright(c) 2023 NeatLogic Co., Ltd. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package neatlogic.module.tenant.api.extramenu; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.auth.label.EXTRA_MENU_MODIFY; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.module.tenant.dao.mapper.ExtraMenuMapper; +import neatlogic.framework.extramenu.dto.ExtraMenuVo; +import neatlogic.module.tenant.service.extramenu.ExtraMenuService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service + +@AuthAction(action = EXTRA_MENU_MODIFY.class) +@OperationType(type = OperationTypeEnum.SEARCH) +public class ExtraMenuTreeApi extends PrivateApiComponentBase { + + @Resource + private ExtraMenuMapper extraMenuMapper; + @Resource + private ExtraMenuService extraMenuService; + + @Override + public String getName() { + return "nmtae.extramenutreeapi.getname"; + } + + @Output({@Param(name = "Return", type = ApiParamType.JSONOBJECT, explode = ExtraMenuVo.class)}) + @Description(desc = "nmtae.extramenutreeapi.getname") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + ExtraMenuVo root = extraMenuService.buildRootExtraMenu(); + List list = extraMenuMapper.getExtraMenuForTree(root.getLft(), root.getRht()); + if (!list.isEmpty()) { + Map map = new HashMap<>(); + list.add(root); + list.forEach(o -> map.put(o.getId(), o)); + for (ExtraMenuVo vo : list) { + ExtraMenuVo parent = map.get(vo.getParentId()); + vo.setParent(parent); + } + } + if (root.getChildren() != null && root.getChildren().size() > 0) { + return root.getChildren().get(0); + } else { + return null; + } + } + + @Override + public String getToken() { + return "/extramenu/tree"; + } +} diff --git a/src/main/java/neatlogic/module/tenant/dao/mapper/ExtraMenuMapper.java b/src/main/java/neatlogic/module/tenant/dao/mapper/ExtraMenuMapper.java new file mode 100644 index 00000000..191ee0d3 --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/dao/mapper/ExtraMenuMapper.java @@ -0,0 +1,50 @@ +/* + * Copyright(c) 2023 NeatLogic Co., Ltd. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package neatlogic.module.tenant.dao.mapper; + +import neatlogic.framework.dto.AuthorityVo; +import neatlogic.framework.extramenu.dto.ExtraMenuVo; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface ExtraMenuMapper { + + Integer getMaxRhtCode(); + + int insertExtraMenu(ExtraMenuVo vo); + + int insertExtraMenuAuthority(@Param("authorityVo") AuthorityVo authorityVo, @Param("menuId") Long menuId); + + int checkExtraMenuNameIsRepeat(ExtraMenuVo vo); + + int checkExtraMenuIsExists(Long id); + + int updateExtraMenuById(ExtraMenuVo vo); + + int deleteExtraMenuAuthorityByMenuId(Long id); + + List getExtraMenuForTree(@Param("lft") Integer lft, @Param("rht") Integer rht); + + int checkExtraMenuRootCount(Long parentId); + + ExtraMenuVo getExtraMenuById(Long id); + + List getExtraMenuAuthorityListByMenuId(Long id); + + int deleteExtraMenuById(Long id); + + List getAuthorizedExtraMenuIdList(@Param("userUuid") String userUuid, + @Param("teamUuidList") List teamUuidList, @Param("roleUuidList") List roleUuidList); +} diff --git a/src/main/java/neatlogic/module/tenant/dao/mapper/ExtraMenuMapper.xml b/src/main/java/neatlogic/module/tenant/dao/mapper/ExtraMenuMapper.xml new file mode 100644 index 00000000..151f676b --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/dao/mapper/ExtraMenuMapper.xml @@ -0,0 +1,149 @@ + + + + + + + + insert into `extramenu`(`id`, + `name`, + `type`, + `is_active`, + `url`, + `description`, + `parent_id`, + `lft`, + `rht`) + values (#{id}, + #{name}, + #{type}, + #{isActive}, + #{url}, + #{description}, + #{parentId}, + #{lft}, + #{rht}) + + + INSERT INTO `extramenu_authority` (`menu_id`, + `type`, + `uuid`) + VALUES (#{menuId}, + #{authorityVo.type}, + #{authorityVo.uuid}) + + + update `extramenu` + set `name` = #{name}, + `is_active` = #{isActive}, + `url` = #{url}, + `description` = #{description} + where `id` = #{id} + + + DELETE + FROM `extramenu_authority` + WHERE `menu_id` = #{value} + + + DELETE + FROM `extramenu` + WHERE `id` = #{value} + + + + + + + + + + + diff --git a/src/main/java/neatlogic/module/tenant/service/extramenu/ExtraMenuService.java b/src/main/java/neatlogic/module/tenant/service/extramenu/ExtraMenuService.java new file mode 100644 index 00000000..f0399cc9 --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/service/extramenu/ExtraMenuService.java @@ -0,0 +1,22 @@ +/* + * Copyright(c) 2023 NeatLogic Co., Ltd. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package neatlogic.module.tenant.service.extramenu; + +import neatlogic.framework.extramenu.dto.ExtraMenuVo; + +public interface ExtraMenuService { + ExtraMenuVo buildRootExtraMenu(); + + ExtraMenuVo removeEmptyDirectory(ExtraMenuVo extraMenuVo); +} diff --git a/src/main/java/neatlogic/module/tenant/service/extramenu/ExtraMenuServiceImpl.java b/src/main/java/neatlogic/module/tenant/service/extramenu/ExtraMenuServiceImpl.java new file mode 100644 index 00000000..75c1b9c8 --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/service/extramenu/ExtraMenuServiceImpl.java @@ -0,0 +1,67 @@ +/* + * Copyright(c) 2023 NeatLogic Co., Ltd. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package neatlogic.module.tenant.service.extramenu; + +import neatlogic.framework.extramenu.constvalue.ExtraMenuType; +import neatlogic.module.tenant.dao.mapper.ExtraMenuMapper; +import neatlogic.framework.extramenu.dto.ExtraMenuVo; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Iterator; + +@Service +public class ExtraMenuServiceImpl implements ExtraMenuService { + @Resource + ExtraMenuMapper extraMenuMapper; + + @Override + public ExtraMenuVo buildRootExtraMenu() { + Integer maxRhtCode = extraMenuMapper.getMaxRhtCode(); + ExtraMenuVo extraMenuVo = new ExtraMenuVo(); + extraMenuVo.setId(ExtraMenuVo.ROOT_ID); + extraMenuVo.setName(ExtraMenuVo.ROOT_NAME); + extraMenuVo.setParentId(ExtraMenuVo.ROOT_PARENTID); + extraMenuVo.setIsActive(1); + extraMenuVo.setLft(1); + extraMenuVo.setRht(maxRhtCode == null ? 2 : maxRhtCode.intValue() + 1); + return extraMenuVo; + } + + @Override + public ExtraMenuVo removeEmptyDirectory(ExtraMenuVo vo) { + if (vo == null) { + return null; + } + if (vo.getType() != null && vo.getType() == ExtraMenuType.DIRECTORY.getType()) { + if (vo.getChildren() == null) { + return null; + } + Iterator iterator = vo.getChildren().listIterator(); + while (iterator.hasNext()) { + ExtraMenuVo childrenVo = iterator.next(); + if (removeEmptyDirectory(childrenVo) == null) { + iterator.remove(); + } + } + if (vo.getChildren().size() > 0) { + return vo; + } else { + return null; + } + } else { + return vo; + } + } +} -- Gitee From e1e5f82cb71faa15e5ad1a804f43ab06b61f1d6f Mon Sep 17 00:00:00 2001 From: chenjg <17688741996@163.com> Date: Tue, 19 Dec 2023 18:17:41 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E9=99=84=E5=8A=A0?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ExtraMenuDeleteApi.java => DeleteExtraMenuApi.java} | 2 +- .../extramenu/{ExtraMenuGetApi.java => GetExtraMenuApi.java} | 2 +- .../api/extramenu/{ExtraMenuApi.java => ListExtraMenuApi.java} | 2 +- .../extramenu/{ExtraMenuMoveApi.java => MoveExtraMenuApi.java} | 2 +- .../extramenu/{ExtraMenuSaveApi.java => SaveExtraMenuApi.java} | 2 +- .../extramenu/{ExtraMenuTreeApi.java => TreeExtraMenuApi.java} | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) rename src/main/java/neatlogic/module/tenant/api/extramenu/{ExtraMenuDeleteApi.java => DeleteExtraMenuApi.java} (98%) rename src/main/java/neatlogic/module/tenant/api/extramenu/{ExtraMenuGetApi.java => GetExtraMenuApi.java} (97%) rename src/main/java/neatlogic/module/tenant/api/extramenu/{ExtraMenuApi.java => ListExtraMenuApi.java} (98%) rename src/main/java/neatlogic/module/tenant/api/extramenu/{ExtraMenuMoveApi.java => MoveExtraMenuApi.java} (98%) rename src/main/java/neatlogic/module/tenant/api/extramenu/{ExtraMenuSaveApi.java => SaveExtraMenuApi.java} (98%) rename src/main/java/neatlogic/module/tenant/api/extramenu/{ExtraMenuTreeApi.java => TreeExtraMenuApi.java} (97%) diff --git a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuDeleteApi.java b/src/main/java/neatlogic/module/tenant/api/extramenu/DeleteExtraMenuApi.java similarity index 98% rename from src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuDeleteApi.java rename to src/main/java/neatlogic/module/tenant/api/extramenu/DeleteExtraMenuApi.java index 8303d10f..75fcf588 100644 --- a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuDeleteApi.java +++ b/src/main/java/neatlogic/module/tenant/api/extramenu/DeleteExtraMenuApi.java @@ -41,7 +41,7 @@ import java.util.List; @Transactional @AuthAction(action = EXTRA_MENU_MODIFY.class) @OperationType(type = OperationTypeEnum.DELETE) -public class ExtraMenuDeleteApi extends PrivateApiComponentBase { +public class DeleteExtraMenuApi extends PrivateApiComponentBase { @Resource private ExtraMenuMapper extraMenuMapper; diff --git a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuGetApi.java b/src/main/java/neatlogic/module/tenant/api/extramenu/GetExtraMenuApi.java similarity index 97% rename from src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuGetApi.java rename to src/main/java/neatlogic/module/tenant/api/extramenu/GetExtraMenuApi.java index 1b140770..3156fc98 100644 --- a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuGetApi.java +++ b/src/main/java/neatlogic/module/tenant/api/extramenu/GetExtraMenuApi.java @@ -32,7 +32,7 @@ import java.util.List; @AuthAction(action = EXTRA_MENU_MODIFY.class) @OperationType(type = OperationTypeEnum.SEARCH) -public class ExtraMenuGetApi extends PrivateApiComponentBase { +public class GetExtraMenuApi extends PrivateApiComponentBase { @Resource private ExtraMenuMapper extraMenuMapper; diff --git a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuApi.java b/src/main/java/neatlogic/module/tenant/api/extramenu/ListExtraMenuApi.java similarity index 98% rename from src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuApi.java rename to src/main/java/neatlogic/module/tenant/api/extramenu/ListExtraMenuApi.java index dc113a36..3ec6be92 100644 --- a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuApi.java +++ b/src/main/java/neatlogic/module/tenant/api/extramenu/ListExtraMenuApi.java @@ -37,7 +37,7 @@ import java.util.Map; @Service @OperationType(type = OperationTypeEnum.SEARCH) -public class ExtraMenuApi extends PrivateApiComponentBase { +public class ListExtraMenuApi extends PrivateApiComponentBase { @Resource private ExtraMenuMapper extraMenuMapper; diff --git a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuMoveApi.java b/src/main/java/neatlogic/module/tenant/api/extramenu/MoveExtraMenuApi.java similarity index 98% rename from src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuMoveApi.java rename to src/main/java/neatlogic/module/tenant/api/extramenu/MoveExtraMenuApi.java index ff1d301a..b0787536 100644 --- a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuMoveApi.java +++ b/src/main/java/neatlogic/module/tenant/api/extramenu/MoveExtraMenuApi.java @@ -40,7 +40,7 @@ import javax.annotation.Resource; @AuthAction(action = EXTRA_MENU_MODIFY.class) @OperationType(type = OperationTypeEnum.UPDATE) @Transactional -public class ExtraMenuMoveApi extends PrivateApiComponentBase { +public class MoveExtraMenuApi extends PrivateApiComponentBase { @Resource private ExtraMenuMapper extraMenuMapper; diff --git a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuSaveApi.java b/src/main/java/neatlogic/module/tenant/api/extramenu/SaveExtraMenuApi.java similarity index 98% rename from src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuSaveApi.java rename to src/main/java/neatlogic/module/tenant/api/extramenu/SaveExtraMenuApi.java index 017cc6a0..0353ce87 100644 --- a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuSaveApi.java +++ b/src/main/java/neatlogic/module/tenant/api/extramenu/SaveExtraMenuApi.java @@ -43,7 +43,7 @@ import java.util.List; @AuthAction(action = EXTRA_MENU_MODIFY.class) @OperationType(type = OperationTypeEnum.UPDATE) @Transactional -public class ExtraMenuSaveApi extends PrivateApiComponentBase { +public class SaveExtraMenuApi extends PrivateApiComponentBase { @Resource private ExtraMenuMapper extraMenuMapper; diff --git a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuTreeApi.java b/src/main/java/neatlogic/module/tenant/api/extramenu/TreeExtraMenuApi.java similarity index 97% rename from src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuTreeApi.java rename to src/main/java/neatlogic/module/tenant/api/extramenu/TreeExtraMenuApi.java index 026c32a3..a1c3a039 100644 --- a/src/main/java/neatlogic/module/tenant/api/extramenu/ExtraMenuTreeApi.java +++ b/src/main/java/neatlogic/module/tenant/api/extramenu/TreeExtraMenuApi.java @@ -34,7 +34,7 @@ import java.util.Map; @AuthAction(action = EXTRA_MENU_MODIFY.class) @OperationType(type = OperationTypeEnum.SEARCH) -public class ExtraMenuTreeApi extends PrivateApiComponentBase { +public class TreeExtraMenuApi extends PrivateApiComponentBase { @Resource private ExtraMenuMapper extraMenuMapper; -- Gitee