1、roll平台 mm图片api实现
This commit is contained in:
parent
7a5f4afb0c
commit
1d448587bf
|
|
@ -58,6 +58,8 @@ public class ApiConst {
|
|||
|
||||
public static final String ROLL_GARBAGE_SORTING = "ROLL-垃圾分类";
|
||||
|
||||
public static final String ROLL_BEAUTY_PICTURE = "ROLL-美女图片";
|
||||
|
||||
|
||||
//-------------------url------------------------------
|
||||
|
||||
|
|
@ -120,7 +122,12 @@ public class ApiConst {
|
|||
/**
|
||||
* 接口文档:https://www.mxnzp.com/doc/detail?id=14
|
||||
*/
|
||||
public static final String ROLL_GARBAGE_SORTING_URL = "https://www.mxnzp.com/api/rubbish/type";
|
||||
public static final String ROLL_GARBAGE_SORTING_URL = "http://www.mxnzp.com/api/rubbish/type";
|
||||
|
||||
/**
|
||||
* 接口文档:https://www.mxnzp.com/doc/detail?id=15
|
||||
*/
|
||||
public static final String ROLL_BEAUTY_PICTURE_URL = "https://www.mxnzp.com/api/image/girl/list/random";
|
||||
|
||||
|
||||
|
||||
|
|
@ -144,6 +151,10 @@ public class ApiConst {
|
|||
* roll平台返回值code成功参数
|
||||
*/
|
||||
public static final Integer ROLL_CODE_SUCCESS = 1;
|
||||
/**
|
||||
* roll平台返回值code失败参数
|
||||
*/
|
||||
public static final Integer ROLL_CODE_ERROR = 0;
|
||||
/**
|
||||
* speedtest平台返回值code成功参数
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -76,6 +76,14 @@ public class ApiToolsController {
|
|||
return R.ok(apiToolsService.getGarbageSorting(name));
|
||||
}
|
||||
|
||||
@GetMapping("beautypicture")
|
||||
@ApiOperation("获取mm图片信息")
|
||||
@Log(title = "获取mm图片分类")
|
||||
public R<List<ApiBeautyPicture>> getBeautyPictureApiData() {
|
||||
return R.ok(apiToolsService.getBeautyPicture());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
package com.xjs.apitools.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* api mm图片实体
|
||||
*
|
||||
* @author xiejs
|
||||
* @since 2022-01-19
|
||||
*/
|
||||
@Data
|
||||
public class ApiBeautyPicture implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 福利图片链接
|
||||
*/
|
||||
private String imageUrl;
|
||||
|
||||
|
||||
/**
|
||||
* 福利图片尺寸
|
||||
*/
|
||||
private String imageSize;
|
||||
|
||||
|
||||
/**
|
||||
* 福利图片文件大小
|
||||
*/
|
||||
private String imageFileLength;
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package com.xjs.apitools.factory.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xjs.apitools.domain.ApiBeautyPicture;
|
||||
import com.xjs.apitools.domain.RequestBody;
|
||||
import com.xjs.apitools.factory.ApiToolsFactory;
|
||||
import com.xjs.common.client.api.roll.RollBeautyPictureFeignClient;
|
||||
import com.xjs.config.RollProperties;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
import static com.xjs.consts.ApiConst.ROLL_CODE_SUCCESS;
|
||||
|
||||
/**
|
||||
* roll平台获取mm图片api工厂实现
|
||||
*
|
||||
* @author xiejs
|
||||
* @since 2022-01-19
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class RollBeautyPictureFactory implements ApiToolsFactory<ApiBeautyPicture, Object> {
|
||||
|
||||
@Autowired
|
||||
private RollProperties rollProperties;
|
||||
@Autowired
|
||||
private RollBeautyPictureFeignClient rollBeautyPictureFeignClient;
|
||||
|
||||
|
||||
@Override
|
||||
public List<ApiBeautyPicture> apiDataList() {
|
||||
RequestBody requestBody = new RequestBody();
|
||||
requestBody.setApp_secret(rollProperties.getApp_secret());
|
||||
requestBody.setApp_id(rollProperties.getApp_id());
|
||||
JSONObject jsonObject = rollBeautyPictureFeignClient.beautyPictureApi(requestBody);
|
||||
if (!jsonObject.containsKey(DEMOTE_ERROR) && jsonObject.getInteger("code") == ROLL_CODE_SUCCESS.intValue()) {
|
||||
JSONArray jsonArrayData = jsonObject.getJSONArray("data");
|
||||
return jsonArrayData.stream().map(data -> {
|
||||
JSONObject jsonData = (JSONObject) data;
|
||||
return jsonData.toJavaObject(ApiBeautyPicture.class);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,14 +6,15 @@ import com.xjs.apitools.domain.RequestBody;
|
|||
import com.xjs.apitools.factory.ApiToolsFactory;
|
||||
import com.xjs.common.client.api.roll.RollWeatherFeignClient;
|
||||
import com.xjs.config.RollProperties;
|
||||
import com.xjs.exception.ApiException;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
import static com.xjs.consts.ApiConst.ROLL_CODE_SUCCESS;
|
||||
import static com.xjs.consts.ApiConst.*;
|
||||
|
||||
/**
|
||||
* roll平台获取预报天气api工厂实现
|
||||
* @author xiejs
|
||||
* @since 2022-01-18
|
||||
*/
|
||||
|
|
@ -35,6 +36,8 @@ public class RollForecastWeatherFactory implements ApiToolsFactory<ApiForecastWe
|
|||
if (!jsonObject.containsKey(DEMOTE_ERROR) && jsonObject.getInteger("code") == ROLL_CODE_SUCCESS.intValue()) {
|
||||
JSONObject jsonData = jsonObject.getJSONObject("data");
|
||||
return jsonData.toJavaObject(ApiForecastWeather.class);
|
||||
}else if (jsonObject.getInteger("code") == ROLL_CODE_ERROR.intValue()) {
|
||||
throw new ApiException("未找到对应城市,请检查后重试");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ import com.xjs.apitools.domain.RequestBody;
|
|||
import com.xjs.apitools.factory.ApiToolsFactory;
|
||||
import com.xjs.common.client.api.roll.RollGarbageSortingDeignClient;
|
||||
import com.xjs.config.RollProperties;
|
||||
import com.xjs.exception.ApiException;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
import static com.xjs.consts.ApiConst.ROLL_CODE_SUCCESS;
|
||||
import static com.xjs.consts.ApiConst.*;
|
||||
|
||||
/**
|
||||
* roll平台获取垃圾分类api工厂实现
|
||||
|
|
@ -36,6 +36,8 @@ public class RollGarbageSortingFactory implements ApiToolsFactory<ApiGarbageSort
|
|||
if (!jsonObject.containsKey(DEMOTE_ERROR) && jsonObject.getInteger("code") == ROLL_CODE_SUCCESS.intValue()) {
|
||||
JSONObject jsonData = jsonObject.getJSONObject("data");
|
||||
return jsonData.toJavaObject(ApiGarbageSorting.class);
|
||||
} else if (jsonObject.getInteger("code") == ROLL_CODE_ERROR.intValue()) {
|
||||
throw new ApiException("未搜索到相关物品垃圾分类信息,该关键词已上报,感谢您的使用");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ import com.xjs.apitools.domain.RequestBody;
|
|||
import com.xjs.apitools.factory.ApiToolsFactory;
|
||||
import com.xjs.common.client.api.roll.RollWeatherFeignClient;
|
||||
import com.xjs.config.RollProperties;
|
||||
import com.xjs.exception.ApiException;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
import static com.xjs.consts.ApiConst.ROLL_CODE_SUCCESS;
|
||||
import static com.xjs.consts.ApiConst.*;
|
||||
|
||||
/**
|
||||
* roll天气预报api工厂实现
|
||||
|
|
@ -36,6 +36,8 @@ public class RollNowWeatherFactory implements ApiToolsFactory<ApiNowWeather, Req
|
|||
if (!jsonObject.containsKey(DEMOTE_ERROR) && jsonObject.getInteger("code") == ROLL_CODE_SUCCESS.intValue()) {
|
||||
JSONObject jsonData = jsonObject.getJSONObject("data");
|
||||
return jsonData.toJavaObject(ApiNowWeather.class);
|
||||
}else if (jsonObject.getInteger("code") == ROLL_CODE_ERROR.intValue()) {
|
||||
throw new ApiException("未找到对应城市,请检查后重试");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,5 +49,12 @@ public interface ApiToolsService {
|
|||
ApiGarbageSorting getGarbageSorting(String name);
|
||||
|
||||
|
||||
/**
|
||||
* 获取mm图片
|
||||
* @return ApiBeautyPicture
|
||||
*/
|
||||
List<ApiBeautyPicture> getBeautyPicture();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.xjs.apitools.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.xjs.apitools.domain.*;
|
||||
import com.xjs.apitools.factory.ApiToolsFactory;
|
||||
import com.xjs.apitools.factory.impl.*;
|
||||
|
|
@ -8,6 +9,8 @@ import com.xjs.exception.ApiException;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
|
@ -22,11 +25,17 @@ import java.util.stream.Collectors;
|
|||
@Service
|
||||
public class ApiToolsServiceImpl implements ApiToolsService {
|
||||
|
||||
/**
|
||||
* 文件单位
|
||||
*/
|
||||
public static final String KB= "KB";
|
||||
|
||||
private ApiToolsFactory<ApiHoliday, Object> holidayFactory;
|
||||
private ApiToolsFactory<ApiMobileBelong, RequestBody> mobileBelongFactory;
|
||||
private ApiToolsFactory<ApiNowWeather, RequestBody> nowWeatherFactory;
|
||||
private ApiToolsFactory<ApiForecastWeather,RequestBody> forecastWeatherFactory;
|
||||
private ApiToolsFactory<ApiGarbageSorting,RequestBody> garbageSortingFactory;
|
||||
private ApiToolsFactory<ApiForecastWeather, RequestBody> forecastWeatherFactory;
|
||||
private ApiToolsFactory<ApiGarbageSorting, RequestBody> garbageSortingFactory;
|
||||
private ApiToolsFactory<ApiBeautyPicture, Object> beautyPictureFactory;
|
||||
|
||||
@Autowired
|
||||
public void setHolidayFactory(RollHolidayFactory rollHolidayFactory) {
|
||||
|
|
@ -53,6 +62,11 @@ public class ApiToolsServiceImpl implements ApiToolsService {
|
|||
this.garbageSortingFactory = rollGarbageSortingFactory;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setBeautyPictureFactory(RollBeautyPictureFactory rollBeautyPictureFactory) {
|
||||
this.beautyPictureFactory = rollBeautyPictureFactory;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<ApiHoliday> getApiHolidayList() {
|
||||
|
|
@ -100,4 +114,19 @@ public class ApiToolsServiceImpl implements ApiToolsService {
|
|||
return Optional.ofNullable(garbageSortingFactory.apiData(requestBody))
|
||||
.orElseThrow(ApiException::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiBeautyPicture> getBeautyPicture() {
|
||||
List<ApiBeautyPicture> beautyPictureList = Optional.ofNullable(beautyPictureFactory.apiDataList())
|
||||
.orElseThrow(ApiException::new);
|
||||
beautyPictureList.forEach(bp ->{
|
||||
String imageFileLength = bp.getImageFileLength();
|
||||
if (StringUtils.isNotEmpty(imageFileLength)) {
|
||||
BigDecimal decimal = new BigDecimal(imageFileLength);
|
||||
BigDecimal divide = decimal.divide(new BigDecimal(1024), 0, RoundingMode.HALF_UP);
|
||||
bp.setImageFileLength(divide.toPlainString()+KB);
|
||||
}
|
||||
});
|
||||
return beautyPictureList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package com.xjs.common.client.api.roll;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xjs.annotation.ApiLog;
|
||||
import com.xjs.apitools.domain.RequestBody;
|
||||
import com.xjs.common.client.factory.RollBeautyPictureFeignFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.cloud.openfeign.SpringQueryMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import static com.xjs.consts.ApiConst.ROLL_BEAUTY_PICTURE;
|
||||
import static com.xjs.consts.ApiConst.ROLL_BEAUTY_PICTURE_URL;
|
||||
|
||||
/**
|
||||
* roll mm图片api接口feign远程调用
|
||||
* @author xiejs
|
||||
* @since 2022-01-19
|
||||
*/
|
||||
@FeignClient(name = "rollBeautyPicture", url = ROLL_BEAUTY_PICTURE_URL, fallbackFactory = RollBeautyPictureFeignFactory.class)
|
||||
public interface RollBeautyPictureFeignClient {
|
||||
|
||||
@GetMapping()
|
||||
@ApiLog(name = ROLL_BEAUTY_PICTURE,
|
||||
url = ROLL_BEAUTY_PICTURE_URL,
|
||||
method = "Get")
|
||||
JSONObject beautyPictureApi(@SpringQueryMap RequestBody requestBody);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.xjs.common.client.factory;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.xjs.common.client.api.roll.RollBeautyPictureFeignClient;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.xjs.consts.ApiConst.DEMOTE_ERROR;
|
||||
|
||||
/**
|
||||
* roll mm图片api接口feign远程调用 降级
|
||||
* @author xiejs
|
||||
* @since 2022-01-19
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class RollBeautyPictureFeignFactory implements FallbackFactory<RollBeautyPictureFeignClient> {
|
||||
@Override
|
||||
public RollBeautyPictureFeignClient create(Throwable cause) {
|
||||
log.error("api模块roll mm图片服务调用失败:{},执行降级处理", cause.getMessage());
|
||||
return requestBody -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put(DEMOTE_ERROR, R.FAIL);
|
||||
return jsonObject;
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue