parent
7a5f4afb0c
commit
1d448587bf
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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