소스 검색

添加kfc

gongfuzhu 9 달 전
부모
커밋
e1d212e63d

+ 0 - 2
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/core/api/ypp/TokenApi.java

@@ -29,8 +29,6 @@ public class TokenApi {
     @Value("${ypp.appId}")
     private String appId;
 
-    @Value("${ypp.test}")
-    private Boolean test;
 
     @Autowired
     RedisHelper redisHelper;

+ 104 - 0
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/core/publish/KfcPublish.java

@@ -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();
+                }
+
+            });
+        }
+    }
+}

+ 1 - 1
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/core/service/impl/KfcServiceImpl.java

@@ -121,7 +121,7 @@ public class KfcServiceImpl {
 
         CreateOrder2Model.Goods goods = new CreateOrder2Model.Goods();
         goods.setGoodsId(kfcGoodsDetailRequest.getProducts().get(0).getProductId());
-        goods.setJobFlowMap(JobFlowMap.YPP);
+        goods.setJobFlowMap(JobFlowMap.Kfc);
         goods.setGoodsInfo(goodsInfo);
         goods.setPayAmount(bigDecimal);
         goods.setValidDay(90);