1
0

fix(web): Set改List统一接口逻辑

This commit is contained in:
2024-11-28 14:46:24 +08:00
parent 3bda73badf
commit 00e88078a2
8 changed files with 63 additions and 20 deletions

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -1,18 +1,8 @@
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
* @date 2024-11-28
*/
public interface SimpleController<SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> {
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;
public interface SimpleController<SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> extends SaveController<SAVE_ITEM>, ListController<LIST_ITEM>, DetailController<DETAIL_ITEM>, RemoveController {
}

View File

@@ -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.domain.base.entity.SimpleEntity;
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.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@@ -33,7 +33,7 @@ public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_
@GetMapping(LIST)
@Override
public AmisResponse<ImmutableSet<LIST_ITEM>> list() {
public AmisResponse<ImmutableList<LIST_ITEM>> list() {
return AmisResponse.responseSuccess(service.list().collect(entity -> {
try {
return toListItem(entity);

View File

@@ -2,6 +2,7 @@ package com.eshore.gringotts.web.domain.base.service;
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
import java.util.Optional;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.set.ImmutableSet;
/**
@@ -10,11 +11,18 @@ import org.eclipse.collections.api.set.ImmutableSet;
*/
public interface SimpleService<ENTITY extends SimpleEntity> {
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;
ENTITY detail(Long id) throws Exception;
ENTITY detailOrThrow(Long id) throws Exception;
ENTITY detailOrNull(Long id) throws Exception;
void remove(Long id) throws Exception;
}

View File

@@ -13,7 +13,7 @@ import javax.persistence.criteria.Predicate;
import javax.transaction.Transactional;
import lombok.extern.slf4j.Slf4j;
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.set.ImmutableSet;
import org.springframework.data.domain.Sort;
@@ -56,8 +56,8 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
}
@Override
public ImmutableSet<ENTITY> list() {
return Sets.immutable.ofAll(repository.findAll(
public ImmutableList<ENTITY> list() {
return Lists.immutable.ofAll(repository.findAll(
(root, query, builder) -> {
MutableList<Predicate> predicates = Lists.mutable.empty();
User user = userService.currentLoginUser();
@@ -71,8 +71,8 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
}
@Override
public ImmutableSet<ENTITY> list(ImmutableSet<Long> ids) {
return Sets.immutable.ofAll(repository.findAll(
public ImmutableList<ENTITY> list(ImmutableSet<Long> ids) {
return Lists.immutable.ofAll(repository.findAll(
(root, query, builder) -> {
MutableList<Predicate> predicates = Lists.mutable.of(
builder.in(root.get("id")).value(ids.select(ObjectUtil::isNotNull))