优化
This commit is contained in:
@@ -13,6 +13,7 @@ import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
@Repository
|
||||
public class PartnerRepository {
|
||||
@@ -43,6 +44,26 @@ public class PartnerRepository {
|
||||
}
|
||||
|
||||
public PageResult<PartnerEntity> page(Long tenantId, PartnerPageQuery request) {
|
||||
if (request.types() != null && !request.types().isEmpty()) {
|
||||
List<Long> typedIds = new LinkedHashSet<String>(request.types()).stream()
|
||||
.flatMap(type -> typedIds(tenantId == null ? 0L : tenantId, type).stream())
|
||||
.distinct().toList();
|
||||
if (typedIds.isEmpty()) return PageResult.from(new Page<PartnerEntity>(request.page(), request.size()));
|
||||
LambdaQueryWrapper<PartnerEntity> wrapper = new LambdaQueryWrapper<PartnerEntity>()
|
||||
.eq(tenantId != null, PartnerEntity::getTenantId, tenantId)
|
||||
.in(PartnerEntity::getId, typedIds)
|
||||
.eq(StringUtils.hasText(request.status()), PartnerEntity::getStatus, request.status())
|
||||
.and(StringUtils.hasText(request.keyword()), query -> query
|
||||
.like(PartnerEntity::getPartnerCode, request.keyword())
|
||||
.or().like(PartnerEntity::getPartnerName, request.keyword())
|
||||
.or().like(PartnerEntity::getContactName, request.keyword())
|
||||
.or().like(PartnerEntity::getContactPhone, request.keyword()))
|
||||
.orderByAsc(PartnerEntity::getPartnerName).orderByAsc(PartnerEntity::getId);
|
||||
PageResult<PartnerEntity> result = PageResult.from(mapper.selectPage(
|
||||
new Page<>(request.page(), request.size()), wrapper));
|
||||
hydrateTypes(result.records());
|
||||
return result;
|
||||
}
|
||||
if (StringUtils.hasText(request.type())) {
|
||||
Page<PartnerEntity> page = mapper.selectPartnerPageByType(
|
||||
new Page<>(request.page(), request.size()), tenantId, request.type(),
|
||||
|
||||
@@ -16,19 +16,37 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Locale;
|
||||
|
||||
/** 平台往来单位管理服务。 */
|
||||
@Service
|
||||
public class PlatformPartnerQueryService {
|
||||
private static final long PUBLIC_TENANT_ID = 0L;
|
||||
private static final Set<String> ALLOWED_QUERY_TYPES = Set.of(
|
||||
"CUSTOMER", "SUPPLIER", "CARRIER", "CUSTOMS_BROKER", "SHIPPER", "CONSIGNEE", "BOTH");
|
||||
@Resource
|
||||
private PartnerRepository repository;
|
||||
|
||||
public PageResult<PartnerEntity> page(Long tenantId, PartnerPageQuery query) {
|
||||
requirePublicScope(tenantId);
|
||||
validateQueryTypes(query);
|
||||
return repository.page(PUBLIC_TENANT_ID, query);
|
||||
}
|
||||
|
||||
private static void validateQueryTypes(PartnerPageQuery query) {
|
||||
if (query == null) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED, "查询条件不能为空");
|
||||
}
|
||||
if (query.type() != null && !query.type().isBlank()
|
||||
&& !ALLOWED_QUERY_TYPES.contains(query.type().toUpperCase(Locale.ROOT))) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED, "往来单位类型无效");
|
||||
}
|
||||
if (query.types() != null && query.types().stream().anyMatch(type ->
|
||||
type == null || !ALLOWED_QUERY_TYPES.contains(type.toUpperCase(Locale.ROOT)))) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED, "往来单位类型无效");
|
||||
}
|
||||
}
|
||||
|
||||
public PartnerEntity detail(long tenantId, long id) {
|
||||
requirePublicScope(tenantId);
|
||||
return owned(PUBLIC_TENANT_ID, id);
|
||||
|
||||
Reference in New Issue
Block a user