Feature/parsing-service: fix after pull

This commit is contained in:
danil.markov 2024-10-15 11:34:24 +04:00
parent 83b1c5d72c
commit 42d947440c
13 changed files with 29 additions and 22 deletions

View File

@ -1,4 +1,4 @@
package ru.pricepulse.parsingservice.wildberries_parser.configuration;
package ru.pricepulse.parsingservice.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpRequest;

View File

@ -1,4 +1,4 @@
package ru.pricepulse.parsingservice.wildberries_parser.configuration;
package ru.pricepulse.parsingservice.config;
import org.springframework.stereotype.Component;

View File

@ -1,4 +1,4 @@
package ru.pricepulse.parsingservice.wildberries_parser.configuration;
package ru.pricepulse.parsingservice.config;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Bean;
@ -6,8 +6,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.web.client.RestTemplate;
import java.util.Collections;
@Configuration
@AllArgsConstructor
public class RestTemplateConfig {
@ -21,7 +19,7 @@ public class RestTemplateConfig {
ClientHttpRequestInterceptor dynamicProxyInterceptor = new DynamicProxyInterceptor(userAgentProvider, proxyProvider);
// Добавляем интерсептор в RestTemplate
restTemplate.setInterceptors(Collections.singletonList(dynamicProxyInterceptor));
//restTemplate.setInterceptors(Collections.singletonList(dynamicProxyInterceptor));
return restTemplate;
}

View File

@ -1,12 +1,20 @@
package ru.pricepulse.parsingservice.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
@Configuration
@EnableScheduling
public class SchedulerConfig {
@Bean
public ThreadPoolTaskScheduler taskScheduler() {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(10);
taskScheduler.setThreadNamePrefix("ScheduledTask-");
return taskScheduler;
}
}

View File

@ -1,4 +1,4 @@
package ru.pricepulse.parsingservice.wildberries_parser.configuration;
package ru.pricepulse.parsingservice.config;
import org.springframework.stereotype.Component;

View File

@ -1,4 +1,4 @@
package ru.pricepulse.parsingservice.wildberries_parser.configuration;
package ru.pricepulse.parsingservice.config;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -17,7 +17,7 @@ import java.net.InetSocketAddress;
@AllArgsConstructor
public class WebClientConfig {
private final UserAgentProvider userAgentProvider;
private final ru.pricepulse.parsingservice.wildberries_parser.configuration.ProxyProvider proxyProvider;
private final ru.pricepulse.parsingservice.config.ProxyProvider proxyProvider;
@Bean

View File

@ -45,9 +45,6 @@ public class ProductEntity {
@Column(name = "image-url", nullable = false)
private String imageUrl;
@Column(name = "article", nullable = false)
private String article;
@Override
public final boolean equals(Object o) {
if (this == o) return true;

View File

@ -21,7 +21,6 @@ public class ProductInfoDto2ProductEntity implements Converter<ProductInfoDto, P
.productName(source.getName())
.createdAt(LocalDateTime.now())
.imageUrl("")
.article(source.getId().toString())
.build();
}
}

View File

@ -12,6 +12,7 @@ import ru.pricepulse.parsingservice.wildberries_parser.service.ParsingService;
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "marketplace.wildberries", name = "status", havingValue = "true")
public class WildberriesProductUpdater {
private final ParsingService parsingService;
@Scheduled(fixedRate = 3600000)

View File

@ -20,7 +20,7 @@ import java.util.Map;
@Service("wildberriesParsingService")
@AllArgsConstructor
public class WildberriesParsingService {
public class ParsingService {
private final Client client;
private final ObjectMapper objectMapper;
private final ConversionService conversionService;
@ -36,6 +36,7 @@ public class WildberriesParsingService {
Integer totalPages = null;
do {
var pageData = client.scrapPage(page, marketplacesConfig.getWildberriesConfigProperties().getShard(), marketplacesConfig.getWildberriesConfigProperties().getLaptopUrl());
System.out.println("Получена страница: " + page);
if (totalPages == null) {
@ -59,12 +60,10 @@ public class WildberriesParsingService {
productEntities.add(productEntity);
priceHistories.add(priceHistory);
});
productService.saveData(productEntities, priceHistories);
page++;
} while (page <= totalPages);
// } while (page <= 5);
productService.saveData(productEntities, priceHistories);
}
private List<ProductInfoDto> convertMapObjectToListProductInfoDto(Map<String, Object> map) {

View File

@ -12,7 +12,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
@Service("wildberriesProductService")
@AllArgsConstructor
public class ProductService {
private final ProductRepository productRepository;
@ -45,8 +45,8 @@ public class ProductService {
// Фильтруем и обновляем идентификаторы для истории цен
List<PriceHistoryEntity> updatedPriceHistories = priceHistoryEntities.stream()
.peek(priceHistory -> {
ProductEntity product = productMap.get(priceHistory.getId().getProduct().getUrl());
priceHistory.getId().setProduct(product);
ProductEntity product = productMap.get(priceHistory.getId().getProductUrl());
priceHistory.getId().setProductUrl(product.getUrl());
})
.collect(Collectors.toList());

View File

@ -30,6 +30,12 @@ public class ClientImpl implements Client {
shard +
query +
"?dest=-1257786&page=" + page + "&subject=2290";
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
return restTemplate.exchange(
url,

View File

@ -22,7 +22,6 @@ spring:
marketplace:
ozon:
status: false
categories-urls:
- https://www.ozon.ru/category/noutbuki-15692/?brandcertified=t
wildberries: