fix(web): Set改List统一接口逻辑
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
package com.eshore.gringotts.web.domain.base.controller;
|
||||||
|
|
||||||
|
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @date 2024-11-28
|
||||||
|
*/
|
||||||
|
public interface DetailController<DETAIL_ITEM> {
|
||||||
|
AmisResponse<DETAIL_ITEM> detail(Long id) throws Exception;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.eshore.gringotts.web.domain.base.controller;
|
||||||
|
|
||||||
|
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||||
|
import org.eclipse.collections.api.list.ImmutableList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @date 2024-11-28
|
||||||
|
*/
|
||||||
|
public interface ListController<LIST_ITEM> {
|
||||||
|
AmisResponse<ImmutableList<LIST_ITEM>> list() throws Exception;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.eshore.gringotts.web.domain.base.controller;
|
||||||
|
|
||||||
|
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @date 2024-11-28
|
||||||
|
*/
|
||||||
|
public interface RemoveController {
|
||||||
|
AmisResponse<Object> remove(Long id) throws Exception;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.eshore.gringotts.web.domain.base.controller;
|
||||||
|
|
||||||
|
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @date 2024-11-28
|
||||||
|
*/
|
||||||
|
public interface SaveController<SAVE_ITEM> {
|
||||||
|
AmisResponse<Long> save(SAVE_ITEM item) throws Exception;
|
||||||
|
}
|
||||||
@@ -1,18 +1,8 @@
|
|||||||
package com.eshore.gringotts.web.domain.base.controller;
|
package com.eshore.gringotts.web.domain.base.controller;
|
||||||
|
|
||||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
|
||||||
import org.eclipse.collections.api.set.ImmutableSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lanyuanxiaoyao
|
* @author lanyuanxiaoyao
|
||||||
* @date 2024-11-28
|
* @date 2024-11-28
|
||||||
*/
|
*/
|
||||||
public interface SimpleController<SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> {
|
public interface SimpleController<SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> extends SaveController<SAVE_ITEM>, ListController<LIST_ITEM>, DetailController<DETAIL_ITEM>, RemoveController {
|
||||||
AmisResponse<Long> save(SAVE_ITEM item) throws Exception;
|
|
||||||
|
|
||||||
AmisResponse<ImmutableSet<LIST_ITEM>> list() throws Exception;
|
|
||||||
|
|
||||||
AmisResponse<DETAIL_ITEM> detail(Long id) throws Exception;
|
|
||||||
|
|
||||||
AmisResponse<Object> remove(Long id) throws Exception;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.eshore.gringotts.web.domain.base.controller;
|
|||||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||||
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
|
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
|
||||||
import org.eclipse.collections.api.set.ImmutableSet;
|
import org.eclipse.collections.api.list.ImmutableList;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
@@ -33,7 +33,7 @@ public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_
|
|||||||
|
|
||||||
@GetMapping(LIST)
|
@GetMapping(LIST)
|
||||||
@Override
|
@Override
|
||||||
public AmisResponse<ImmutableSet<LIST_ITEM>> list() {
|
public AmisResponse<ImmutableList<LIST_ITEM>> list() {
|
||||||
return AmisResponse.responseSuccess(service.list().collect(entity -> {
|
return AmisResponse.responseSuccess(service.list().collect(entity -> {
|
||||||
try {
|
try {
|
||||||
return toListItem(entity);
|
return toListItem(entity);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.eshore.gringotts.web.domain.base.service;
|
|||||||
|
|
||||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import org.eclipse.collections.api.list.ImmutableList;
|
||||||
import org.eclipse.collections.api.set.ImmutableSet;
|
import org.eclipse.collections.api.set.ImmutableSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,11 +11,18 @@ import org.eclipse.collections.api.set.ImmutableSet;
|
|||||||
*/
|
*/
|
||||||
public interface SimpleService<ENTITY extends SimpleEntity> {
|
public interface SimpleService<ENTITY extends SimpleEntity> {
|
||||||
Long save(ENTITY entity) throws Exception;
|
Long save(ENTITY entity) throws Exception;
|
||||||
ImmutableSet<ENTITY> list() throws Exception;
|
|
||||||
ImmutableSet<ENTITY> list(ImmutableSet<Long> ids) throws Exception;
|
ImmutableList<ENTITY> list() throws Exception;
|
||||||
|
|
||||||
|
ImmutableList<ENTITY> list(ImmutableSet<Long> ids) throws Exception;
|
||||||
|
|
||||||
Optional<ENTITY> detailOptional(Long id) throws Exception;
|
Optional<ENTITY> detailOptional(Long id) throws Exception;
|
||||||
|
|
||||||
ENTITY detail(Long id) throws Exception;
|
ENTITY detail(Long id) throws Exception;
|
||||||
|
|
||||||
ENTITY detailOrThrow(Long id) throws Exception;
|
ENTITY detailOrThrow(Long id) throws Exception;
|
||||||
|
|
||||||
ENTITY detailOrNull(Long id) throws Exception;
|
ENTITY detailOrNull(Long id) throws Exception;
|
||||||
|
|
||||||
void remove(Long id) throws Exception;
|
void remove(Long id) throws Exception;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import javax.persistence.criteria.Predicate;
|
|||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.eclipse.collections.api.factory.Lists;
|
import org.eclipse.collections.api.factory.Lists;
|
||||||
import org.eclipse.collections.api.factory.Sets;
|
import org.eclipse.collections.api.list.ImmutableList;
|
||||||
import org.eclipse.collections.api.list.MutableList;
|
import org.eclipse.collections.api.list.MutableList;
|
||||||
import org.eclipse.collections.api.set.ImmutableSet;
|
import org.eclipse.collections.api.set.ImmutableSet;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
@@ -56,8 +56,8 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImmutableSet<ENTITY> list() {
|
public ImmutableList<ENTITY> list() {
|
||||||
return Sets.immutable.ofAll(repository.findAll(
|
return Lists.immutable.ofAll(repository.findAll(
|
||||||
(root, query, builder) -> {
|
(root, query, builder) -> {
|
||||||
MutableList<Predicate> predicates = Lists.mutable.empty();
|
MutableList<Predicate> predicates = Lists.mutable.empty();
|
||||||
User user = userService.currentLoginUser();
|
User user = userService.currentLoginUser();
|
||||||
@@ -71,8 +71,8 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImmutableSet<ENTITY> list(ImmutableSet<Long> ids) {
|
public ImmutableList<ENTITY> list(ImmutableSet<Long> ids) {
|
||||||
return Sets.immutable.ofAll(repository.findAll(
|
return Lists.immutable.ofAll(repository.findAll(
|
||||||
(root, query, builder) -> {
|
(root, query, builder) -> {
|
||||||
MutableList<Predicate> predicates = Lists.mutable.of(
|
MutableList<Predicate> predicates = Lists.mutable.of(
|
||||||
builder.in(root.get("id")).value(ids.select(ObjectUtil::isNotNull))
|
builder.in(root.get("id")).value(ids.select(ObjectUtil::isNotNull))
|
||||||
|
|||||||
Reference in New Issue
Block a user