refactor: 优化菜单和关系服务及资源类的代码结构
重构了菜单和关系服务的代码,包括方法重命名、参数顺序调整以及SQL查询逻辑的优化。同时,更新了相关资源类以适配服务层的更改,提升了代码的可读性和可维护性。
This commit is contained in:
parent
dfeb86842f
commit
e0781b0f8c
@ -85,6 +85,10 @@ public abstract class BaseRepository {
|
||||
if (condition == null) continue;
|
||||
String operator = condition.get("op") != null ? condition.get("op").toString() : "";
|
||||
Object value = condition.get("value");
|
||||
Object filter = condition.get("filter");
|
||||
if (filter != null) {
|
||||
sql.append(" AND (").append(filter).append(")");
|
||||
}
|
||||
if (operator.isEmpty() || value == null) continue;
|
||||
// 构建SQL条件
|
||||
if (operator.equalsIgnoreCase("IFNULL")) {
|
||||
@ -145,6 +149,10 @@ public abstract class BaseRepository {
|
||||
}
|
||||
String operator = condition.get("op") != null ? condition.get("op").toString() : "";
|
||||
Object value = condition.get("value");
|
||||
Object filter = condition.get("filter");
|
||||
if (filter != null) {
|
||||
wheres.append(" AND (").append(filter).append(")");
|
||||
}
|
||||
if (operator.isEmpty() || value == null) continue;
|
||||
// 构建SQL条件
|
||||
if (operator.equalsIgnoreCase("IFNULL")) {
|
||||
|
||||
@ -96,7 +96,7 @@ public class MenuService {
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Flux<Map<String, Object>> getMenusTree(String table, Map<String, Object> params, Pageable pageable) {
|
||||
public Flux<Map<String, Object>> getTree(String table, Map<String, Object> params, Pageable pageable) {
|
||||
return SecurityUtils.getCurrentOrganization()
|
||||
.flatMapMany(organization ->
|
||||
menuRepository
|
||||
@ -128,7 +128,7 @@ public class MenuService {
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Flux<Map<String, Object>> getMenusRelation(String table, Map<String, Object> params, Pageable pageable) {
|
||||
public Flux<Map<String, Object>> getRelation(String table, Map<String, Object> params, Pageable pageable) {
|
||||
return SecurityUtils.getCurrentUserLogin()
|
||||
.flatMapMany(login -> {
|
||||
params.put(
|
||||
@ -137,7 +137,7 @@ public class MenuService {
|
||||
login +
|
||||
"'))"
|
||||
);
|
||||
return getMenusTree(table, params, pageable);
|
||||
return getTree(table, params, pageable);
|
||||
});
|
||||
}
|
||||
|
||||
@ -155,13 +155,6 @@ public class MenuService {
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Flux<Menu> getVisibleMenus() {
|
||||
return SecurityUtils.getCurrentOrganization()
|
||||
.map(organization -> menuRepository.findVisibleMenus(organization))
|
||||
.flatMapMany(menus -> menus);
|
||||
}
|
||||
|
||||
private Flux<Menu> getChildren(String organization, String number) {
|
||||
return menuRepository
|
||||
.findByParentNumber(organization, number)
|
||||
|
||||
@ -27,10 +27,10 @@ public class RelationService {
|
||||
private final R2dbcEntityTemplate r2dbcEntityTemplate;
|
||||
private final DatabaseClient databaseClient;
|
||||
|
||||
public RelationService(RelationRepository relationRepository, R2dbcEntityTemplate r2dbcEntityTemplate, DatabaseClient databaseClient) {
|
||||
public RelationService(DatabaseClient databaseClient, RelationRepository relationRepository, R2dbcEntityTemplate r2dbcEntityTemplate) {
|
||||
this.databaseClient = databaseClient;
|
||||
this.relationRepository = relationRepository;
|
||||
this.r2dbcEntityTemplate = r2dbcEntityTemplate;
|
||||
this.databaseClient = databaseClient;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.vxnet.pms.web.rest;
|
||||
|
||||
import com.vxnet.pms.domain.Menu;
|
||||
import com.vxnet.pms.security.SecurityUtils;
|
||||
import com.vxnet.pms.service.MenuService;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.Arrays;
|
||||
@ -72,7 +73,7 @@ public class MenuResource {
|
||||
}
|
||||
|
||||
@GetMapping("/menus/tree")
|
||||
public Mono<ResponseEntity<Flux<Map<String, Object>>>> getMenusTree(
|
||||
public Mono<ResponseEntity<Flux<Map<String, Object>>>> getTree(
|
||||
@RequestParam Map<String, Object> params,
|
||||
@ParameterObject @PageableDefault(size = Integer.MAX_VALUE) Pageable pageable
|
||||
) {
|
||||
@ -82,12 +83,12 @@ public class MenuResource {
|
||||
return menuService
|
||||
.countMenus(table, params)
|
||||
.map(total ->
|
||||
ResponseEntity.ok().header("X-Total-Count", String.valueOf(total)).body(menuService.getMenusTree(table, params, pageable))
|
||||
ResponseEntity.ok().header("X-Total-Count", String.valueOf(total)).body(menuService.getTree(table, params, pageable))
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping("/menus/relation")
|
||||
public Mono<ResponseEntity<Flux<Map<String, Object>>>> getMenusRelation(
|
||||
public Mono<ResponseEntity<Flux<Map<String, Object>>>> getRelation(
|
||||
@RequestParam Map<String, Object> params,
|
||||
@ParameterObject @PageableDefault(size = Integer.MAX_VALUE) Pageable pageable
|
||||
) {
|
||||
@ -97,14 +98,33 @@ public class MenuResource {
|
||||
return menuService
|
||||
.countMenus(table, params)
|
||||
.map(total ->
|
||||
ResponseEntity.ok()
|
||||
.header("X-Total-Count", String.valueOf(total))
|
||||
.body(menuService.getMenusRelation(table, params, pageable))
|
||||
ResponseEntity.ok().header("X-Total-Count", String.valueOf(total)).body(menuService.getRelation(table, params, pageable))
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping("/menus/visible")
|
||||
public Mono<ResponseEntity<Flux<Menu>>> getVisibleMenus() {
|
||||
return Mono.just(ResponseEntity.ok().body(menuService.getVisibleMenus()));
|
||||
@GetMapping("/menus/available")
|
||||
public Mono<ResponseEntity<Flux<Map<String, Object>>>> getAvailable(
|
||||
@RequestParam Map<String, Object> params,
|
||||
@ParameterObject @PageableDefault(size = Integer.MAX_VALUE) Pageable pageable
|
||||
) {
|
||||
if (!onlyContainsAllowedProperties(pageable)) {
|
||||
return Mono.just(ResponseEntity.badRequest().build());
|
||||
}
|
||||
return SecurityUtils.getCurrentUserLogin()
|
||||
.flatMap(login -> {
|
||||
params.put(
|
||||
"dataScope[filter]",
|
||||
"(select 1 from jhi_relation where jhi_relation.relation_type = 'menu' and jhi_relation.number = jhi_menu.number and IFNULL(data_scope,'') <> '' and exists(select 1 from jhi_relation r where r.role_number = jhi_relation.role_number and relation_type = 'user' and number = '" +
|
||||
login +
|
||||
"'))"
|
||||
);
|
||||
return menuService
|
||||
.countMenus(table, params)
|
||||
.map(total ->
|
||||
ResponseEntity.ok()
|
||||
.header("X-Total-Count", String.valueOf(total))
|
||||
.body(menuService.getTree(table, params, pageable))
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ export default defineComponent({
|
||||
sort: sort(),
|
||||
};
|
||||
|
||||
const response = await axios.get(`api/menus/tree?${buildPaginationQuery(pagination)}`, {
|
||||
const response = await axios.get(`api/menus/available?${buildPaginationQuery(pagination)}`, {
|
||||
params: {
|
||||
number: { name: '' },
|
||||
name: { name: '' },
|
||||
|
||||
Loading…
Reference in New Issue
Block a user