其中有三个接口,车型的信息分为四个层级,1-品牌,2-汽车分公司即厂商,3-车系,4-车型;
接口一:无参数调用,阿里云返回172个品牌信息(当前数据量,阿里半个月一次更新);
接口二:使用品牌id作为parentid调用,返回depth为2,3,4的数据;其中第四层级的车型信息为简单信息;
接口三:使用具体的车型id作为参数carid调用,返回具体的车型信息,很详细;
注意,再设置参数时,requestDto.setParentid("1")或者requestDto.setCarid("41375");
设置的那个实体类的参数,parentid和carid,不能写成parentId和carId!
我在调用了接口一,将品牌信息遍历入库,在使用品牌id作为参数直接调用接口二时,只能得到一部分(五六个厂商)信息,
后台报错:Access-Control-Allow-Headers,返回的错误代码信息是403,通过与阿里技术员沟通得知:
是"通过用户流量控制节流",一种流量控制,阿里的这个接口,有限制:一分钟最大访问次数三十次!
没有其他办法避免这个限制!
解决办法:在自己的代码中,线程休眠!2秒即可!
另外,在遍历车厂商信息,获取每个厂商的车系list,再获取每个车系的车型list,取出其中的车型id调用接口三时,
有的车系,没有车型!getList为null!要多加一个非null判断,再去取车型list!
阿里云返回的车型详情中的颜色字段:
是这样:
魔力黑,#000000|季风灰,#2c5866|海南蓝,#48689e|白鲸棕,#574126|西拉红,#681529|喀纳斯绿
或者是这样:
幽灵党灰,传奇黑,#000000|探索蓝,#858585
或者这样:
传奇黑,#000000|探索蓝,#9e0f0f|白金色金属漆,#9f9c8e|
可以在自己的数据库车型详情表中加一个字段,存储处理之后的颜色字段:
/**
* ","
*/
public static final String SPLIT_0 = ",";
/**
* "|"
*/
public static final String SPLIT_1 = "|";
/**
* "#"
*/
public static final String SPLIT_2 = "#";
/**
* "%s%s"
*/
public static final String STRING_FORMAT_2 = "%s%s";
/**
* "%s%s%s"
*/
public static final String STRING_FORMAT_3 = "%s%s%s";
/**
* 处理车型颜色,返回正确的颜色
*
* @param color 阿里云返回的车型详情的颜色: 圣邦蓝,#375F92|天云灰,#6E6E70|米萨诺红,#E52B2C 或者 :
* 幽灵党灰,传奇黑,#000000|探索蓝,#858585 或者:
* 传奇黑,#000000|探索蓝,#9e0f0f|白金色金属漆,#9f9c8e|
* @return 处理之后的颜色: 圣邦蓝,天云灰,米萨诺红
*/
@Override
public String genColorList(String color) {
log.info("传入的颜色color:{} ", color);
String colorList = StringUtils.EMPTY;
// 根据","分割
for (String colorArr : color.split(VehicleConstants.SPLIT_0)) {
// 含有 |
if (colorArr.contains(VehicleConstants.SPLIT_1)) {
String colorSubstring = colorArr.substring(colorArr.indexOf(VehicleConstants.SPLIT_1) + 1);
if (StringUtils.isNotBlank(colorSubstring)) {
colorList = colorList + colorSubstring + VehicleConstants.SPLIT_0;
}
} else {
// 含有 #
if (colorArr.contains(VehicleConstants.SPLIT_2)) {
colorList = String.format(VehicleConstants.STRING_FORMAT_2, colorList,
colorArr.substring(0, colorArr.indexOf(VehicleConstants.SPLIT_2)));
} else {
colorList = String.format(VehicleConstants.STRING_FORMAT_3, colorList, colorArr,
VehicleConstants.SPLIT_0);
}
}
}
colorList = colorList.substring(0, colorList.length() - 1);
log.info("处理完的颜色colorList:{} ", colorList);
return colorList;
}