|
@@ -0,0 +1,124 @@
|
|
|
|
+package com.zswl.cloud.springBtach.server.core.publish;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
|
+import com.github.microservice.productcenter.client.model.LocationModel;
|
|
|
|
+import com.github.microservice.productcenter.client.model.ProductPushModel;
|
|
|
|
+import com.github.microservice.productcenter.client.model.ProductTriggerTaskModel;
|
|
|
|
+import com.github.microservice.productcenter.client.model.RegionModel;
|
|
|
|
+import com.github.microservice.productcenter.client.publish.ProductPublish;
|
|
|
|
+import com.github.microservice.productcenter.client.service.ProductPushService;
|
|
|
|
+import com.github.microservice.productcenter.client.stream.ProductCenterStream;
|
|
|
|
+import com.github.microservice.productcenter.client.type.ProductType;
|
|
|
|
+import com.github.microservice.productcenter.client.type.RegionType;
|
|
|
|
+import com.zswl.cloud.springBatch.client.model.dfy.Hotel.request.HotelListRequest;
|
|
|
|
+import com.zswl.cloud.springBatch.client.model.dfy.Hotel.request.QueryNewRequest;
|
|
|
|
+import com.zswl.cloud.springBatch.client.model.dfy.Hotel.response.HotelListResponse;
|
|
|
|
+import com.zswl.cloud.springBatch.client.model.dfy.Hotel.response.QueryNewResponse;
|
|
|
|
+import com.zswl.cloud.springBatch.client.model.dfy.Ticket.request.ScenicListRequest;
|
|
|
|
+import com.zswl.cloud.springBatch.client.model.dfy.Ticket.response.ScenicListResponse;
|
|
|
|
+import com.zswl.cloud.springBtach.server.core.api.dfy.DomesticHotelApi;
|
|
|
|
+import com.zswl.cloud.springBtach.server.core.api.dfy.TicketApi;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+@Slf4j
|
|
|
|
+@Component
|
|
|
|
+public class HotelPublish implements ProductPublish {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ TicketApi ticketApi;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ DomesticHotelApi domesticHotelApi;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ProductCenterStream productCenterStream;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String regionCode() {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Collection<RegionType> regionType() {
|
|
|
|
+ return Set.of(RegionType.City);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Collection<ProductType> productTypes() {
|
|
|
|
+ return Set.of(
|
|
|
|
+ ProductType.Hotel
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void trigger(ProductPushService updateService, ProductTriggerTaskModel productTriggerTask) {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ RegionModel region = productTriggerTask.getRegion();
|
|
|
|
+ String name = region.getName();
|
|
|
|
+ QueryNewRequest queryNewRequest = new QueryNewRequest();
|
|
|
|
+ queryNewRequest.setKeywords(name);
|
|
|
|
+ QueryNewResponse queryNewResponse = domesticHotelApi.queryNew(queryNewRequest);
|
|
|
|
+ QueryNewResponse.Datas data = queryNewResponse.getData();
|
|
|
|
+ List<QueryNewResponse.Dest> destinationSuggests = data.getDestinationSuggests();
|
|
|
|
+ for (QueryNewResponse.Dest dest : destinationSuggests.stream().filter(it -> !it.getPoiType().equals(Integer.valueOf(7))).collect(Collectors.toList())) {
|
|
|
|
+ int start = 0;
|
|
|
|
+ int limit = 30;
|
|
|
|
+
|
|
|
|
+ while (true) {
|
|
|
|
+ HotelListRequest hotelListRequest = new HotelListRequest();
|
|
|
|
+ hotelListRequest.setStart(start);
|
|
|
|
+ hotelListRequest.setLimit(limit);
|
|
|
|
+ hotelListRequest.setCityName(dest.getCityName());
|
|
|
|
+ hotelListRequest.setCityCode(dest.getCityCode());
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ String inDate = DateUtil.format(date, "yyyy-MM-dd");
|
|
|
|
+ DateTime dateTime = DateUtil.offsetDay(date, 1);
|
|
|
|
+ long time = dateTime.getTime();
|
|
|
|
+ String oute = DateUtil.format(new Date(time), "yyyy-MM-dd");
|
|
|
|
+ hotelListRequest.setCheckInDate(inDate);
|
|
|
|
+ hotelListRequest.setCheckOutDate(oute);
|
|
|
|
+ HotelListRequest.FilterInfo filterInfo = new HotelListRequest.FilterInfo();
|
|
|
|
+ hotelListRequest.setFilter(filterInfo);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ HotelListResponse hotelListResponse = domesticHotelApi.hotelList(hotelListRequest);
|
|
|
|
+ if (!hotelListResponse.getSuccess()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ HotelListResponse.Datas data1 = hotelListResponse.getData();
|
|
|
|
+ if (data1.getHotelList().isEmpty()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ data1.getHotelList().forEach(it -> {
|
|
|
|
+ String hotelId = it.getHotelId();
|
|
|
|
+ String chineseName = it.getChineseName();
|
|
|
|
+ String picture = it.getPicture();
|
|
|
|
+ BigDecimal price = it.getPrice();
|
|
|
|
+ productCenterStream.send(List.of(ProductPushModel.builder()
|
|
|
|
+ .regionCode(productTriggerTask.getRegion().getCode())
|
|
|
|
+ .pid(hotelId)
|
|
|
|
+ .productType(ProductType.Hotel)
|
|
|
|
+ .cover(new String[]{picture})
|
|
|
|
+ .salePrice(price.longValue())
|
|
|
|
+ .title(chineseName)
|
|
|
|
+ .meta(Map.of("hotel", it))
|
|
|
|
+// .expireTimeSecond(60 * 60 * 24)
|
|
|
|
+ .build()));
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ start += limit;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|