|
|
@@ -4,10 +4,12 @@ import com.uas.platform.b2c.advertise.ad.model.Message;
|
|
|
import com.uas.platform.b2c.advertise.ad.model.RecommendProduct;
|
|
|
import com.uas.platform.b2c.advertise.ad.service.RecommendProductService;
|
|
|
import com.uas.platform.b2c.advertise.ad.utils.RecommendProductsUtils;
|
|
|
+import com.uas.platform.b2c.core.config.MicroServicesConfMulti;
|
|
|
import com.uas.platform.b2c.core.utils.JacksonUtils;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.GoodsDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.Goods;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.kafka.core.KafkaTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
@@ -30,17 +32,23 @@ import java.util.Set;
|
|
|
@Service
|
|
|
public class RecommendProductServiceImpl implements RecommendProductService {
|
|
|
|
|
|
+ @Value("#{sys.profile}")
|
|
|
+ private String profile;
|
|
|
+
|
|
|
private final RestTemplate restTemplate;
|
|
|
|
|
|
private final GoodsDao goodsDao;
|
|
|
|
|
|
private final KafkaTemplate<String, String> kafkaTemplate;
|
|
|
|
|
|
+ private final MicroServicesConfMulti conf;
|
|
|
+
|
|
|
@Autowired
|
|
|
- public RecommendProductServiceImpl(RestTemplate restTemplate, GoodsDao goodsDao, KafkaTemplate<String, String> kafkaTemplate) {
|
|
|
+ public RecommendProductServiceImpl(RestTemplate restTemplate, GoodsDao goodsDao, KafkaTemplate<String, String> kafkaTemplate, MicroServicesConfMulti conf) {
|
|
|
this.restTemplate = restTemplate;
|
|
|
this.goodsDao = goodsDao;
|
|
|
this.kafkaTemplate = kafkaTemplate;
|
|
|
+ this.conf = conf;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -49,6 +57,10 @@ public class RecommendProductServiceImpl implements RecommendProductService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ if (StringUtils.isEmpty(profile)) {
|
|
|
+ throw new IllegalStateException("无法获取配置文件属性值");
|
|
|
+ }
|
|
|
+
|
|
|
Date date = new Date();
|
|
|
|
|
|
Message message = new Message();
|
|
|
@@ -58,14 +70,17 @@ public class RecommendProductServiceImpl implements RecommendProductService {
|
|
|
message.setBatchCodes(batchCodes);
|
|
|
System.out.println(JacksonUtils.toJson(message));
|
|
|
|
|
|
- kafkaTemplate.send("recommend-products-delete", "batchCode", JacksonUtils.toJson(message));
|
|
|
+ String topic = "recommend-products-delete" + "-" + profile;
|
|
|
+
|
|
|
+ kafkaTemplate.send(topic, "batchCode", JacksonUtils.toJson(message));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<RecommendProduct> findProductsWhenUserVisitStore(String uuid) {
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
map.put("uuid", uuid);
|
|
|
- String content = restTemplate.getForObject("http://api.ubtob.com/api/recommend/products?condition=store_uuid&uuid={uuid}", String.class, map);
|
|
|
+ String url = conf.getRequestUrl(20100, "/api/recommend/products?condition=store_uuid&uuid={uuid}");
|
|
|
+ String content = restTemplate.getForObject(url, String.class, map);
|
|
|
if (StringUtils.isEmpty(content)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
@@ -80,4 +95,34 @@ public class RecommendProductServiceImpl implements RecommendProductService {
|
|
|
}
|
|
|
return recommendProducts;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<RecommendProduct> saveProductsWhenSellerUpdate(String uuid, List<RecommendProduct> productList) {
|
|
|
+ if (StringUtils.isEmpty(uuid)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(productList)) {
|
|
|
+ productList = Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ String url = conf.getRequestUrl(20100, "/api/recommend/products?uuid=" + uuid);
|
|
|
+
|
|
|
+ String content;
|
|
|
+ try {
|
|
|
+ content = restTemplate.postForObject(url, productList, String.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ content = "[]";
|
|
|
+ }
|
|
|
+
|
|
|
+ List<RecommendProduct> recommendProducts = JacksonUtils.fromJsonArray(content, RecommendProduct.class);
|
|
|
+
|
|
|
+ for (RecommendProduct product : recommendProducts) {
|
|
|
+ Goods commodity = goodsDao.findByBatchCode(product.getBatchCode());
|
|
|
+ if (commodity != null) {
|
|
|
+ RecommendProductsUtils.fillCommodityInfo(product, commodity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return recommendProducts;
|
|
|
+ }
|
|
|
}
|