|
@@ -0,0 +1,104 @@
|
|
|
+package com.zswl.cloud.springBtach.server.core.publish;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+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.ypp.kfc.response.CityListResponse;
|
|
|
+import com.zswl.cloud.springBatch.client.model.ypp.kfc.response.ShopsResponse;
|
|
|
+import com.zswl.cloud.springBtach.server.core.api.ypp.KfcApi;
|
|
|
+import com.zswl.cloud.springBtach.server.core.api.ypp.request.KfcShopsRequest;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class KfcPublish implements ProductPublish {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ KfcApi kfcApi;
|
|
|
+
|
|
|
+
|
|
|
+ @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.Kfc
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void trigger(ProductPushService updateService, ProductTriggerTaskModel productTriggerTask) {
|
|
|
+
|
|
|
+
|
|
|
+ CityListResponse cityListResponse = kfcApi.cityList();
|
|
|
+ Map<String, String> collect = cityListResponse.getData().stream().collect(Collectors.toMap(it -> it.getName(), it -> it.getCityId()));
|
|
|
+
|
|
|
+ RegionModel region = productTriggerTask.getRegion();
|
|
|
+ String name = region.getName();
|
|
|
+ String s = collect.get(name);
|
|
|
+ if (ObjectUtil.isEmpty(s)) {
|
|
|
+ throw new RuntimeException("地区信息不匹配");
|
|
|
+ }
|
|
|
+
|
|
|
+ ArrayList<String> strings = new ArrayList<>();
|
|
|
+ strings.add("Kfc");
|
|
|
+ strings.add("MDL");
|
|
|
+ strings.add("XBK");
|
|
|
+ strings.add("NXDC");
|
|
|
+ strings.add("RXKF");
|
|
|
+ strings.add("XC");
|
|
|
+ strings.add("KD");
|
|
|
+
|
|
|
+ for (String string : strings) {
|
|
|
+ KfcShopsRequest kfcShopsRequest = new KfcShopsRequest();
|
|
|
+ kfcShopsRequest.setCityId(s);
|
|
|
+ kfcShopsRequest.setOt(string);
|
|
|
+ ShopsResponse shops = kfcApi.shops(kfcShopsRequest);
|
|
|
+ shops.getData().forEach(it -> {
|
|
|
+ try {
|
|
|
+ LocationModel locationModel = new LocationModel();
|
|
|
+ locationModel.setLongitude(it.getLon());
|
|
|
+ locationModel.setLatitude(it.getLat());
|
|
|
+
|
|
|
+ productCenterStream.send(List.of(
|
|
|
+ ProductPushModel.builder()
|
|
|
+ .regionCode(productTriggerTask.getRegion().getCode())
|
|
|
+ .pid(it.getShopCode())
|
|
|
+ .address(it.getAddress())
|
|
|
+ .productType(ProductType.Kfc)
|
|
|
+ .locationPoint(locationModel)
|
|
|
+ .title(it.getShopName())
|
|
|
+ .meta(Map.of("shop", it, "ot", string))
|
|
|
+ .build()));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|