refactor(基础模块): 优化菜单ID生成策略. (#556)
This commit is contained in:
parent
65e5ac9046
commit
f946c97ce5
|
|
@ -13,7 +13,6 @@ import org.hswebframework.web.api.crud.entity.GenericTreeSortSupportEntity;
|
|||
import org.hswebframework.web.api.crud.entity.RecordCreationEntity;
|
||||
import org.hswebframework.web.crud.annotation.EnableEntityEvent;
|
||||
import org.hswebframework.web.crud.generator.Generators;
|
||||
import org.hswebframework.web.utils.DigestUtils;
|
||||
import org.hswebframework.web.validator.CreateGroup;
|
||||
|
||||
import javax.persistence.Column;
|
||||
|
|
@ -122,23 +121,6 @@ public class MenuEntity
|
|||
)
|
||||
private Long createTime;
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
if (super.getId() == null) {
|
||||
generateId();
|
||||
}
|
||||
return super.getId();
|
||||
}
|
||||
|
||||
public void generateId() {
|
||||
String id = generateHexId(code, owner);
|
||||
setId(id);
|
||||
}
|
||||
|
||||
public static String generateHexId(String boardId, String owner) {
|
||||
return DigestUtils.md5Hex(String.join(boardId, "|", owner));
|
||||
}
|
||||
|
||||
public boolean isSupportDataAccess() {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import org.hswebframework.web.crud.web.reactive.ReactiveServiceCrudController;
|
|||
import org.hswebframework.web.exception.ValidationException;
|
||||
import org.hswebframework.web.i18n.LocaleUtils;
|
||||
import org.hswebframework.web.system.authorization.defaults.service.DefaultPermissionService;
|
||||
import org.hswebframework.web.validator.CreateGroup;
|
||||
import org.jetlinks.community.auth.configuration.MenuProperties;
|
||||
import org.jetlinks.community.auth.entity.MenuEntity;
|
||||
import org.jetlinks.community.auth.entity.MenuView;
|
||||
|
|
@ -275,17 +274,14 @@ public class MenuController implements ReactiveServiceCrudController<MenuEntity,
|
|||
@Parameter(description = "外部菜单所属应用ID") String appId,
|
||||
@RequestParam @Parameter(description = "菜单所有者") String owner) {
|
||||
return LocaleUtils.currentReactive()
|
||||
.flatMap(locale -> {
|
||||
MenuEntity entity = new MenuEntity();
|
||||
entity.setCode(code);
|
||||
entity.setOwner(owner);
|
||||
entity.tryValidate("code", CreateGroup.class);
|
||||
|
||||
return defaultMenuService
|
||||
.findById(entity.getId())
|
||||
.flatMap(locale -> defaultMenuService
|
||||
.createQuery()
|
||||
.where(MenuEntity::getCode, code)
|
||||
.and(MenuEntity::getOwner, owner)
|
||||
.fetch()
|
||||
.next()
|
||||
.map(menu -> ValidationResult
|
||||
.error(LocaleUtils.resolveMessage("error.id_already_exists", locale)));
|
||||
})
|
||||
.error(LocaleUtils.resolveMessage("error.id_already_exists", locale))))
|
||||
.defaultIfEmpty(ValidationResult.success())
|
||||
.onErrorResume(ValidationException.class, e -> Mono.just(e.getI18nCode())
|
||||
.map(ValidationResult::error));
|
||||
|
|
|
|||
Loading…
Reference in New Issue