| | |
| | | merchant.logo_url, merchant.cover_url, merchant.address, merchant.business_status, merchant.longitude, |
| | | merchant.latitude, merchant.can_login_merchant_app, merchant.group_buying_enabled, merchant.usage_instructions, |
| | | merchant.rights_text, merchant.merchant_rights_config, merchant.service_label, merchant.is_recommend, |
| | | merchant.sort_no, merchant.status, merchant.created_at, merchant.updated_at, |
| | | merchant.sort_no, merchant.status, merchant.created_at, merchant.updated_at, merchant.merchant_type_code, |
| | | s.external_link_type as car_wash_external_link_type, |
| | | s.external_mini_program_app_id as car_wash_external_mini_program_app_id, |
| | | s.external_mini_program_path as car_wash_external_mini_program_path, |
| | |
| | | where merchant_id = ? |
| | | order by sort_no, id |
| | | """, id))); |
| | | if ("fuel".equals(String.valueOf(result.get("merchantTypeCode")))) { |
| | | result.put("applicableStores", DatabaseRows.normalize(jdbcTemplate.queryForList(""" |
| | | select id, store_name, address, longitude, latitude |
| | | from transport_fuel_store |
| | | where merchant_id = ? and deleted = 0 and enabled = 1 |
| | | order by sort_no asc, id asc |
| | | """, id))); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | |
| | | Long id = jdbcTemplate.queryForObject("select last_insert_id()", Long.class); |
| | | ensureParkingBenefit(id, merchantType.code()); |
| | | ensureFuelBenefit(id, merchantType.code(), request.serviceLabel()); |
| | | syncFuelStores(id, merchantType.code(), request.applicableStores()); |
| | | syncPremiumTopicMerchant(id, merchantType, request.sortNo()); |
| | | Long storeId = createDefaultStore(id, request.merchantName(), request.address()); |
| | | syncMerchantBusinessHours(id, storeId, request.businessHours()); |
| | |
| | | ensureUpdated(updated); |
| | | ensureParkingBenefit(id, merchantType.code()); |
| | | ensureFuelBenefit(id, merchantType.code(), request.serviceLabel()); |
| | | syncFuelStores(id, merchantType.code(), request.applicableStores()); |
| | | syncPremiumTopicMerchant(id, merchantType, request.sortNo()); |
| | | Long storeId = findOrCreateDefaultStore(id, request.merchantName(), request.address()); |
| | | syncMerchantBusinessHours(id, storeId, request.businessHours()); |
| | |
| | | """, merchantId, discountText, merchantId); |
| | | } |
| | | |
| | | private void syncFuelStores(Long merchantId, String merchantType, List<Map<String, Object>> stores) { |
| | | if (!"fuel".equals(merchantType) || stores == null) return; |
| | | List<Map<String, Object>> normalized = new ArrayList<>(); |
| | | Set<String> names = new HashSet<>(); |
| | | for (Map<String, Object> store : stores) { |
| | | if (store == null) continue; |
| | | Object nameValue = store.containsKey("storeName") ? store.get("storeName") : store.get("name"); |
| | | String name = nameValue == null ? "" : String.valueOf(nameValue).trim(); |
| | | Object addressValue = store.get("address"); |
| | | String address = addressValue == null ? "" : String.valueOf(addressValue).trim(); |
| | | if (name.isBlank() || address.isBlank()) throw new BusinessException(ErrorCode.BAD_REQUEST, "请完善适用门店名称和地址"); |
| | | if (!names.add(name)) throw new BusinessException(ErrorCode.BAD_REQUEST, "适用门店名称不能重复"); |
| | | Double longitude = numberValue(store.get("longitude")); |
| | | Double latitude = numberValue(store.get("latitude")); |
| | | if (longitude == null || longitude < -180 || longitude > 180 || latitude == null || latitude < -90 || latitude > 90 |
| | | || (longitude == 0 && latitude == 0)) { |
| | | throw new BusinessException(ErrorCode.BAD_REQUEST, "请完成所有适用门店的标点"); |
| | | } |
| | | Map<String, Object> item = new LinkedHashMap<>(); |
| | | item.put("name", name); |
| | | item.put("address", address); |
| | | item.put("longitude", longitude); |
| | | item.put("latitude", latitude); |
| | | normalized.add(item); |
| | | } |
| | | jdbcTemplate.update("delete from transport_fuel_store where merchant_id = ?", merchantId); |
| | | for (int index = 0; index < normalized.size(); index++) { |
| | | Map<String, Object> store = normalized.get(index); |
| | | jdbcTemplate.update(""" |
| | | insert into transport_fuel_store(merchant_id, store_name, address, longitude, latitude, sort_no, enabled, deleted) |
| | | values (?, ?, ?, ?, ?, ?, 1, 0) |
| | | """, merchantId, store.get("name"), store.get("address"), store.get("longitude"), store.get("latitude"), (index + 1) * 10); |
| | | } |
| | | } |
| | | |
| | | private Double numberValue(Object value) { |
| | | if (value instanceof Number number) return number.doubleValue(); |
| | | try { return value == null ? null : Double.valueOf(String.valueOf(value)); } |
| | | catch (NumberFormatException ignored) { return null; } |
| | | } |
| | | |
| | | private void syncPremiumTopicMerchant(Long merchantId, MerchantType merchantType, Integer sortNo) { |
| | | if (merchantType.premiumCategoryKey() == null || merchantType.premiumBusinessType() == null) { |
| | | jdbcTemplate.update("update premium_topic_merchant set deleted = 1 where merchant_id = ? and deleted = 0", merchantId); |