|
@@ -137,19 +137,30 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
public List<Product> getProductListBydeviceId(String deviceId) {
|
|
public List<Product> getProductListBydeviceId(String deviceId) {
|
|
|
try {
|
|
try {
|
|
|
Map<String, Object> result = hahaClient.getGoodsApi().getDeviceGoodsList(deviceId, null);
|
|
Map<String, Object> result = hahaClient.getGoodsApi().getDeviceGoodsList(deviceId, null);
|
|
|
- if (result != null && result.containsKey("list")) {
|
|
|
|
|
|
|
+ if (result != null && result.containsKey("dataInfo")) {
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
|
- List<Map<String, Object>> apiList = (List<Map<String, Object>>) result.get("list");
|
|
|
|
|
- return apiList.stream().map(item -> {
|
|
|
|
|
- Product product = new Product();
|
|
|
|
|
- product.setCode((String) item.get("code"));
|
|
|
|
|
- product.setName((String) item.get("product_name"));
|
|
|
|
|
- product.setBarcode((String) item.get("bar_code"));
|
|
|
|
|
- if (item.get("price") != null) {
|
|
|
|
|
- product.setPrice(((Number) item.get("price")).doubleValue());
|
|
|
|
|
- }
|
|
|
|
|
- return product;
|
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
|
|
|
|
+ List<Map<String, Object>> dataInfoList = (List<Map<String, Object>>) result.get("dataInfo");
|
|
|
|
|
+ return dataInfoList.stream()
|
|
|
|
|
+ .flatMap(category -> {
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ List<Map<String, Object>> goodsList = (List<Map<String, Object>>) category.get("goods");
|
|
|
|
|
+ if (goodsList == null) return java.util.stream.Stream.empty();
|
|
|
|
|
+ return goodsList.stream().map(item -> {
|
|
|
|
|
+ Product product = new Product();
|
|
|
|
|
+ product.setCode((String) item.get("code"));
|
|
|
|
|
+ product.setName((String) item.get("name"));
|
|
|
|
|
+ product.setPic((String) item.get("pic"));
|
|
|
|
|
+ if (item.get("c_price") != null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ product.setPrice(Double.parseDouble(item.get("c_price").toString()));
|
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
|
+ log.debug("价格解析失败: {}", item.get("c_price"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return product;
|
|
|
|
|
+ });
|
|
|
|
|
+ })
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("获取设备商品列表失败 - deviceId: {}, error: {}", deviceId, e.getMessage());
|
|
log.error("获取设备商品列表失败 - deviceId: {}, error: {}", deviceId, e.getMessage());
|