|
|
@@ -1,60 +1,64 @@
|
|
|
package com.ruoyi.api.service.impl;
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-import com.ruoyi.api.constant.yz.ApiConstant;
|
|
|
+import com.ruoyi.api.constant.yz.ApiEnum;
|
|
|
import com.ruoyi.api.downstream.YzResult;
|
|
|
import com.ruoyi.api.fake.PushProductFake;
|
|
|
+import com.ruoyi.api.pojo.bo.ProductByIdsBO;
|
|
|
import com.ruoyi.api.pojo.bo.ProductsBO;
|
|
|
import com.ruoyi.api.pojo.bo.ProductsSkusBO;
|
|
|
import com.ruoyi.api.service.IProductService;
|
|
|
-import com.ruoyi.api.utils.HttpUtils;
|
|
|
-import org.apache.poi.ss.formula.functions.T;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
+import com.ruoyi.api.utils.YzResultProcessingUtil;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
@Service
|
|
|
public class ProductServiceImpl implements IProductService {
|
|
|
- @Value("${downstream.url}")
|
|
|
- private String url;
|
|
|
-
|
|
|
- private final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
|
@Override
|
|
|
public YzResult pushProduct() throws JsonProcessingException {
|
|
|
- String realUrl = url + ApiConstant.PUSH_PRODUCT;
|
|
|
-
|
|
|
// TODO:没有第三方供应链,伪造测试数据
|
|
|
ProductsBO productsBO = PushProductFake.pushProduct();
|
|
|
- return getYzResult(realUrl, productsBO);
|
|
|
+ return YzResultProcessingUtil.getYzResult(ApiEnum.PUSH_PRODUCT, productsBO);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public YzResult updateCloudProduct() throws JsonProcessingException {
|
|
|
- String realUrl = url + ApiConstant.UPDATE_CLOUD_PRODUCT;
|
|
|
-
|
|
|
// TODO:没有第三方供应链,伪造测试数据
|
|
|
ProductsBO productsBO = PushProductFake.updateCloudProduct();
|
|
|
- return getYzResult(realUrl, productsBO);
|
|
|
+ return YzResultProcessingUtil.getYzResult(ApiEnum.UPDATE_CLOUD_PRODUCT, productsBO);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public YzResult updateCloudSku() throws JsonProcessingException {
|
|
|
- String realUrl = url + ApiConstant.UPDATE_CLOUD_SKU;
|
|
|
-
|
|
|
// TODO:没有第三方供应链,伪造测试数据
|
|
|
ProductsSkusBO productsSkusBO = PushProductFake.updateCloudSku();
|
|
|
- return getYzResult(realUrl, productsSkusBO);
|
|
|
+ return YzResultProcessingUtil.getYzResult(ApiEnum.UPDATE_CLOUD_SKU, productsSkusBO);
|
|
|
}
|
|
|
|
|
|
- private YzResult getYzResult(String realUrl, Object bo) throws JsonProcessingException {
|
|
|
- objectMapper.setPropertyNamingStrategy(com.fasterxml.jackson.databind.PropertyNamingStrategy.SNAKE_CASE);
|
|
|
+ @Override
|
|
|
+ public YzResult displayProductByIds() throws JsonProcessingException {
|
|
|
+ // TODO:没有第三方供应链,伪造测试数据
|
|
|
+ ProductByIdsBO productByIdsBO = PushProductFake.displayProductByIds();
|
|
|
+ return YzResultProcessingUtil.getYzResult(ApiEnum.DISPLAY_PRODUCT_BY_IDS, productByIdsBO);
|
|
|
+ }
|
|
|
|
|
|
- String data = objectMapper.writeValueAsString(bo);
|
|
|
- System.out.println("data: " + data);
|
|
|
+ @Override
|
|
|
+ public YzResult findProduct() throws JsonProcessingException {
|
|
|
+ // TODO:没有第三方供应链,伪造测试数据
|
|
|
+ Map<String, Integer> map = new HashMap<>();
|
|
|
+ map.put("id", 398);
|
|
|
+ return YzResultProcessingUtil.getYzResult(ApiEnum.FIND_PRODUCT, map);
|
|
|
+ }
|
|
|
|
|
|
- ResponseEntity<String> responseEntity = HttpUtils.sendPostWithHeaders(realUrl, data);
|
|
|
- return objectMapper.readValue(responseEntity.getBody(), YzResult.class);
|
|
|
+ @Override
|
|
|
+ public YzResult deleteProduct() throws JsonProcessingException {
|
|
|
+ // TODO:没有第三方供应链,伪造测试数据
|
|
|
+ Map<String, Integer> map = new HashMap<>();
|
|
|
+ map.put("id", 398);
|
|
|
+ return YzResultProcessingUtil.getYzResult(ApiEnum.DELETE_PRODUCT, map);
|
|
|
}
|
|
|
+
|
|
|
}
|