| | |
| | | |
| | | @Transactional(readOnly = true) |
| | | public PageResult<Map<String, Object>> stayMerchants(String type, int page, int size) { |
| | | if (!List.of("hotel", "apartment").contains(type)) throw new BusinessException(ErrorCode.BAD_REQUEST, "不支持的住宿服务类型"); |
| | | String requestedType = type == null ? "" : type.trim(); |
| | | String merchantType = switch (requestedType) { |
| | | case "hotel", "酒店服务" -> "酒店服务"; |
| | | case "apartment", "公寓租赁服务" -> "公寓租赁服务"; |
| | | default -> throw new BusinessException(ErrorCode.BAD_REQUEST, "不支持的住宿服务类型"); |
| | | }; |
| | | String responseMerchantType = merchantType.equals("公寓租赁服务") ? "apartment" : "hotel"; |
| | | String merchantWhere = " where deleted = 0 and merchant_type = ?"; |
| | | PageResult<Map<String, Object>> result = page(""" |
| | | select id, merchant_name, merchant_type, contact_name, contact_mobile, logo_url, cover_url, address, |
| | |
| | | (select min(p.original_price) from merchant_product p where p.merchant_id = merchant.id and p.deleted = 0 and p.status = 1 and p.audit_status = 2) as original_price |
| | | from merchant |
| | | """ + merchantWhere + " order by sort_no asc, id asc", |
| | | "select count(*) from merchant" + merchantWhere, page, size, type); |
| | | List<Map<String, Object>> records = result.records().stream().map(this::enrichMerchantSearchRow).toList(); |
| | | "select count(*) from merchant" + merchantWhere, page, size, merchantType); |
| | | List<Map<String, Object>> records = result.records().stream().map(row -> { |
| | | Map<String, Object> normalized = new LinkedHashMap<>(row); |
| | | normalized.put("merchantType", responseMerchantType); |
| | | return enrichMerchantSearchRow(normalized); |
| | | }).toList(); |
| | | return new PageResult<>(records, result.page(), result.size(), result.total()); |
| | | } |
| | | |