features: change parse logic

This commit is contained in:
Emelyanov535 2024-10-15 12:13:46 +04:00
parent 42d947440c
commit 1df7dc94b8
2 changed files with 5 additions and 6 deletions

View File

@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="ParsingService [local]" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
<option name="ACTIVE_PROFILES" value="dev,headless,ozon,postgres_stat" />
<option name="ACTIVE_PROFILES" value="dev,headless,postgres_stat" />
<option name="SCHEDULED_DEBUGGER" value="true" />
<envs>
<env name="POSTGRES_JDBC_PASSWORD" value="postgres" />

View File

@ -28,15 +28,12 @@ public class ParsingService {
private final ProductService productService;
public void parse() {
List<ProductEntity> productEntities = new ArrayList<>();
List<PriceHistoryEntity> priceHistories = new ArrayList<>();
final int elementsInPage = 100;
int page = 1;
Integer totalPages = null;
do {
var pageData = client.scrapPage(page, marketplacesConfig.getWildberriesConfigProperties().getShard(), marketplacesConfig.getWildberriesConfigProperties().getLaptopUrl());
System.out.println("Получена страница: " + page);
if (totalPages == null) {
@ -45,6 +42,8 @@ public class ParsingService {
totalPages = (int) Math.ceil((double) totalElements / elementsInPage);
}
List<ProductEntity> productEntities = new ArrayList<>();
List<PriceHistoryEntity> priceHistories = new ArrayList<>();
List<ProductInfoDto> productInfoDtoList = convertMapObjectToListProductInfoDto(pageData);
productInfoDtoList.forEach(dto -> {
@ -62,8 +61,8 @@ public class ParsingService {
});
productService.saveData(productEntities, priceHistories);
page++;
} while (page <= totalPages);
// } while (page <= 5);
// } while (page <= totalPages);
} while (page <= 5);
}
private List<ProductInfoDto> convertMapObjectToListProductInfoDto(Map<String, Object> map) {